Skip to content

Commit 94dc3d1

Browse files
author
Radovan Janjic
committed
ADDED: Debug backtrace for errors and logs.
1 parent d543de5 commit 94dc3d1

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

MySQL_wrapper.class.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,9 +716,9 @@ function error($msg, $web = FALSE) {
716716
}
717717
$nl = empty($_SERVER['REMOTE_ADDR']) ? PHP_EOL : "<br>" . PHP_EOL;
718718
$web = empty($_SERVER['REMOTE_ADDR']) ? FALSE : $web;
719-
$error = ($web ? "{$nl} - Error No: <a href=\"http://search.oracle.com/search/search?q={$this->errorNo}&amp;group=MySQL\">{$this->errorNo}</a>{$nl} - Error: {$this->error}" : "{$nl} - Error No: {$this->errorNo}{$nl} - Error: {$this->error}") . PHP_EOL;
719+
$error = ($web ? "{$nl} - Error No: <a href=\"http://search.oracle.com/search/search?q={$this->errorNo}&amp;group=MySQL\">{$this->errorNo}</a>{$nl} - Error: {$this->error}" : "{$nl} - Error No: {$this->errorNo}{$nl} - Error: {$this->error}{$nl} - Call: {$this->backtrace()}") . PHP_EOL;
720720
if ($this->logErrors)
721-
$this->log('ERROR', "NO -> {$this->errorNo} - DESC -> {$this->error}");
721+
$this->log('ERROR', "NO -> {$this->errorNo} - DESC -> {$this->error} - CALL -> {$this->backtrace()}");
722722
if ($this->displayError)
723723
echo $msg, $this->link ? $error : NULL;
724724
}
@@ -738,6 +738,18 @@ function log($type, $log) {
738738
}
739739
}
740740

741+
/** Debug Backtrace
742+
* @param void
743+
* @return string - Backtrace
744+
*/
745+
function backtrace() {
746+
foreach (debug_backtrace() as $t) {
747+
if ($t['file'] != __FILE__) {
748+
return "Function {$t['function']} in {$t['file']} on line {$t['line']}";
749+
}
750+
}
751+
}
752+
741753
/** Get Microtime
742754
* @return float - Current time
743755
*/

example.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
// create test table
2121
$db = new MySQL_wrapper(HOST, USER, PASS, DB);
22-
$db->connect();
22+
$db->connect();
2323

2424
// test table sql for examples
2525
$db->query("CREATE TABLE IF NOT EXISTS `table` (

0 commit comments

Comments
 (0)