检查代码信号查询错误,而不是向用户显示它们 [英] Check codeigniter query errors instead of showing them to the user
本文介绍了检查代码信号查询错误,而不是向用户显示它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查查询是否出错,而不是向用户显示错误(包含不安全的数据库信息)。
How can I check if a query went wrong instead of showing errors to users (containing database info which is unsafe).
假设我有这样的情况,分页类需要一个URI段来显示页面
。如果有人写这样
example.com/page/uri_segment example.com/page/bla_bla_bla
我得到一个错误,显示有关我的数据库的信息。
Let's say I have such situation where my paging class takes a URI segment to show page
example.com/page/uri_segment
. If someone write it like this example.com/page/bla_bla_bla
I get an error that shows information about my database.
如何处理此问题?
推荐答案
/database.php set
In application/config/database.php set
// suppress error output to the screen
$db['default']['db_debug'] = FALSE;
在您的模型或控制器中:
In your model or controller:
// try the select.
$dbRet = $this->db->select($table, $dataArray);
// select has had some problem.
if( !$dbRet )
{
$errNo = $this->db->_error_number()
$errMess = $this->db->_error_message();
// Do something with the error message or just show_404();
}
这篇关于检查代码信号查询错误,而不是向用户显示它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文