无法将App Engine上的Laravel应用程序连接到Cloud SQL数据库 [英] Not able to connect Laravel application on App Engine to Cloud SQL database

查看:72
本文介绍了无法将App Engine上的Laravel应用程序连接到Cloud SQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行在Google App Engine上的Laravel应用程序,我想将其连接到我拥有的Google Cloud SQL数据库.我尝试了许多解决方案,但都没有解决问题.每当它向数据库发出请求时,它都会抛出
SQLSTATE [HY000] [2002]没有这样的文件或目录(SQL:从 sessions 中选择*,其中 id = CQZwtQFAm5RCYcP4ZSqf5mtxTnebGUigQQKVluJa限制1).
我确实有会话表,尝试登录但又使用用户表时也出现此错误.

I have a Laravel application running on Google App Engine and I want to connect it to the Google Cloud SQL database I have. I have tried many solutions none of them fixed the problem. Everytime it does a request to the database, it throws
SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from sessions where id = CQZwtQFAm5RCYcP4ZSqf5mtxTnebGUigQQKVluJa limit 1).
I do have the sessions table, and I also get this error while trying to log in but with the users table then.

我正在尝试更改所有环境变量,编辑config/database.php文件,...

I've trying changing up all the environment variables, editing the config/database.php file, ...

在这里我的app.yaml:

Heres my app.yaml:

runtime: php
env: flex

runtime_config:
  document_root: public

env_variables:
  APP_ENV: production
  APP_DEBUG: true
  APP_LOG: errorlog
  APP_KEY: mykey
  APP_TIMEZONE: "Europe/Brussels"
  CACHE_DRIVER: database
  SESSION_DRIVER: database

  DB_HOST: localhost
  DB_DATABASE: data
  DB_USERNAME: root # tried custom user aswell
  DB_PASSWORD: mypassword
  DB_SOCKET: "/cloudsql/projectname:region:instancename"

beta_settings:
  cloud_sql_instances: "projectname:region:instancename"

这是config/database.php的一部分(大部分未经编辑):

Here is a part of config/database.php (mostly unedited):

'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

很显然,我希望此连接成功.让我知道是否需要更多代码部分.

Obviously I want this connection to be succesful. Let me know if you need any more code parts.

预先感谢

推荐答案

请更改此行:

cloud_sql_instances: "projectname:region:instancename"

进入此行:

cloud_sql_instances:projectname:region:instancename

如果这不起作用,请检查

If that doesn't work, please check this link and activate your API if you haven't done so.

此外,如果启用API仍无法解决问题,请将 cloud_sql_instances 变量还原为该值具有双引号.

Also, if enabling the API didn't solve the issue, please revert the cloud_sql_instances variable to having double quotes on the value.

这篇关于无法将App Engine上的Laravel应用程序连接到Cloud SQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆