Hi everyone i am facing an error when i connect multiple database in CI. Can Someone point me to get right way when i connect to multiple DB.
this is my database.php file
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = 'root';
$db['default']['database'] = 'cizacl';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
$active_group = 'alternate';
$active_record = TRUE;
$db['alternate']['hostname'] = 'localhost';
$db['alternate']['username'] = 'root';
$db['alternate']['password'] = 'root';
$db['alternate']['database'] = 'vkwow_auth';
$db['alternate']['dbdriver'] = 'mysql';
$db['alternate']['dbprefix'] = '';
$db['alternate']['pconnect'] = TRUE;
$db['alternate']['db_debug'] = TRUE;
$db['alternate']['cache_on'] = FALSE;
$db['alternate']['cachedir'] = '';
$db['alternate']['char_set'] = 'utf8';
$db['alternate']['dbcollat'] = 'utf8_general_ci';
$db['alternate']['swap_pre'] = '';
$db['alternate']['autoinit'] = TRUE;
$db['alternate']['stricton'] = FALSE;
and then this is retrieve all the records function in my model
function getAll(){
$DB1 = $this->load->database('default',TRUE);
$DB2 = $this->load->database('alternate',TRUE);
//retrieve default DB
$query = $DB1->get('users');
if($query->num_rows() > 0){
foreach($query->result() as $row){
$data[] = $row;
}
return $data;
}
//retrieve alternate db
$query = $DB2->get('admins');
if($query->num_rows() > 0){
foreach($query->result() as $row){
$data[] = $row;
}
return $data;
}
}
this is my output view code
<p>
<?php foreach($records as $row) : ?>
<h1><?php echo $row->user_username;?></h1>
<?php endforeach; ?>
</p>
<p>
<?php foreach($records as $row) : ?>
<h1><?php echo $row->username;?></h1>
<?php endforeach; ?>
</p>
when i run this program i got the error Table ‘vkwow_auth.users’ doesn’t exist
I appreciate any feedback/right way to connect multiple DB.