查找mysql错误发生的位置 [英] Finding mysql error occured location

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

问题描述

我收到此 mysql 错误

I am getting this mysql error

"您的 SQL 语法有错误;检查对应的手册您的 MySQL 服务器版本在 'AND ( 附近使用的正确语法XYZField = 5)' 在第 1 行

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND ( XYZField = 5)' at line 1 "

此错误未提供有关 mysql 错误发生位置的信息,我的意思是文件名、函数和行号.有什么方法可以检索此信息?

This error doesnt give information about mysql error occured location , i mean filename, function and line number.Is there any way to retrieve this info?

推荐答案

你可以做到.您必须创建自己的错误处理程序.这将需要您提供额外的代码.

You can do. You have to create you own error handler. This will require a extra code from your side.

例如:-

假设您正在使用 mysql_ 系列函数和 PHP

Assuming you are using mysql_ family function and PHP

当您调用任何查询时,您必须处理这些 mysql 错误,并且可以传递一些包含函数、文件名信息的变量来自定义错误.

When you invoke any query you have to handle these mysql errors and can pass some of the variable containing function, file name info to customize errors.

查看 PHP 的 debug-backtrace 函数,这将给出你需要什么.当前行号、文件名、函数名、类名.

Look at the debug-backtrace function of PHP this will give you what you needed. The current line number, file name function name, class name.

您可以从该函数中获取数据并将它们与 mysql_error() 函数一起传递给 trigger_error

You can get data from this function and pass them into the trigger_error along with mysql_error() function

  mysql_query('SELECT ....') or trigger_error(mysql_error().' in the file 
'.$filename.' with function'.$function_name)

这只是一个你可以做得更好的方向.

This is just a direction you can do even better from this.

在 OP 评论后编辑

您已经自定义了数据库类

You have customized database class

function db_error($query, mysql_errno(), mysql_error())
{
   $info=debug_backtrace();
   //This return array containing file name, line number function name etc
   //your rest code to display errors
}

这篇关于查找mysql错误发生的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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