我有一个 CodeIgniter 和一些 Mysql 数据库。但是知道我想设置另一个数据库来工作,并且在一些操作之后禁用它。例如,我有函数 make_some_actions_with_db(),现在我需要这样的东西:
public function action()
{
//load db
make_some_actions_with_db();
//disable db
}
所以,现在我需要知道如何设置新的默认数据库以及如何设置另一个(第一个)数据库。谢谢你。
更新: 它不起作用:
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);
}
}