检查 codeigniter 查询错误而不是将它们显示给用户 [英] Check codeigniter query errors instead of showing them to the user

查看:24
本文介绍了检查 codeigniter 查询错误而不是将它们显示给用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查查询是否出错而不是向用户显示错误(包含不安全的数据库信息).

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.

我该如何处理?

推荐答案

在application/config/database.php中设置

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();
}

这篇关于检查 codeigniter 查询错误而不是将它们显示给用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆