CodeIgniter - 如何捕获DB错误? [英] CodeIgniter - how to catch DB errors?
本文介绍了CodeIgniter - 如何捕获DB错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种方法使CI在遇到DB错误时抛出异常,而不是显示以下消息:
Is there a way to make CI throw an exception when it encounters a DB error instead of displaying a message like:
A Database Error Occurred
Error Number: 1054
Unknown column 'foo' in 'where clause'
SELECT * FROM (`FooBar`) WHERE `foo` = '1'
注意:我只想要在一个控制器中发生。
NOTE: I only want this to happen in one controller. In the other controllers, I'm happy for it to display the DB error messages.
推荐答案
尝试使用这些CI函数
$this->db->_error_message(); (mysql_error equivalent)
$this->db->_error_number(); (mysql_errno equivalent)
这篇关于CodeIgniter - 如何捕获DB错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文