OK, I have found that it isn't the location of the SSL certificates. When I change the path to something that doesn't exist I get an error saying "SSL certificate error", so that rules that out.
But I am still having no luck. In desperation, I uploaded the code to my web server and tried it out there. Now things are even more confusing. When I try to run the page it just hangs and doesn't open at all - not even if I leave it for 15 minutes.
Here is the code:
define ("HOST","mydomain.com");
define ("USER","WebUser");
define ("PASSWORD","password");
define ("DATABASE","Database");
echo phpinfo();
$mysqli = mysqli_init();
if (!$mysqli) {
die('mysqli_init failed');
}
$mysqli->ssl_set('/etc/ssl/client-key.pem','/etc/ssla/client-cert.pem', '/etc/ssla/ca-cert.pem',NULL,NULL);
if (!$mysqli->options(MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT = 0')) {
die('Setting MYSQLI_INIT_COMMAND failed');
}
if (!$mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5)) {
die('Setting MYSQLI_OPT_CONNECT_TIMEOUT failed');
}
if (!$mysqli->real_connect(HOST, USER, PASSWORD, DATABASE, NULL, NULL, MYSQLI_CLIENT_SSL)) {
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
If I remove the MYSQLI_CLIENT_SSL flag I get the error message "Connect Error (1045) Access denied". If I put the flag in the page just hangs and never loads.
What could be wrong? I mean, this code was copied and pasted straight out of the PHP documentation!