php 如何关闭在 CodeIgniter 中显示到屏幕的 mysql 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/288559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to turn off mysql errors from being displayed to screen in CodeIgniter
提问by
Even though error_reporting is set to 0, database errors are still being printed to screen. Is there a setting somewhere I can change to disable database error reporting? This is for CodeIgniter v1.6.x
即使 error_reporting 设置为 0,数据库错误仍会打印到屏幕上。是否有我可以更改的设置以禁用数据库错误报告?这是用于 CodeIgniter v1.6.x
EDIT: Re: Fixing errors - Um, yes. I want to fix the errors. I get error notices from my error log, not from what my visitors see printed to their screen. That helps no one, and hurts my system's security.
编辑:回复:修复错误 - 嗯,是的。我想修复错误。我从我的错误日志中收到错误通知,而不是我的访问者在他们的屏幕上看到的打印内容。这对任何人都没有帮助,而且会损害我系统的安全性。
EDIT 2: Setting error_reporting to 0 does not affect CodeIgniter's built-in error logging class from writing to the error log.
编辑 2:将 error_reporting 设置为 0 不会影响 CodeIgniter 的内置错误日志类写入错误日志。
回答by
Found the answer:
找到答案:
In config/database.php:
在 config/database.php:
// ['db_debug'] TRUE/FALSE - Whether database errors should be displayed.
so:
所以:
$db['default']['db_debug'] = FALSE;
... should disable.
...应该禁用。
回答by NaturalBornCamper
In addition to Ian's answer, to temporarily disable the error messages:
除了伊恩的回答,暂时禁用错误消息:
$db_debug = $this->db->db_debug;
$this->db->db_debug = false;
// Do your sketchy stuff here
$this->db->db_debug = $db_debug;
回答by Tom Haigh
You don't want to change error_reporting to 0, because that will also suppress errors from being logged.
instead you should change display_errors to 0
您不想将 error_reporting 更改为 0,因为这也会禁止记录错误。
相反,您应该将 display_errors 更改为 0
This doesn't explain why you are getting errors displayed though, assuming error_reporting is actually 0. Maybe the framework handles these errors
这并不能解释为什么会显示错误,假设 error_reporting 实际上为 0。也许框架会处理这些错误
回答by Eli
You can edit the /errors/db_error.php file under the application directory - that is the template included for DB errors.
您可以编辑应用程序目录下的 /errors/db_error.php 文件 - 这是包含用于 DB 错误的模板。
However, you should really just fix the errors.
但是,您真的应该只修复错误。

