Line number reference

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
w35z0r
Forum Newbie
Posts: 17
Joined: Thu May 18, 2006 7:02 pm

Line number reference

Post by w35z0r »

Hello,
I was writting or die statements for my mysql statements and I was wondering if there was a way I could reference the line they occurred on without hard coding it in. Basically like when PHP returns and error and tells you what line its on.
Right now, I basically give a vauge descritpion of the statement that failed along with the mysql_error() function.
Example:

Code: Select all

 
mysql_query("UPDATE eo_tbl02 SET blendsWW = CONCAT(blendsWW, '$appendLink') WHERE productNumber='$pn'") or die("died while appending a bww, " . mysql_error()); 
 
This does the job well enough, but I think it'd be sweet if I could say what line as well.
Any thoughts?

--W
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: Line number reference

Post by yacahuma »

You should not use "or die" statement in production code. I dont think you want a user to see a big die when half you page has been generated already.
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Re: Line number reference

Post by jmut »

__LINE__ constant might be of interested
debug_backtrace(), array_shift() etc.
Post Reply