CI 跨資料庫存取

要在CI做跨資料庫存取的方式
1.設定database.php
$db[‘db2’][‘hostname’] = ‘localhost’;
$db[‘db2’][‘username’] = ‘aaa’;
$db[‘db2’][‘password’] = ‘aaa’;
$db[‘db2’][‘database’] = ‘aaa’;
$db[‘db2’][‘dbdriver’] = ‘mysql’;
$db[‘db2’][‘dbprefix’] = ”;
$db[‘db2’][‘pconnect’] = ! TRUE;
$db[‘db2’][‘db_debug’] = TRUE;
$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’] = TRUE;
$db[‘db2’][‘stricton’] = FALSE;

第一維索引為你之後引用的名稱
2.
在controller的設定
$db2= $this->load->database(‘db2’);
$where = array(‘app_type’=>’ios’);
$db2->select(‘id,’app_type’)->from(“apps”)->where($where);
$rs = $db2->get()->result_array();
print_r($db2);
$this->load->database 是用來載入資料庫設定的,按照CI的設計,他們用第一維索引當作判斷載入資料庫設定的群組名稱
收工