Connecting to a Cloud SQL instance requires the use of a Unix socket and 
the appropriate extension available to the runtime.  *mysql* and *mysqli* 
are enabled by default 
<https://cloud.google.com/appengine/docs/standard/php/runtime#PHP_Enabled_extensions>
 
in the PHP runtime for App Engine.  An example of connecting using 
*mysqli_connect* can be found here 
<http://stackoverflow.com/questions/24554143/connection-issue-connecting-from-php-app-engine-instance-to-a-cloud-sql-instance>.
 
 The key element here is the use of the *socket* argument in the 
*mysqli_connect()* call.

Note that the PHP team recommends using *PDO* or *mysqli* 
<http://php.net/manual/en/mysqlinfo.api.choosing.php>, not the original 
*mysql*.  Are you facing any particular challenges with using mysqli or PDO?

On Sunday, April 30, 2017 at 11:08:15 PM UTC-4, Abinav Chandar wrote:
>
> Can this only be done with the PDO or can it also be done with 
> mysql_connect()
>
> On Thursday, September 29, 2016 at 5:11:22 PM UTC-5, Kevin Lau wrote:
>>
>>
>> down votefavorite 
>> <http://stackoverflow.com/questions/39778544/why-does-my-php-app-engine-not-connect-to-cloud-sql#>
>>
>> I am trying to connect my app engine PHP app to cloud sql via unix socket 
>> (I assume that is correct so that I don't have to connect to the ip). The 
>> connect via IP works but the unix socket does not. Any ideas? It's also 
>> weird that when I ssh into the box, I don't see any /cloudsql/ directory. I 
>> can create it by manually starting cloud_sql_proxy but that doesn't persist 
>> as soon as I turn debug off.
>>
>>
>> I'm using: $db = new pdo( 
>> 'mysql:unix_socket=/cloudsql/testproject-xxxxxx:us-central1:library;dbname=books',
>>  
>> 'phpapp', // username 'somepw' // password );
>>
>> And get SQLSTATE[HY000] [2002] No such file or directory
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/80858be3-2aad-409b-9a99-2e10b5fa1cff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to