Page 1 of 1

Sending error notices along with line numbers by email...

Posted: Mon Feb 17, 2003 1:57 pm
by puckeye
Hi guys/gals,

I've started sending MySQL errors to my email instead of directly on the site and this for 2 major reasons.

1) the page continues on without error
2) I can manage the error and activate this or that function depending on the error.

What I would like to know is how to send the PHP line number when such an error occurs.

Here's a possible event.

I have a MySQL query which may or may not be well formed, when I use the mysql_query function I also use the OR keyword to MAIL() the mysql_error() along with the query string and the filename. Now what I would like to be able to do is to send the line number where the error occurs. Is that possible?

I guess it's possible because PHP returns the line number when it encounters a syntax error or parse error...

I've never played with trigger_error () would that be usefull?

Thanks for the help.

Posted: Mon Feb 17, 2003 2:27 pm
by puckeye
Well...

Guess what? I found the way to include line numbers into my mail notice...

Simply use __FILE__ and __LINE__ to write the filename and line number...

I used it like this:

Code: Select all

<?php
$result	=	mysql_query($query) OR mail("MY@EMAIL", "error notice", mysql_error()."\n\n".$query."\n\nError in file : ".__FILE__." one line :  ".__LINE__);
?>
edit 1: __FILE__ and __LINE__ are constants check them out here Predefined constants