I try to connect to the MySQL database in CI
if the connection to the first DB fails, I try to connect to the second,
I use this code in the CI forum:
http://ellislab.com/forums/viewthread/224522/#1030449
$db_obj = $this->database->load('xxx',TRUE);
$connected = $db_obj->initialize();
if (!$connected) {
$db_obj = $this->database->load('yyy',TRUE);
}
it works fine on the local host, it tries to connect to the 1st database and fail, and then connect directly to the 2nd database (without any long-term transparency)
<b> but
when I moved my code to online server, it took a long time to try to connect to the 1st database, then (after this timeout) tried to connect the 2nd database and succeed
how can I remove this waiting time? I need it to directly try to connect to another DB in case of failure
my DB configuration is as follows:
$db['DB1']['hostname'] = '1.1.1.1';
$db['DB1']['username'] = 'test';
$db['DB1']['password'] = '123456';
$db['DB1']['database'] = 'db1';
$db['DB1']['dbdriver'] = 'mysql';
$db['DB1']['dbprefix'] = '';
$db['DB1']['pconnect'] = TRUE;
$db['DB1']['db_debug'] = FALSE;
$db['DB1']['cache_on'] = FALSE;
$db['DB1']['cachedir'] = '';
$db['DB1']['char_set'] = 'utf8';
$db['DB1']['dbcollat'] = 'utf8_general_ci';
$db['DB1']['swap_pre'] = '';
$db['DB1']['autoinit'] = FALSE;
$db['DB1']['stricton'] = FALSE;
$db['DB2']['hostname'] = '1.1.1.1';
$db['DB2']['username'] = 'test';
$db['DB2']['password'] = '123456';
$db['DB2']['database'] = 'db2';
$db['DB2']['dbdriver'] = 'mysql';
$db['DB2']['dbprefix'] = '';
$db['DB2']['pconnect'] = TRUE;
$db['DB2']['db_debug'] = FALSE;
$db['DB2']['cache_on'] = FALSE;
$db['DB2']['cachedir'] = '';
$db['DB2']['char_set'] = 'utf8';
$db['DB2']['dbcollat'] = 'utf8_general_ci';
$db['DB2']['swap_pre'] = '';
$db['DB2']['autoinit'] = FALSE;
$db['DB2']['stricton'] = FALSE;
Many thanks!
jodi source
share