0
votes

I am experiencing issues connecting to a Cloud SQL instance hosted in an App engine (Java Runtime). The connecting client is a PHP web application hosted in another Google app engine instance. Is it possible for an App engine instance to connect to a Cloud SQL in another instance?

Basically, my setup is as follow:

  • Google App Engine 1 (Java Runtime)
    • installed with Cloud SQL instance
    • hosts Google Endpoints and connects to Cloud SQL on this instance
  • Google App Engine 2 (PHP Runtime)
    • PHP script connecting to Cloud SQL Instance of Google App Engine 1

The problem is I am always getting error below:

Warning: mysqli_connect(): MySQL server has gone away in /base/data/home/apps/s~some-php-web-app-v1/v1.376456666740733344/includes/database.php on line 29 Warning: mysqli_connect(): Error while reading greeting packet. PID=-1

I believe that my connection code is correct

public function connect($server = DBHOST, $username = DBUSER, $password = DBPASS,  $database = DBNAME, $socket = DBSOCKET, $port = DBPORT)
{
    $this->link = mysqli_connect($server, $username, $password, $database, $port, $socket) or die(mysqli_error());
}

Constants are:

define('DBHOST', null);
define('DBSOCKET','/cloudsql/some-app-v1-test:some-db');
define('DBNAME', 'database_name');
define('DBUSER', 'root');
define('DBPORT', null);
define('DBPASS', null);
define('PROJECT_PATH', "http:someserver.com//");

Is this possible? If it is, what configuration do I have to set in order to make this work?

Thanks, Stephen

1

1 Answers

0
votes

I found the answer to my novice question. Click Edit on your Cloud SQL console then add your google app instance id under "Authorized App Engine Applications" section.