Reputation: 931
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}"
How can I use Google Cloud SQL from my PHP development server? Thank you.
Upvotes: 1
Views: 2502
Reputation: 168
You have to copy php.ini into the project local path (the same directory as the app.yaml file) with the pdo extension uncommented.
https://cloud.google.com/appengine/docs/standard/php/config/php_ini
It works for me.
Upvotes: 0
Reputation: 2326
Follow the instructions here:
https://developers.google.com/appengine/downloads#Google_App_Engine_SDK_for_PHP
HOWEVER, you should use this configure command:
./configure --prefix=$PWD/installdir --enable-bcmath --with-mysql --with-pdo-mysql
You might be able to run that configure command after-the-fact, but I'm unsure TBH
Upvotes: 1
Reputation: 931
I have sold my problem.
php.ini-development
file in php
folder to php.ini
php.ini
extension_dir = "ext"
in my php.ini
, so php will now see the extensions.That's all. Thank you.
Upvotes: 0
Reputation: 2001
It sounds like you need to install the mysql and mysqli extensions in your local environment.
Upvotes: 0
Reputation: 7054
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.
Upvotes: 1