Hello,
I need some help connecting to my Azure Database for MySQL flexible server.
I watched the video https://www.youtube.com/watch?v=MwxqYHbQxqY and read countless articles online about it, but I can't connect to the DB from a website running PHP.
In Azure portal,
I checked "Allow public access to this resource through the internet using a public IP address"
I set up the IP addresses (my local and website) in Networking > Firewall rules
////////////////////////////////
/////// local computer /////////
////////////////////////////////
I downloaded DigiCertGlobalRootCA.crt.pem and added to c:/1/ in my computer
I can connect from my computer using xampp with the following PHP code:
PDO::ERRMODE_EXCEPTION,
PDO::MYSQL_ATTR_SSL_CA => $path . 'DigiCertGlobalRootCA.crt.pem'
];
// Establish the connection
$db = new PDO($dsn, $username, $password, $options);
// If connection is successful
echo "Connection successful!";
} catch (PDOException $e) {
// If there is an error in the connection
echo "Connection failed: " . $e->getMessage();
}
?>
////////////////////////////////
/////// website server /////////
////////////////////////////////
The problem is, I can't connect from a website using a similar PHP script.
I have the server IP in the firewall rules.
the code below does not work, I get a SQLSTATE[HY000] [2002] Connection refused
I think it is related to the path to DigiCertGlobalRootCA.crt.pem, but I'm not sure
I uploaded the .pem file to the root of the site and below the root, none work.
What am I doing wrong?
PDO::ERRMODE_EXCEPTION,
PDO::MYSQL_ATTR_SSL_CA => $path . 'DigiCertGlobalRootCA.crt.pem'
];
$pdo = new PDO($dsn, $username, $password, $options);
// If connection is successful
echo "Connection successful!";
} catch (PDOException $e) {
// If there is an error in the connection
echo "Connection failed: " . $e->getMessage();
}
?>
Btw, I can connect to the DB with MySQL Workbench also.
I also tried the IP range from 0.0.0.0 - 255.255.255.255, still no luck.
Thanks for your help in advance.
Dario