We set up mysql with SSL by creating the certificates, updating the my.cnf, creating users with right privileges and requiring ssl, restarting the service, and verified it works server side and client side (via mysql command line) by connecting remotely. I've also verified PDO works properly with the exact same setup but disabling the "require ssl" on the user account in mysql because it just fails silently and uses a non-ssl connection.
However when using the PHP application to connect it does not work using PDO forcing ssl but does work using mysqli with force ssl. I thought they used the same drivers and both should work fine. The error message I get is 'Failed connecting to database [SQLSTATE[28000] [1045] Access denied for user', but the user exists and this connection works with mysqli (force ssl) and the connection works for PDO only if I remove 'require ssl' from the user in mysql.
php 5.5.9 CentOS release 6.5 (Final) pdo_mysql 5.5.31
Let me know if I can provide any additional information. Below are connection examples,
//mysqli
$conn=mysqli_init();
mysqli_ssl_set($conn, $clientkey, $clientcert, $sharedca, NULL, NULL);
if (!mysqli_real_connect($conn, $host, $user, $pass, $db))
{
die("Failed connecting to ssl mysql via mysqli");
}
$res = mysqli_query($conn, "SHOW STATUS like 'Ssl_cipher'");
print_r(mysqli_fetch_row($res));
mysqli_close($conn);
//pdo
$options = array_merge($options, array(
PDO::MYSQL_ATTR_SSL_KEY => $sslkey,
PDO::MYSQL_ATTR_SSL_CERT => $sslcert,
PDO::MYSQL_ATTR_SSL_CA => $sslca,
));
try
{
$pdo = new PDO("mysql:dbname={$db};host={$host}", $user, $pass, $options);
}
catch( PDOException $e )
{
die("Failed connecting");
}
Is there anything I should know about how to properly connect using SSL with PDO? Or am I forced to switch to mysqli because PDO support for SSL may be problematic?