Search code examples
phpgoogle-app-enginegoogle-cloud-sql

app engine unable connect to sql database


I am trying make a web app in app engine. I have loaded a php script in the app that pulls data from a database in cloud sql. I am connecting to the database using the following method.

$db = new mysqli(null, 'root', '', $dbname, null, 
      '/cloudsql/<project-id>:<sql instance id>');  

I am getting the error

Unable to connect to database [MySQL server has gone away]

Solution

  • I was using 2nd generation cloud sql. Currently app engine is not supported by 2nd generation. Only first generation cloud sql can be used with app engine. Google's documentation is very poor. It did not even mention this while creating instance in the 2nd generation cloud sql. Only compute engine can use 2nd generation cloud sql.