1

i am trying to deploy a test php project on google app engine flexible environment.

My app.yaml looks like this:

*

runtime: php
env: flex
service: testphpflex
manual_scaling:
  instances: 1
#[START cloudsql_settings]
# Use the connection name obtained when configuring your Cloud SQL instance.
beta_settings:
    cloud_sql_instances: "my-first-project:us-central1:tempdb"
#[END cloudsql_settings]

*

The composer.json looks like this:

{
    "require": {
        "silex/silex": "^1.3",
        "php": "5.6.*",
        "google/apiclient": "^2.0"

    },
    "require-dev": {
        "google/cloud-tools": "^0.6",
        "paragonie/random_compat": "^2.0",
        "phpunit/phpunit": "~4"
    }
}

And my sample code looks like this:

<?php
 $conn = mysql_connect('unix_socket:/cloudsql/my-first-project:us-central1:tempdb',
         'username', 
         'password'
     );

     echo "<br><br/>connection done";
if(!$conn)
{
die('Connection Failed'.mysql_error());
}
else 
{
die('Connection successful');
}

?>

However, i am not able to connect. What is wrong?

3 Answers3

2

My hypothesis is that the Google Cloud SQL API is not enabled.

Go to the following link and see if it's enabled. Enable it if not.

https://console.cloud.google.com/apis/api/sqladmin.googleapis.com/overview?project=_

Then try re-deploying the app (unfortunately you need to deploy it again). If this is the case, it's a dup of Connecting to 2nd gen Cloud SQL on App Engine flexible PHP 7.0 - missing socket

Community
  • 1
  • 1
Takashi Matsuo
  • 3,406
  • 16
  • 25
1

Google Cloud Support tells me that mysql_connect is deprecated. It has been deprecated in PHP since 5.5 and so there is no support for this. So the above is not supported.

0

I think I understand why you're getting the error.

You should use:

mysql_connect(':/cloudsql/my-first-project:us-central1:tempdb',

or

mysql_connect('localhost:/cloudsql/my-first-project:us-central1:tempdb',

According to the manual http://php.net/manual/en/function.mysql-connect.php

Takashi Matsuo
  • 3,406
  • 16
  • 25