database.php :
$db['default']['hostname'] = "192.168.2.104";
$db['default']['username'] = "webuser";
$db['default']['password'] = "----";
$db['default']['database'] = "vad";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
$db['stats']['hostname'] = "192.168.2.104";
$db['stats']['username'] = "webuser";
$db['stats']['password'] = "---";
$db['stats']['database'] = "vad_stats";
$db['stats']['dbdriver'] = "mysql";
$db['stats']['dbprefix'] = "";
$db['stats']['pconnect'] = TRUE;
$db['stats']['db_debug'] = TRUE;
$db['stats']['cache_on'] = FALSE;
$db['stats']['cachedir'] = "";
$db['stats']['char_set'] = "utf8";
$db['stats']['dbcollat'] = "utf8_general_ci";
问题是我只能在配置中定义一个
$active_group
,默认值或统计信息。我遵循了CodeIgniter文档,并添加了以下内容:$DB2 = $this->load->database('stats', TRUE);
这样,我连接到第二个数据库,但是失去了与第一个数据库的连接。有没有人对如何加载两个数据库有任何想法,而不必在所有模型构造函数中执行以下操作?
$database1 = $this->load->database('database1', TRUE);
$database2 = $this->load->database('database2', TRUE);
问候,
佩德罗
最佳答案
除了应用Camacho提到的hack之外,您还可以将database.php文件中的'pconnect'标志设置为FALSE来进行所有连接。
关于php - Codeigniter-使用多个数据库,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/634291/