快速调试php文件,调试php。文件和行 (Debugging php. file and line)

本文详细解释了如何在函数中使用debug_backtrace来定位数据库错误,并提供了在PHP中避免冗余mysql_error调用的建议,推荐转向MySQLi。通过示例代码演示了如何创建自定义错误报告。
摘要由CSDN通过智能技术生成

英文原文

Realistically, you should be using debug_backtrace for this.

Eg:

function error(){

$trace = debug_backtrace();

$file = $trace[1]['file']; // use 1 because you don't want

// to include this function!

// 2 will be the function which called the function

// which called this function.

$line = $trace[1]['line'];

trigger_error("DB error in *{$file}* on line {$line}
\n " .

// You really should consider using MySQLi instead of MySQL

mysql_error() . "" . @mysql_error($this->dbl), E_USER_ERROR);

// why do you have two mysql_error calls???

}

中文翻译

例如:

function error(){

$ trace = debug_backtrace();

$ file = $ trace [1] ['file']; //使用1,因为你不想要

//包含这个功能!

// 2将是调用函数的函数

//调用了这个函数。

$ line = $ trace [1] ['line'];

trigger_error(" *< b> {$ file}< / b> *中的数据库错误*行< b> {$ line}< / b>< br /> \ n" 。

//你真的应该考虑使用MySQLi而不是MySQL

mysql_error()。 " " 。 @mysql_error($ this-> dbl),E_USER_ERROR);

//为什么你有两个mysql_error调用???

}

Realistically, you should be using debug_backtrace for this.

Eg:

function error(){

$trace = debug_backtrace();

$file = $trace[1]['file']; // use 1 because you don't want

// to include this function!

// 2 will be the function which called the function

// which called this function.

$line = $trace[1]['line'];

trigger_error("DB error in *{$file}* on line {$line}
\n " .

// You really should consider using MySQLi instead of MySQL

mysql_error() . "" . @mysql_error($this->dbl), E_USER_ERROR);

// why do you have two mysql_error calls???

}

例如:

function error(){

$ trace = debug_backtrace();

$ file = $ trace [1] ['file']; //使用1,因为你不想要

//包含这个功能!

// 2将是调用函数的函数

//调用了这个函数。

$ line = $ trace [1] ['line'];

trigger_error(" *< b> {$ file}< / b> *中的数据库错误*行< b> {$ line}< / b>< br /> \ n" 。

//你真的应该考虑使用MySQLi而不是MySQL

mysql_error()。 " " 。 @mysql_error($ this-> dbl),E_USER_ERROR);

//为什么你有两个mysql_error调用???

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值