«

»

Nov 07

How to: Connect to a MySql server using SSL from a WordPress Site

How to: Connect to a MySql server using SSL from a WordPress Site

Truly you could title this post simply How to Connect to a MySql server using SSL from a PHP application. The key is in the connection construct, which by default in WordPress it looks sort of like this:

$this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );

So here comes the key to the whole business: You must use the “MYSQL_CLIENT_SSL” client flag to indicate PHP to use SSL. So, in the case of WordPress you could manually open the db.php file and make the manual edit or rely on the parameter $client_flags which is defined as follows:

$client_flags = defined( 'MYSQL_CLIENT_FLAGS' ) ? MYSQL_CLIENT_FLAGS : 0;

So what this means for you is that by defining MYSQL_CLIENT_FLAGS in something like your wp-config.php file you could set the flag to MYSQL_CLIENT_SSL effectively indicating PHP to connect to MySql via SSL. Below is a sample of what to add to your config file:

define(‘MYSQL_CLIENT_FLAGS’, MYSQL_CLIENT_SSL);

Hope this helps!

Leave a Reply

%d bloggers like this: