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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
puckeye
Forum Contributor
Posts: 105
Joined: Fri Dec 06, 2002 7:26 pm
Location: Joliette, QC, CA
Contact:

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

Post 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.
User avatar
puckeye
Forum Contributor
Posts: 105
Joined: Fri Dec 06, 2002 7:26 pm
Location: Joliette, QC, CA
Contact:

Post 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
Post Reply