2
votes

I am new to Google App Engine. I am currently following the tutorial for Google App Engine here: https://cloud.google.com/appengine/docs/php/cloud-sql/

I can't seem to get my application to access the Cloud-SQL database on Google App Engine.

I keep receiving this error below:

Warning: PDO::__construct(): MySQL server has gone away in /base/data/home/apps/p~iconic-indexer-112318/1.388447661471940227/guestbook.php on line 24 
Warning: PDO::__construct(): Error while reading greeting packet. PID=-1 in /base/data/home/apps/p~iconic-indexer-112318/1.388447661471940227/guestbook.php on line 24 {"outcome":false,"message":"Unable to connect."}

I have looked at other questions that point to a syntax error, but I'm not quite sure I see one here. I believe my application has access to the Cloud-SQL database. Because I have created the database instances inside of my application and according to this link: https://cloud.google.com/appengine/docs/php/cloud-sql/#create

My application should have access to the database. Aside from this I have no other Authorized App Engine Applications and even if I did try to add iconic-indexer-112318, it doesn't allow me to and notifies me "Could not complete the operation". I suspect this is because the application already has access.

I have doubled checked and both the application and instances are in the same region : us-east1

Project Id: iconic-indexer-112318

Instance Id: iconic-indexer-112318:hellodb

 // Connect from App Engine.
 try{
    $db = new pdo('mysql:unix_socket=/cloudsql/iconic-indexer-112318:iconic-indexer-112318:hellodb;dbname=guestbook', 'root', '');
 }catch(PDOException $ex){
     die(json_encode(
         array('outcome' => false, 'message' => 'Unable to connect.')
         )
     );
 }

I am not sure what is wrong. Thank you for your assistance.

2

2 Answers

1
votes

Have you checked if your Cloud SQL instance have the an IPv4 address assigned to it?

You can check under Access Control > IP address. There is a button "Request IPv4 address" that would enable it.

0
votes

Might be related to this bug, which appears to be unresolved: random "server has gone away" errors from GAE to cloud SQL