RE: [PHP] get current line number
| From: | Matt Schroebel | Date: | Thu, 20 Jun 2002 15:32:50 +0000 |
| Subject: | RE: [PHP] get current line number | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-103148@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Erik Price [mailto:pricee@hhbrown.com]
> Sent: Thursday, June 20, 2002 10:14 AM
> I've searched the manual and the archives, but can't find out
> if there
> is a way to get the current line number of execution. I am writing a
> function, and want to write an error trap using die() like this:
>
> if (!$result = mysql_query($sql, $db)) {
> $line_number = // function to get current line number
> die("Query failed in listbox_generator() on line " .
> $line_number);
I use this function all the time:
// -------------------------------------------------------------------------
// logs to syslog define the constant DISPLAY_MYSQL_ERRORS as 1
// if you want to see errors in browser too
// usage: $result = mysql_query($sql,$db)
// or die(log_mysql_error($sql,__FILE__,__LINE__));
// -------------------------------------------------------------------------
function log_mysql_error($sql='',$file='',$line=0) {
$msg="{$_SERVER['PHP_SELF']}: (FILE=$file) (LINE=$line)\n);
if (!empty($sql)) {
$msg .= "SQL Statement was: $sql";
}
error_log($msg,0);
if (1 == DISPLAY_MYSQL_ERRORS) {
echo "<br>$msg<br>\n";
}
exit;
}