MySQLi 错误处理
是否可以指定 MySQLi 将任何错误和警告发送到 PHP 默认的“error_log”指令?我似乎找不到类规范的任何错误选项,并且我不希望像这样手动处理错误:
if ($result = $mysqli->query("...")) { }
else
handle $mysqli->error;
Is it possible to specify that MySQLi sends any errors and warnings to the PHP default 'error_log' directive? I can't seem to find any error options for the class specification, and I don't wish to handle errors manually like so:
if ($result = $mysqli->query("...")) { }
else
handle $mysqli->error;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,一种方法是重写该类:
然后照常使用,只不过不是通过 new MySQLi() 创建连接,而是使用 new myMySQLi() 。除了错误处理之外,它的运行方式是一样的。我经常这样做,抛出错误异常并向 MySQLi 添加附加功能......
Well, one way would be to override the class:
Then just use as normal, except instead of creating an connection via
new MySQLi()
, usenew myMySQLi()
. Other than the error handling, it'll run just the same. I do this quite often, to throw exceptions on errors and to add additional functionality to MySQLi...当然,这是可能的。您所要做的就是启用自动错误报告并告诉 PHP 将所有错误记录到文件中。
在使用 mysqli 打开连接之前,您应该确保启用了这两个设置:
您不再需要手动检查 mysqli 错误,所有错误都将记录到文件中。
Of course, it is possible. All you have to do is enable automatic error reporting and tell PHP to log all errors into a file.
Before you open a connection using mysqli you should ensure that you have these two settings enabled:
You don't need to check for mysqli errors manually anymore and all errors will be logged to a file.