Is it possible to connect two databases using hooks in CodeIgniter 3?

Viewed 40

Is it possible to connect two databases using hooks in CodeIgniter 3?

$CI =& get_instance();

$CI->load->database();

$query = $CI->db->get("tablename");
1 Answers

yes can you have define in database.php

    $db['db'] = array(
    'dsn'   => '',
    'hostname' => '',
    'username' => '',
    'password' => '',
    'database' => '',
    'dbdriver' => '',
    'dbprefix' => '',
    'pconnect' => TRUE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

and can call like this

$this->db1 = $CI->load->database('db',true);
Related