我正在尝试从我的本地开发 Google App PHP 服务器连接到我的 Google Cloud SQL。但是 PHP 看不到 function mysql_connect
,它看不到 class并且当我尝试连接 PDO 类时mysqli
它会引发异常。could not find driver
我使用以下命令运行我的开发 PHP 服务器:
"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\
该app.yaml
文件具有以下内容:
application: gaetest
version: 1
runtime: php
api_version: 1
handlers:
- url: /(.*)
script: app/\1
测试脚本是:
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());
}
测试脚本的输出:
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}"
如何从我的 PHP 开发服务器使用 Google Cloud SQL?谢谢你。