PHP PDO not Connecting to Cloud SQL

115 views
Skip to first unread message

Aminu Lawal Nasir

unread,
Feb 7, 2020, 11:03:30 PM2/7/20
to Google Cloud SQL discuss
Hello,

I'm having problems connecting to Cloud SQL using PDO.

Can someone please help me out.


$db_server=null;
$db_username="root";
$db_password="password";
$db_database="database";
$connection=new PDO('mysql:unix_socket=/cloudsql/corvater:europe-west6:dbinstance;dbname='.$db_database,$db_username,$db_password);

EZEKIAS BOKOVE

unread,
Feb 8, 2020, 4:25:08 AM2/8/20
to Google Cloud SQL discuss

George (Cloud Platform Support)

unread,
Feb 11, 2020, 1:24:50 PM2/11/20
to Google Cloud SQL discuss
Hello Aminu, 

You may consider something similar to: 

$dsn = "/cloudsql/PROJECT:REGION:INSTANCE;dbname=DATABASE";
 $user = "USER";
 $password = "PASSWORD";
 $db = new PDO($dsn, $user, $password);

Alternatively, you could set relevant environment variables in the app.yaml configuration file, and using these variables: 

env_variables:

MYSQL_USER: root

MYSQL_PASSWORD: "*****"

MYSQL_DSN: mysql:dbname=DBNAME;unix_socket=/cloudsql/INSTANCE_NAME

This discussion group is oriented more towards general opinions, trends, and issues of general nature touching App Engine and Cloud SQL. For coding and programming architecture, as well as setting up PDO connectivity, you may be better served in dedicated forums such as stackoverflow, where experienced programmers are within reach and ready to help. 
Reply all
Reply to author
Forward
0 new messages