我有一個CodeIgniter和一些Mysql數據庫。但知道我想設置另一個數據庫的工作,並在一些行動後禁用它。例如,我有功能make_some_actions_with_db(),現在我需要有類似的東西:如何使用CodeIgniter加載另一個數據庫?
public function action()
{
//load db
make_some_actions_with_db();
//disable db
}
所以,現在我需要知道如何設置新的默認數據庫,我怎麼可以設置其他(第一) D b。謝謝。
更新: 它不工作:
public function update_record_insert_test()
{
if ($this->facebook->getUser())
{
$another_db_settings['hostname'] = 'localhost';
$another_db_settings['username'] = 'root';
$another_db_settings['password'] = '';
$another_db_settings['database'] = 'name';
$another_db_settings['dbdriver'] = "mysql";
$another_db_settings['dbprefix'] = "";
$another_db_settings['pconnect'] = TRUE;
$another_db_settings['db_debug'] = TRUE;
$another_db_settings['cache_on'] = FALSE;
$another_db_settings['cachedir'] = "";
$another_db_settings['char_set'] = "utf8";
$another_db_settings['dbcollat'] = "utf8_general_ci";
$this->load->database($another_db_settings);
$_POST['id']='AccountPagesView.a_book/1000';
$_POST['value']='test';
$_POST['old_value']='not';
$welcome=new Welcome();
$welcome->update_record();
}
else
{
$url=$this->facebook->getLoginUrl(array('next' => base_url().'update_record_insert_test'));
redirect($url);
}
}
到另一個變量的新連接現在,我讓使用$所有請求,這 - > DB->得到(.. ),並且我不能更改此代碼,但是有相同的db和相同的表,我需要更改默認db這一個。我如何做到這一點?例如,現在我有「db1」數據庫,第二個是「db1_copy」 - 我需要類似$ this-> db - > ...的所有請求都將使用「db1_copy」執行。 – user1477886
如果您可以更改配置,請將'default'組的詳細信息更改爲'db1_copy'的詳細信息。這應該工作? – cchana
不,我剛剛嘗試過,它不起作用。 – user1477886