From 60f8c395f24ba6db80d510892bcc53ce5bf9f4eb Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Wed, 25 Aug 2010 18:03:28 +0200 Subject: Modified the database driver's display_error() method to show the filename and line number of the failed query. --- system/database/DB_driver.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'system/database/DB_driver.php') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index dfef42757..8e6f88801 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1169,6 +1169,24 @@ class CI_DB_driver { $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; } + // Find the most likely culprit of the error by going through + // the backtrace until the source file is no longer in the + // database folder. + + $trace = debug_backtrace(); + + foreach($trace as $call) + { + if (isset($call['file']) && strpos($call['file'], BASEPATH.'database') === FALSE) + { + // Found it - use a relative path for safety + $message[] = 'Filename: '.str_replace(array(BASEPATH, APPPATH), '', $call['file']); + $message[] = 'Line Number: '.$call['line']; + + break; + } + } + $error =& load_class('Exceptions', 'core'); echo $error->show_error($heading, $message, 'error_db'); exit; -- cgit v1.2.3-24-g4f1b