I'm trying to connect my App (from App Engine) to Cloud SQL, and I must be missing something:
- I added a Cloud SQL instance
I Authorized my App
I added a test_db database via PhpMyAdmin (authorized my IP and connected to do that), tested that the user & password work
- Finally I deployed an app with the following lines (to test connection):
.
$dbh = mysqli_init();
var_dump( mysqli_real_connect( $dbh, ':/cloudsql/my_project_id:database_name', 'test_db', 'test_db', 'test_db' ) );
var_dump( mysqli_real_connect( $dbh, 'localhost:/cloudsql/my_project_id:database_name', 'test_db', 'test_db', 'test_db' ) );
var_dump( mysqli_real_connect( $dbh, 'test_db', 'test_db', 'test_db', ':/cloudsql/my_project_id:database_name', 3306 ) );
var_dump( mysqli_real_connect( $dbh, 'test_db', 'test_db', 'test_db', 'localhost:/cloudsql/my_project_id:database_name', 3306 ) );
var_dump( mysqli_real_connect( $dbh, ':/cloudsql/my_project_id:database_name', 'test_db', 'test_db', null, 3306 ) );
var_dump( mysqli_real_connect( $dbh, 'localhost:/cloudsql/my_project_id:database_name', 'test_db', 'test_db', null, 3306 ) );
var_dump( mysqli_real_connect( $dbh, null, 'test_db', 'test_db', 'test_db', ':/cloudsql/my_project_id:database_name', 3306 ) );
var_dump( mysqli_real_connect( $dbh, 'localhost', 'test_db', 'test_db', 'test_db', ':/cloudsql/my_project_id:database_name', 3306 ) );
var_dump( mysqli_real_connect( $dbh, null, 'test_db', 'test_db', 'test_db', ':/cloudsql/my_project_id:database_name' ) );
var_dump( mysqli_real_connect( $dbh, 'localhost', 'test_db', 'test_db', 'test_db', ':/cloudsql/my_project_id:database_name' ) );
var_dump( $dbh->connect_error );
All if these rows returned False or Null (i.e. none of them work), help?
(if there's a solution let's please keep it with mysqli_real_connect() because that's what WordPress is using)
UPDATE: New Error
Currently I'm using this line:
var_dump( mysqli_real_connect( $dbh, 'localhost', 'test_db', 'test_db', 'test_db', 3306, 'mysql:unix_socket=/cloudsql/my_project_id:database_name' ) );
and I'm getting the following error
Unable to find the socket transport "unix" - did you forget to enable it when you configured PHP?