Thursday, October 18, 2018

[google-cloud-sql-discuss] SQLSTATE[HY000] [2002] No such file or directory, google app engine flexible

Using cloud sql with app engine flexible. Trying to connect sql with socket as bellow:

   
   $dsn = getenv('MYSQL_DSN');
   $user = getenv('MYSQL_USER');
   $password = getenv('MYSQL_PASSWORD');
   try {
       $db = new PDO($dsn, $user, $password);
       $statement = $db->prepare("SELECT * from user");
       $statement->execute();
       $users = $statement->fetchAll();
   } catch (Exception $e) {
       echo 'Caught exception: ',  $e->getMessage(), "\n";
   }

My app.yaml file

    runtime: php
    env: flex

    runtime_config:
        document_root: .

    env_variables:
        MYSQL_DSN: mysql:dbname=DATABASE;unix_socket=/cloudsql/INSTANCE_CONNECTION_NAME
        MYSQL_USER: username
        MYSQL_PASSWORD: password

I am getting bellow error:

Caught exception: SQLSTATE[HY000] [2002] No such file or directory

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/5316d2c5-6983-46f7-aa35-356735b8ccfa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment