公喜發財 发表于 2013-3-5 11:11:51

请教CI如何捕获SQL语句异常

$this->db->where($conArray);
$dataList=$this->db->get($this->_table)->result_array();

conArray是条件数组,当里面的字段都正常的时候,可以正确执行,但是当字段异常比如原本的 id=>1 改成idtest=>1就报错了
提示Unknown column 'idtest' in 'where clause'

那么在CI中,如何处理这种类似的SQL错误呢?

小弟尝试用过CI提供的事务方法
$this->db->trans_start();
........
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE)
{
.........................
}
但还是捕获不到异常,直接就报错了

现向各位大神求救,如何处理,望不吝赐教小弟感激不尽啊!~

mark35 发表于 2013-3-5 18:32:03


                        $error_msg = $this->db->_error_message();
页: [1]
查看完整版本: 请教CI如何捕获SQL语句异常