Hi Chris Fauskanger •,
Welcome to Micrsoft Q&A forum and thanks for using Azure Services.
As I understand, you are trying to Use PHP to connect and query data in Azure Database for MySQL and could not do so.
Could you please refer to the official Microsoft documentation here:
https://learn.microsoft.com/en-us/azure/mysql/single-server/connect-php#step-1-connect-to-the-server
SSL is enabled by default. You may need to download the DigiCertGlobalRootG2 SSL certificate to connect from your local environment. This code calls:
$host = 'mydemoserver.mysql.database.azure.com';
$username = 'myadmin@mydemoserver';
$password = 'your_password';
$db_name = 'your_database';
//Initializes MySQLi
$conn = mysqli_init();
mysqli_ssl_set($conn,NULL,NULL, "/var/www/html/DigiCertGlobalRootG2.crt.pem", NULL, NULL);
// Establish the connection
mysqli_real_connect($conn, $host, $username, $password, $db_name, 3306, NULL, MYSQLI_CLIENT_SSL);
//If connection failed, show the error
if (mysqli_connect_errno())
{
die('Failed to connect to MySQL: '.mysqli_connect_error());
}
If the application persistently fails to connect to Azure Database for MySQL, it usually indicates an issue with one of the following:- Server firewall configuration: Make sure that the Azure Database for MySQL server firewall is configured to allow connections from your client, including proxy servers and gateways.
- Client firewall configuration: The firewall on your client must allow connections to your database server. IP addresses and ports of the server that you cannot to must be allowed as well as application names such as MySQL in some firewalls.
- User error: You might have mistyped connection parameters, such as the server name in the connection string or a missing @servername suffix in the user name.
Steps to resolve persistent connectivity issues
- Set up firewall rules to allow the client IP address. For temporary testing purposes only, set up a firewall rule using 0.0.0.0 as the starting IP address and using 255.255.255.255 as the ending IP address. This will open the server to all IP addresses. If this resolves your connectivity issue, remove this rule and create a firewall rule for an appropriately limited IP address or address range.
- On all firewalls between the client and the internet, make sure that port 3306 is open for outbound connections.
- Verify your connection string and other connection settings. Review How to connect applications to Azure Database for MySQL.
- Check the service health in the dashboard. If you think there's a regional outage, see Overview of business continuity with Azure Database for MySQL for steps to recover to a new region.
Let us know if above helps. If not, please share screenshot of the error and more details so that we can investigate.Thanks