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";
问题是我只能在配置中定义one $active_group,default或stats。我遵循了CodeIgniter文档,并添加了以下内容:
$active_group
$DB2 = $this->load->database('stats', TRUE);
这样,我连接到第二个数据库,但是失去了与第一个数据库的连接。有谁对如何加载两个数据库有任何想法,而不必在所有模型构造函数中执行以下操作?
$database1 = $this->load->database('database1', TRUE); $database2 = $this->load->database('database2', TRUE);
问候,
佩德罗
除了应用Camacho提到的hack之外,您还可以将database.php文件中的’pconnect’标志设置为FALSE来进行所有连接。