- 关闭 框架的 数据库db_debub 参数,当debug 开启的时候 ,报错会直接抛出到页面
$db['default']['db_debug'] = FALSE;
- 使用 driver 的 error()function 捕捉
mysqli源代码
public function error()
{
if ( ! empty($this->_mysqli->connect_errno))
{
return array(
'code' => $this->_mysqli->connect_errno,
'message' => is_php('5.2.9') ? $this->_mysqli->connect_error : mysqli_connect_error()
);
}
return array('code' => $this->conn_id->errno, 'message' => $this->conn_id->error);
}
demo 代码
$query = $db->get();
$error = $db->error();
if($error['code'] > 0)
{
throw xxxx
}
return $query->result_array();