【问题标题】:CodeIgniter on App Engine time out whe concting to MySQL连接到 MySQL 时 App Engine 上的 CodeIgniter 超时
【发布时间】:2018-10-05 00:39:41
【问题描述】:

我在 GCP App Engine 上托管 CodeIgniter API,但无法连接到 GCP Cloud SQL。我创建了实例和数据库,但是当我尝试通过 CI 连接时,我收到了超时消息 错误屏幕

我在 CI 上的数据库配置是:

$db['default'] = array(
  'dsn' => 'mysql:unix_socket=/instance_name/instancia;dbname=project_name',
  'hostname' => 'http://00.000.00.00',//here i put the public ip from the sql instance
  'username' => 'user',
  'password' => 'passwd',
  'database' => 'projeto',
  'dbdriver' => 'mysqli',
  'dbprefix' => '',
  'pconnect' => FALSE,
  'db_debug' => (ENVIRONMENT !== 'production'),
  'cache_on' => FALSE,
  'cachedir' => '',
  'char_set' => 'utf8',
  'dbcollat' => 'utf8_general_ci',
  'swap_pre' => '',
  'encrypt' => yes,
  'compress' => FALSE,
  'stricton' => FALSE,
  'failover' => array(),
  'save_queries' => TRUE
);

【问题讨论】:

    标签: php mysql sql codeigniter google-app-engine


    【解决方案1】:

    我自己已经为此苦苦挣扎了一段时间,终于破解了!这是我的数据库配置的样子:

    $db['default'] = array(
      'dsn' => '',
      'hostname' => '/cloudsql/PROJECT-NAME:REGION:DATABASE',
      'username' => 'USERNAME',
      'password' => 'PASSWORD',
      'database' => 'DATABASE_NAME',
      'dbdriver' => 'mysqli',
      'dbprefix' => '',
      'pconnect' => FALSE,
      'db_debug' => (ENVIRONMENT !== 'production'),
      // 'db_debug' => TRUE,
      'cache_on' => FALSE,
      'cachedir' => '',
      'char_set' => 'utf8',
      'dbcollat' => 'utf8_general_ci',
      'swap_pre' => '',
      'encrypt' => FALSE,
      'compress' => FALSE,
      'stricton' => FALSE,
      'failover' => array(),
      'save_queries' => TRUE
    );
    

    重要的一点是 dsn 是空的,主机名是 unix 套接字的完整路径。其余的应该差不多。

    希望对你也有帮助!

    【讨论】:

    • 为了帮助其他人解决同样的问题,这个配置文件的哪一部分很重要,为什么?
    猜你喜欢
    • 2018-08-15
    • 2019-11-05
    • 2020-12-18
    • 2017-04-08
    • 2018-03-27
    • 1970-01-01
    • 1970-01-01
    • 2012-12-19
    • 2016-07-23
    相关资源
    最近更新 更多