0

I lost several hours trying to connect to cloud SQL from PHP flex env, but I found the answer.

I hope this help other people.

An exception occured in driver: SQLSTATE[HY000] [2002] No such file or directory

or

Access denied for user 'root'@'cloudsql' (using password: NO)
SurvivalMachine
  • 7,946
  • 15
  • 57
  • 87
J261
  • 642
  • 2
  • 6
  • 21

1 Answers1

0

1.- enable Google Cloud SQL API: https://console.cloud.google.com/apis/

enter image description here

2.- get your cloud sql instance name

enter image description here

3.- add the beta_settings to your yaml

beta_settings:
    cloud_sql_instances: "here-your-instance-name"

4.- config your doctrine dbal unix_socket

$app->register(new Silex\Provider\DoctrineServiceProvider(), array(
    'dbs.options' => array (
        'db_conn' => array(
            'driver'    => 'pdo_mysql',
            'unix_socket' => '/cloudsql/here-your-instance-name',
            'host'      => 'localhost',
            'dbname'    => 'your-database',
            'user'      => 'your-user',
            'password'  => 'your-password',
            'charset'   => 'utf8',
            'collate'   => 'utf8_spanish2_ci'
        )
    )
));
J261
  • 642
  • 2
  • 6
  • 21