无法在Codeigniter中连接远程数据库服务器

时间:2019-04-04 11:50:47

标签: php database-connection codeigniter-3 mysqlconnection

我正在尝试将mysql远程服务器连接到我的codeigniter应用程序。我的mysql服务器在另一台机器上。因此,我正在使用IP地址连接该服务器。但这向我显示数据库错误

  

mysqli :: real_connect():(HY000 / 2002):主机没有路由

由于php和mysql版本是否兼容,我不是。这是我的数据库连接代码,

    $active_group = 'default';
    $query_builder = TRUE;

    $db['default'] = array(
      'dsn' => '',
      'hostname' => '1XX.13X.1XX.XX',
      'username' => 'username',
      'password' => 'paswword',
      'database' => 'database_name',
      'dbdriver' => 'mysqli',
      'dbprefix' => '',
      'pconnect' => FALSE,
      'db_debug' => (ENVIRONMENT !== 'production'),
      'cache_on' => FALSE,
      'cachedir' => '',
      'char_set' => 'latin1',
      'dbcollat' => 'latin1_german2_ci',
      'swap_pre' => '',
      'encrypt' => FALSE,
      'compress' => FALSE,
      'stricton' => FALSE,
      'failover' => array(),
      'save_queries' => TRUE
   );

1 个答案:

答案 0 :(得分:-1)

主机名没有任何变化,如下所示:

$active_group = 'default';
    $query_builder = TRUE;

    $db['default'] = array(
      'dsn' => '',
      'hostname' => 'localhost', // Nothing change Here
      'username' => 'Your database Username',
      'password' => 'your Database Password',
      'database' => 'database_name',
      'dbdriver' => 'mysqli',
      'dbprefix' => '',
      'pconnect' => FALSE,
      'db_debug' => (ENVIRONMENT !== 'production'),
      'cache_on' => FALSE,
      'cachedir' => '',
      'char_set' => 'latin1',
      'dbcollat' => 'latin1_german2_ci',
      'swap_pre' => '',
      'encrypt' => FALSE,
      'compress' => FALSE,
      'stricton' => FALSE,
      'failover' => array(),
      'save_queries' => TRUE
   );