We use a DB abstraction layer to handle all SQL queries for error handling and such.
The problem is, if I'm in script3.php and I have require'd (or include'd) a separate file with offensive SQL in there, and it breaks, I can't extract where the SQL was called from. I have to grep the source files to see where it broke.
What I'd like to do, and I think is the easiest method, is to do something like this:
<?php
class DB {
...
query( ... ) {
if( $error ) {
$linenumber = // some way of determining line number of file that called query
$phpfile = // some way of determining said filename
// call raiserror
raiserror( $SQL, $msg, $phpfile, $linenumber );
} // end if
} // end if
?>
I know a way would be to hard-code things:
<?
$DB->query( $SQL, $GLOBALS[ 'SCRIPT_NAME' ], 904 ); // 904 is line number
?>
But that would require me to change every existing query.. but if that's the only way to do it I will. On a side tangent, is there a pre-defined variable for the current line number? I can't seem to find it. That would allow me to do a global find and replace and just append the name / line number vars to the end of the query.