Reputation: 7688
Having a repetitive code like so:
$SQL = " INSERT INTO ... ";
mysql_query($SQL, $conexion);
$error = mysql_error();
if($_ADM['id_user']==1) {
if( ! empty($error)) {
$debug = array(
'message' => "SQL Error in news_edit module.",
'line' => '177',
'error' => $error,
'SQL' => $SQL
);
exit(print_r($debug));
}
}
This is a common code, that repeats its self every time $SQL
changes. What I'm trying to achieve is a way to debug if any error occurs and as I you can see, I have the line
parameter which contains the number line where last mysql_query
was executed, but I have to type that manually and every time I add code before it, the line
parameters needs to be changed with the new line value.
Is there any way of identifying where was last time mysql_query
executed? Any other way of improving the code above?
Upvotes: 1
Views: 61
Reputation: 7165
try using
'line'=> __LINE__,
its a magic constant which displays the current line of the file..
Upvotes: 3
Reputation: 1963
I think what you want is debug_backtrace
function.
Check the manual for specs:
http://php.net/manual/en/function.debug-backtrace.php
Upvotes: 0