After a few preaprations on the mysql server side that are described here you can connect using ssl with the following php code:
$db = mysqlii_init();
$db->ssl_set('server-key.pem','server-cert.pem', 'cacert.pem', NULL, NULL);
$db->real_connct("your.server.net", "test", "testpass", "yourdb");
Or using the old (deprecated) mysql API this cn be done this way:
$link = mysql_connect("your.server.net", "test", "testpass", false, MYSQL_CLIENT_SSL)
if(!$link) {
die (mysql_error()));
}
Note:
Note that MySQL Native Driver does not support SSL before PHP 5.3.3, so calling this function when using MySQL Native Driver will result in an error. MySQL Native Driver is enabled by default on Microsoft Windows from PHP version 5.3 onwards.