我必须在 Controller 中使用两个数据库。即使我使用第二个参数 TRUE 加载第二个数据库以获取引用而不覆盖默认数据库,它也会替换默认数据库。知道加载第二个数据库时应该做什么。目前我正在加载如下。
$testDB = $this->load->database('preview',TRUE,FALSE);
最佳答案
将两个数据库的 pconnect 参数设置为 false
$db['preview']['pconnect'] = FALSE;
在你的 config/database.php 中
然后在连接到第二个数据库的模型上,像这样加载它:
class Example_m extends CI_Model {
function __construct(){
$CI =& get_instance();
parent::__construct();
$this->db = $CI->load->database('preview',TRUE);
}
关于php - 在 Codeigniter 中连接第二个数据库时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17543765/