We have a large php application and trying to debugging slow sql queries, we'd like to have the ability to auto comment what file actually called the sql query, something like:
"select /* filename.php line 234*/ `ID`,`Email`, `NickName`, `AlertBusiness`,`City` from People where ?=? and limit ?,?"
where the /* filename.php line 234*/ is inserted dynamically. Probably
In php there is a debug_backtrace, http://php.net/manual/en/function.debug-print-backtrace.php
Which could do it manually:
<?php
$query = sprintf("INSERT INTO EventLog (Trace) VALUES ('%s')",
mysql_real_escape_string(join("\n", debug_backtrace())) );
mysql_query($query);
?>
But was hoping for something more central like in a db driver.
MediaWiki has a similar feature. http://www.mediawiki.org/wiki/Manual:How_to_debug
You can also enable backtrace on SQL error by setting $wgShowDBErrorBacktrace:
$wgShowDBErrorBacktrace = true;"
the PDO driver has a dump statement, but that's only the query, not who called it http://php.net/manual/en/pdostatement.debugdumpparams.php
How do you best debug sql in context of the php page running it?