How do you connect with your Azure database using PDO with PHP version 5.5?

Bruce Gust
Bruce Gust used Ask the Experts™
on
My company recently moved to an Azure server and with that came a more secure database dynamic. Alas, my PDO connection is now not working and I'm stuck.

Let me preface this by saying I'm running PHP 5.5.30 and updating is not an option just because of the antiquated code that characterizes the app. I'm concerned that an update would knock some things over and it would be a real mess.

The PDO that I'm working was built with a view to a more contemporary and secure future. Until everything is in place, however, we're taking baby steps and that brings us to the current dilemma.

Here's what I've got currently:

<?php
$user="accurate";
$host="accurate";

$password='accurate';
$database = "accurate";
$test="mysql:host=$host;dbname=$database";

try {
	 $options = array(
	PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
	PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
	PDO::MYSQL_ATTR_SSL_KEY => NULL,
	PDO::MYSQL_ATTR_SSL_CERT  => accurate',
	PDO::MYSQL_ATTR_SSL_CA => NULL,
	//PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false
	);
    $conn = new PDO($test, $user, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}

?>

Open in new window


Where you see "accurate," I'm referring to what I know to be an accurate setting, be it a database name or the location of the SSL_CERT. When I run this, I get:

Warning: PDO::__construct(): Unable to set private key file `D:\www\toolbox' in D:\www\toolbox\functions\personnel.php on line 23

Warning: PDO::__construct(): failed to create an SSL handle in D:\www\toolbox\functions\personnel.php on line 23

Warning: PDO::__construct(): Cannot connect to MySQL by using SSL in D:\www\toolbox\functions\personnel.php on line 23

Warning: PDO::__construct(): [2002] (trying to connect via tcp://east-prod-mysql01.mysql.database.azure.com:3306) in D:\www\toolbox\functions\personnel.php on line 23
Connection failed: SQLSTATE[HY000] [2002]

I was provided the "PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT" dynamic as a suggestion that would convince the system to circumvent the process where the server is being validated, but when I try that, I get:

Fatal error: Undefined class constant 'MYSQL_ATTR_SSL_VERIFY_SERVER_CERT' in D:\www\toolbox\functions\personnel.php on line 21

...which I believe is a result of my version of PHP being less than what's needed for that constant to resonate as legitimate.

So...

Any suggestions?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
2015 Top Expert (Most Article Points)
Commented:
Azure have retired 5.5 and require 5.6 as a minimum. Have you configured Azure to use a custom PHP runtime version?

https://docs.microsoft.com/en-us/azure/app-service/web-sites-php-configure
Bruce GustPHP Developer

Author

Commented:
That's what I needed to know!

Thanks, Chris!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial