I am developing like fair size project which is in developing stage using MySQL as a primary database. Now, client has some data, which is in postgres SQL, which can not be converted into MySQL. So, as I got to know that if the dbdriver is same for two databases, like if both the databases are MySQL then I am able to connect it. But here the issue is, there are two different database management systems with different DB drivers. So how to connect simultaneously both the databases? in my database.php file the code is:
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'xxx';
$db['default']['password'] = 'xxxxx';
$db['default']['database'] = 'xxxx';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = FALSE;
$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;
// ************************ anotherDatabase Connect *****************************************************
$db['database2']['hostname'] = 'xxx.xxx.xxx.xxx'; //ip address of the remote database
$db['database2']['username'] = 'xxxx';
$db['database2']['password'] = 'xxxx';
$db['database2']['database'] = 'xxxx';
$db['database2']['dbdriver'] = 'postgre';
$db['database2']['dbprefix'] = '';
$db['database2']['pconnect'] = TRUE;
$db['database2']['db_debug'] = TRUE;
$db['database2']['cache_on'] = FALSE;
$db['database2']['cachedir'] = '';
$db['database2']['char_set'] = 'utf8';
$db['database2']['dbcollat'] = 'utf8_general_ci';
$db['database2']['swap_pre'] = '';
$db['database2']['autoinit'] = TRUE;
$db['database2']['stricton'] = FALSE;
$db['database2']['port'] = 5433;
I have been searching for this for last one week and going through lots of posts but there is no clear information about it. To test it I have written the following code.
class C_test extends CI_Controller {
public function index()
{
echo "Test";
//$this->db->close();
//$db1 = $this->load->database('default',true);
$this->db2 = $this->load->database('database2',true);
echo "databasa Test ";
// $test1 = $db1->get('table_name')->result_array();
//print_r($test1);
//$this->db->close();
echo "=====================================================";
$test = $this->db2->get('table_name')->result_array();
//$test = $db2->get('admin')->result_array();
print_r($test);
}
}
$this->db2 = $this->load->database('database2',true);is not working, while$db1 = $this->load->database('default',true);is working, right?pconnecttoFALSE?$db['database2']['port'] = 5432;