GAE PHP MySQLI

277 views
Skip to first unread message

Terence Ramos

unread,
Nov 4, 2015, 6:00:51 PM11/4/15
to Google App Engine
I'm completely new to GAE development. I'm just trying to connect to the Cloud SQL instance I created for my App Engine PHP application. My php file is a bare bones:

<?php


// Using mysqli (connecting from App Engine)

$sql
= new mysqli(
 
null, // host
 
'root', // username
 
'',     // password
 
'', // database name
 
null,
 
'/cloudsql/my-app-id:my-sql-db'
 
);

My application does have permission to use the cloud sql instance. The issue is this seems to work when deployed, but locally it doesn't. I get: 

Warning: mysqli::mysqli(): (HY000/2002): No such file or directory in /Users/myuser/Work/projects/default/index.php on line 23
indexaction

The GAE PHP help files don't seem to help. They state something like, see above for how to use GAE locally with the book sample. But the sample above in the web site is the Hello, world! Does anyone know where I can find information on this, or how to do this?

Thanks

Terence Ramos

unread,
Nov 4, 2015, 6:19:52 PM11/4/15
to Google App Engine
Okay, I found their sample. It basically does a check on the global SERVER variable to determine if they are running locally and changes the connection string. So I got this out of it:

$isLocal = !isset($_SERVER['SERVER_SOFTWARE']) || strpos($_SERVER['SERVER_SOFTWARE'], 'Google App Engine') === false;

I guess I have to find out why my local PHP is not configured to properly for mysql.

Thomas Valadez

unread,
Jun 23, 2017, 9:16:59 AM6/23/17
to Google App Engine
How did you get the mysqli function to work when deployed. I am getting an error Warning: mysqli::__construct(): (HY000/2002): Connection timed


any tips on how you set this up to get it to work? 
Reply all
Reply to author
Forward
0 new messages