[eluser]Sumon[/eluser]
Finally i sort it out how to access multiple database simultaneously.
Here is my config\database.php
Code:
$active_group = "default";
$active_record = TRUE;
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "";
$db['default']['database'] = "ci_practice";
$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['second_db']['hostname'] = "localhost";
$db['second_db']['username'] = "root";
$db['second_db']['password'] = "";
$db['second_db']['database'] = "dev_job";
$db['second_db']['dbdriver'] = "mysql";
$db['second_db']['dbprefix'] = "";
$db['second_db']['pconnect'] = FALSE;
$db['second_db']['db_debug'] = TRUE;
$db['second_db']['cache_on'] = FALSE;
$db['second_db']['cachedir'] = "";
$db['second_db']['char_set'] = "utf8";
$db['second_db']['dbcollat'] = "utf8_general_ci";
here is my controller
Code:
function duel_db2()
{
$this->load->model('test_model');
$user_data = $this->test_model->get_country(1);
print_r($user_data);
$user_data = $this->test_model->get_feedback(1);
print_r($user_data);
$this->load->database('default'); //Get Back into default.
}
and finally this is my model(test_model.php)
Code:
function get_country()
{
$DBTwo = $this->load->database('second_db', TRUE);
$query = $DBTwo
->from('countries')
->limit(10)
->where('id' , 10)
->get();
if ($query->num_rows() > 0)
{
$rows = $query->row_array();
return $rows;
}
return false;
}
function get_feedback($id)
{
$DBOne = $this->load->database('default', TRUE);
$query = $DBOne
->from('feedback')
->limit(10)
->where('id' , $id)
->get();
if ($query->num_rows() > 0)
{
$rows = $query->row_array();
return $rows;
}
return false;
}