Google App Engine PHP and Cloud SQL

1 view
Skip to first unread message

user1005242 via StackOverflow

unread,
Jun 10, 2013, 9:58:15 AM6/10/13
to google-appengin...@googlegroups.com

I'm attempting to connect to my Google Cloud SQL from my local development Google App PHP server. But PHP doesn't see function mysql_connect, it doesn't see class mysqli and it raises exception could not find driver when I'm attempting to connect with PDO class.


I run my development PHP server with a command:

"C:\Users\pasha\appengine-php-sdk-1.8.0\google_appengine\dev_appserver.py" --php_executable_path="C:\Users\pasha\php\php-cgi.exe" C:\Work\gaetest\


The app.yaml file has these contents:

application: gaetest
version: 1
runtime: php
api_version: 1

handlers:

- url: /(.*)
  script: app/\1

The testing sript is:

define('MYSQL_HOST', "/cloudsql/sample-project:sample-sql-instance");
define('MYSQL_LOGIN', "sample-login");
define('MYSQL_PASSWORD', "sample-pass");
define('MYSQL_DB', "sample-db");

echo "\nfunction_exists('mysql_connect'):\n"; 
var_dump(function_exists('mysql_connect'));

echo "\nvar_dump(class_exists('mysqli')):\n"; 
var_dump(class_exists('mysqli'));   

try{

    echo "\nUse PDO\n";
    $db = new PDO(
        'mysql:unix_socket='.MYSQL_HOST.';dbname='.MYSQL_DB.';charset=utf8',
        MYSQL_LOGIN,
        MYSQL_PASSWORD
    );
}catch(Exception $e){
    var_dump($e->__toString());
}

Output of the testing script:

function_exists('mysql_connect'):
bool(false)

var_dump(class_exists('mysqli')):
bool(false)

Use PDO
string(371) "exception 'PDOException' with message 'could not find driver' in C:\Work\gaetest\app\test.php:19
Stack trace:
#0 C:\Work\gaetest\app\test.php(19): PDO->__construct('mysql:unix_sock...', 'sample-login', 'sample-pass')
#1 C:\Users\pasha\appengine-php-sdk-1.8.0\google_appengine\google\appengine\tools\devappserver2\php\setup.php(45): require('C:\Work\gaetest...')
#2 {main}"

How can I use Google Cloud SQL from my PHP development server? Thank you.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/17025605/google-app-engine-php-and-cloud-sql

user1005242 via StackOverflow

unread,
Jun 11, 2013, 12:35:18 AM6/11/13
to google-appengin...@googlegroups.com

I'm attempting to connect to my Google Cloud SQL from my local development Google App PHP server. But PHP doesn't see function mysql_connect, it doesn't see class mysqli and it raises exception could not find driver when I'm attempting to connect with PDO class.


I run my development PHP server with a command:

"C:\Users\pasha\appengine-php-sdk-1.8.0\google_appengine\dev_appserver.py" --php_executable_path="C:\Users\pasha\php\php-cgi.exe" C:\Work\gaetest\


The app.yaml file has these contents:

application: gaetest
version: 1
runtime: php
api_version: 1

handlers:

- url: /(.*)
  script: app/\1

The testing sript is:

define('MYSQL_HOST', "/cloudsql/sample-project:sample-sql-instance");
define('MYSQL_LOGIN', "sample-login");
define('MYSQL_PASSWORD', "sample-pass");
define('MYSQL_DB', "sample-db");

echo "\nfunction_exists('mysql_connect'):\n"; 
var_dump(function_exists('mysql_connect'));

echo "\nclass_exists('mysqli'):\n"; 
var_dump(class_exists('mysqli'));   

try{

    echo "\nUse PDO\n";
    $db = new PDO(
        'mysql:unix_socket='.MYSQL_HOST.';dbname='.MYSQL_DB.';charset=utf8',
        MYSQL_LOGIN,
        MYSQL_PASSWORD
    );
}catch(Exception $e){
    var_dump($e->__toString());
}


Output of the testing script:

function_exists('mysql_connect'):
bool(false)

class_exists('mysqli'):
bool(false)

Use PDO
string(371) "exception 'PDOException' with message 'could not find driver' in C:\Work\gaetest\app\test.php:19
Stack trace:
#0 C:\Work\gaetest\app\test.php(19): PDO->__construct('mysql:unix_sock...', 'sample-login', 'sample-pass')
#1 C:\Users\pasha\appengine-php-sdk-1.8.0\google_appengine\google\appengine\tools\devappserver2\php\setup.php(45): require('C:\Work\gaetest...')
#2 {main}"

Stuart Langley via StackOverflow

unread,
Jun 11, 2013, 12:35:20 AM6/11/13
to google-appengin...@googlegroups.com

You cannot connect to the real CloudSQL instance from your development server. You need to test against a local install of MySQL when developing your app.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/17025605/google-app-engine-php-and-cloud-sql/17036551#17036551

Andrew J via StackOverflow

unread,
Jun 11, 2013, 2:35:25 AM6/11/13
to google-appengin...@googlegroups.com

It sounds like you need to install the mysql and mysqli extensions in your local environment.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/17025605/google-app-engine-php-and-cloud-sql/17037815#17037815

user1005242 via StackOverflow

unread,
Jun 12, 2013, 6:23:38 AM6/12/13
to google-appengin...@googlegroups.com

I have sold my problem.

  1. I have renamed php.ini-development file in php folder to php.ini
  2. Then I have enabled the needed extensions in my php.ini
  3. I have decommented the line extension_dir = "ext" in my php.ini, so php will now see the extensions.

That's all. Thank you.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/17025605/google-app-engine-php-and-cloud-sql/17062999#17062999
Reply all
Reply to author
Forward
0 new messages