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.
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}"
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.
It sounds like you need to install the mysql and mysqli extensions in your local environment.
I have sold my problem.
php.ini-development file in php folder to php.iniphp.iniextension_dir = "ext" in my php.ini, so php will now see the extensions.That's all. Thank you.