使用cloud sql连接silex 2 dbal connect app引擎

时间:2017-10-28 02:37:08

标签: symfony google-app-engine google-cloud-sql silex dbal

我尝试从PHP flex env连接到云SQL几个小时,但我找到了答案。

我希望这有助于其他人。

An exception occured in driver: SQLSTATE[HY000] [2002] No such file or directory

Access denied for user 'root'@'cloudsql' (using password: NO)

1 个答案:

答案 0 :(得分:0)

1.-启用Google Cloud SQL API:https://console.cloud.google.com/apis/

enter image description here

2.-获取您的云sql实例名称

enter image description here

3.-将beta_settings添加到您的yaml

beta_settings:
    cloud_sql_instances: "here-your-instance-name"

4.-配置你的学说dbal unix_socket

$app->register(new Silex\Provider\DoctrineServiceProvider(), array(
    'dbs.options' => array (
        'db_conn' => array(
            'driver'    => 'pdo_mysql',
            'unix_socket' => '/cloudsql/here-your-instance-name',
            'host'      => 'localhost',
            'dbname'    => 'your-database',
            'user'      => 'your-user',
            'password'  => 'your-password',
            'charset'   => 'utf8',
            'collate'   => 'utf8_spanish2_ci'
        )
    )
));