0

I am trying to write a simple plain PHP page, that connects to Cloud SQL using mysqli. It works fine on my local machine, when I turn on the Cloud SQL proxy. BUT! it does not work on the Google App Engine. I have tried:

  • changing 127.0.0.1 to the Public IP address stated in the Cloud SQL instance details
  • adding the port (3306), and db socket (/cloudsql/<cloud_sql_instance_name>)

    $servername = "127.0.0.1";
    $username = "test";
    $password = "test";
    $dbname = "testdb";
    
    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname); 
    
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } 
    echo "\nConnected successfully\n";
    

Is there any mistake somewhere?

1 Answers1

0

Google App Engine is not like a regular VM.

The proxy gets deployed alongside the main app container and has some very specific ways to run the connections. Trying to use the proxy as is inside GAE will always fail.

To make it work, you must follow the instructions on the specific documentation for the environment that you're using:

Notice how on both instances you'll be connecting directly to a Unix socket, and not to the instance/proxy IP.

Jofre
  • 3,718
  • 1
  • 23
  • 31