我想从MySQL中的另一个数据库中获得数据,除了默认的数据库.除了执行代码之外,我还在我的模型中添加了以下代码行.另一个数据库,即‘storresDB’.
$this->load->database('storesDB', TRUE);
我的模型如下:
public function getEquipment($id = null)
{
$this->db->select('*');
$this->db->from('tbl_equipment');
$this->db->join('tbl_equipment_category', 'tbl_equipment.eq_cat=tbl_equipment_category.id_cat');
$this->db->where("tbl_equipment.status", '1');
if ($id)
$this->db->where("tbl_equipment.id", $id);
$query = $this->db->get();
return $query->result();
}
代码运行正常.但该代码从defualt DB获取数据,而不是从‘storesDB’获取数据.
修改后的代码如下:
public function getEquipment($id = null)
{
$this->load->database('storesDB', TRUE);
$this->db->select('*');
$this->db->from('tbl_equipment');
$this->db->join('tbl_equipment_category', 'tbl_equipment.eq_cat=tbl_equipment_category.id_cat');
$this->db->where("tbl_equipment.status", '1');
if ($id)
$this->db->where("tbl_equipment.id", $id);
$query = $this->db->get();
return $query->result();
}
可能的原因是什么?