记录mysql错误,最佳做法 [英] Error logging mysql, best practice

查看:100
本文介绍了记录mysql错误,最佳做法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大的Facebook应用程序。它是用php编程的,使用mysql(和mysql_类,而不是PDO ...我知道,我知道)。当我接近一个公开测试版时,我想跟踪任何mysql错误。我有一个很好的主机,我知道这个脚本永远不会丢失到数据库的连接,所以我以为我可以把它存储在一个表中。



我想保留跟踪查询执行失败(不是问题),但我也想知道这发生了什么行和文件。我在几个脚本中看到了 __ 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屋!

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