简体   繁体   English

无法使用ZF2中的Pdo_Mysql通过Google App Engine连接到Google Cloud SQL

[英]Cannot connect to Google Cloud SQL through Google App Engine with Pdo_Mysql in ZF2

I have been trying to solve this issue already for a few days without any results. 我已经尝试解决这个问题几天了,没有任何结果。 When using default php pdo object I can connect to the database: 当使用默认的php pdo对象时,我可以连接到数据库:

$db = new \PDO('mysql:unix_socket=/cloudsql/project-id:database-instance;dbname=test',
          'root',  // username
          ''       // password
        );

But when trying to connect with ZF2 adapter the connection just times out. 但是,当尝试与ZF2适配器连接时,连接只是超时。

'db' => array(
        'driver' => 'Pdo_Mysql',
        'database' => 'test',
        'username' => 'root', 
        'unix_socket' => '/cloudsql/project-id:database-instance',
),

I am quite sure that the problem is somehow with the unix_socket as I can connect to the Cloud SQL server from my localhost directly without socket: 我非常确定unix_socket会出现问题,因为我可以直接从本地主机连接到Cloud SQL Server,而无需套接字:

'db' => array(
        'driver' => 'Pdo_Mysql',
        'host' => 'xxx.xxx.xxx.xxx',
        'database' => 'test',
        'username' => 'user',
        'password' => 'password',

),

What I am missing? 我缺少什么?

unix_socket isn't a recognized option for the pdo driver ( https://github.com/zendframework/zf2/blob/master/library/Zend/Db/Adapter/Driver/Pdo/Connection.php#L164 ). unix_socket不是pdo驱动程序的公认选项( https://github.com/zendframework/zf2/blob/master/library/Zend/Db/Adapter/Driver/Pdo/Connection.php#L164 )。 Try this instead 试试这个

'db' => array(
        'dsn' => 'mysql:unix_socket=/cloudsql/project-id:database-instance;dbname=test',
        'username' => 'user',
        'password' => 'password',    
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM