In /config/database.php
Create a new set of configuration for db connection
$db['seconddb']['hostname'] = 'localhost';
$db['seconddb']['username'] = 'krish';
$db['seconddb']['password'] = 'pass';
$db['seconddb']['database'] = 'oOoOoO';
$db['seconddb']['dbdriver'] = 'mysql';
$db['seconddb']['dbprefix'] = '';
$db['seconddb']['pconnect'] = TRUE;
$db['seconddb']['db_debug'] = TRUE;
$db['seconddb']['cache_on'] = FALSE;
$db['seconddb']['cachedir'] = '';
$db['seconddb']['char_set'] = 'utf8';
$db['seconddb']['dbcollat'] = 'utf8_general_ci';
$db['seconddb']['swap_pre'] = '';
$db['seconddb']['autoinit'] = TRUE;
$db['seconddb']['stricton'] = FALSE;
Loading the db
$this->load->database('seconddb');
To connect to multiple databases
$db1 = $this->load->database('default', TRUE);
$db2 = $this->load->database('seconddb', TRUE);
and the syntax changes a lil bit for active records.
Instead of
$this->db->query();
you should use
$db1->query();
and
$db2->query();
so ,just edit your queries as required.