在 ci 框架中,使用封装的 curd 方法可以免去表前缀,如果新近添加的表没有填写表前缀,可使用如下方法解决。设置前缀为空,然后修改回来。
// 设置表前缀为空
$this->db->set_dbprefix('');
$catid = $cxdata['catid'];
$qishu = $cxdata['qishu'];
$count = $this->db->query("select id from tablename where catid='$catid' and qishu='$qishu'")->row();
if(0 == (int)$count->id){
// 不存在则添加
$this->db->insert('tablename ', $cxdata);
}else{
// 存在则修改
$this->db->where('id', $count->id)->update('tablename ', $cxdata);
}
// 表前缀更改回来,以免出错
$this->db->set_dbprefix('pre_');