在Codeigniter Mongo类中切换DB

时间:2011-02-23 09:54:46

标签: php codeigniter mongodb

我正在使用codeigniter mongo类。我在configigniter中的config / mongo.php中存储配置信息,如mongohost,mongodb name等。但是,我想在我的代码中的某些地方切换db名称,而不必每次都重新编写config / mongo.php。是否有交换机db功能或任何其他方式?

2 个答案:

答案 0 :(得分:0)

You can set another in the config aside from your default one

// your code
$this->load->database('test');

// config
$db['test']['hostname'] = "localhost";
$db['test']['username'] = "root";
$db['test']['password'] = "";
$db['test']['database'] = "database_name";
$db['test']['dbdriver'] = "mysql";
$db['test']['dbprefix'] = "";
$db['test']['pconnect'] = TRUE;
$db['test']['db_debug'] = FALSE;
$db['test']['cache_on'] = FALSE;
$db['test']['cachedir'] = "";
$db['test']['char_set'] = "utf8";
$db['test']['dbcollat'] = "utf8_general_ci";
$db['test']['swap_pre'] = "";
$db['test']['autoinit'] = TRUE;
$db['test']['stricton'] = FALSE;

答案 1 :(得分:0)

$this->mongo->switch_db("data base name");

这应该会成功切换数据库。