connect to remote wpengine mysql service with php/pdo

Following the instructions here:

I’m able to connect to mysql from my command line with:

mysql -uuser -ppassword -h -P13306 -D database –default-auth=mysql_native_password

But when I try the same parameters through php/pdo:

$dbh = new PDO('mysql:host='.$host.';port='.$port.';dbname='.$db.';default-auth=mysql_native_password', $user, $pass);

I get this error:

PHP Fatal error: Uncaught PDOException: PDO::__construct(): MySQL server has gone away

Add Comment
1 Answer(s)

You need to add options and specify the .pem key.

You can download the pem key from the instructions in the question: – save wpengine_root_ca.pem to the same directory as your script.

    $user = '';     $pass = '';     $db = '';     $port = '13306';     $host = '';  //put your account name instead of 'instance' here     $options = ['default-auth'=>'mysql_native_password',     PDO::MYSQL_ATTR_SSL_CA=>__DIR__.'/wpengine_root_ca.pem',     PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false];          $dbh = new PDO('mysql:host='.$host.';port='.$port.';dbname='.$db.';default-auth=mysql_native_password', $user, $pass, $options); 

You should read over the directions carefully and also make sure that WP Engine has whitelisted your ip address.

Answered on September 1, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.