I am trying to connect mysql remote server to my codeigniter applications. My mysql server is in other machine. So I am using the IP address to connect that server. But It is showing me database error

mysqli::real_connect(): (HY000/2002): No route to host

I am not is it because of the php and mysql version compatibility or not. Here is my database connection code,

    $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 Answers

-1
Kamiyabali Sunasara kamu On

You don't have any change in hostname Like below :

$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
   );