记录mysql错误,最佳做法 [英] Error logging mysql, best practice
问题描述
我想保留跟踪查询执行失败(不是问题),但我也想知道这发生了什么行和文件。我在几个脚本中看到了 __ LINE __
,但我从来没有想过如何使用它。
我的基础看起来像这样:
$ query ='SELECT * ...';
$ result = mysql_do_query($ query);
函数mysql_do_query($ q){
[...]
}
我真正的问题是是否可以记录从$调用函数 mysql_do_query
的位置?什么行等等还是有另一种方法来做到这一点?尝试和例外吗?
您可以使用魔术常数,或 debug_backtrace ,或者编写自己的错误处理程序。
I got a "big" Facebook-application coming up. It is programmed in php using mysql (and the mysql_-class, not PDO...I know, I know). As I am close to an open beta, I'd like to keep track of any mysql-errors. I have a good host and I know that the script never looses connection to the database, so I thought I could store this in a table.
I'd like to keep track of the query doing failing (not a problem), but I'd also like to know what line and file this happened in. I've seen __LINE__
in a few scripts, but I never figured out how to use it.
My base simply looks like this:
$query = 'SELECT * ...';
$result = mysql_do_query($query);
function mysql_do_query ($q) {
[...]
}
My real question is; is it possible to log where the function mysql_do_query
was called from? What line etc. Or is there another way to do this? Try and exceptions, perhaps?
You can use magic constants, or debug_backtrace, or write your own error handler.
这篇关于记录mysql错误,最佳做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!