我在Codeigniter控制器_contruct中串联加载了两个不同的数据库。当我调用第二个数据库时,它可以正常工作,但是第一个加载的db指的是第二个加载的db。
function __construct(){
parent::__construct();
$this->liveDB = $this->load->database('liveDB', TRUE);
$this->metricsDB = $this->load->database('metricsDB', TRUE);
}我的行动
$this->metricsDB->query("") // working good
$this->liveDB->query("") // referring database metricsDB注意:如果我更改了__construct中的顺序,它就会相反。
发布于 2014-06-26 15:41:33
这可能是由于持久连接、设置
$db['livDB']['pconnect'] = FALSE;
$db['metricsDB']['pconnect'] = FALSE;在数据库配置中,看看这是否有帮助。
发布于 2013-08-14 08:23:14
看看CI用户指南
如果需要同时连接多个数据库,可以这样做:
$liveDB = $this->load->database('liveDB', TRUE);
$metricsDB = $this->load->database('metricsDB', TRUE);然后你可以使用:
$metricsDB->query();
$metricsDB->result();https://stackoverflow.com/questions/18225999
复制相似问题