Reputation: 869
I have a GAE PHP application that use PDO for connecting a MySQL instance. The MySQL instance is hosted in a different GCP project. I have this error:
SQLSTATE[HY000] [2002] Unable to find the socket transport \"unix\" -
did you forget to enable it when you configured PHP?
this is the PDO code:
# GAE
$this->database = new PDO('mysql:unix_socket=<SQL_INSTANCE_NAME>;dbname=<DB_NAME>', <USER>, <PASSWORD>);
$this->database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->database->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
Is it possible connect a GAE PHP application to a MySQL instance of other project ?
Upvotes: 2
Views: 129
Reputation: 869
Fixed!!! I had this code
$this->database = new PDO('mysql:unix_socket=<SQL_INSTANCE_NAME>;dbname=<DB_NAME>', <USER>, <PASSWORD>);
and was: :/cloudsql/<PROJECT>:<REGION>:<DB_NAME>
the solution is remove colon!!!
So this is the correct dsn:
$this->database = new PDO('mysql:unix_socket=/cloudsql/<PROJECT>:<REGION>:<DB_NAME>;dbname=<DB_NAME>', <USER>, <PASSWORD>);
Upvotes: 2