Wednesday, August 31, 2011

How to find Query Source in MySQL general Log

Most of the time similar queries are used in different modules of the code-base. At times it gets difficult to find out the page where buggy or slow query is being executed. MySQL provides the option of logging slow and general queries in files. In order to record the source of the executed query it is best that you append a string in query which is then being executed via mysql_query() function of PHP.

$sql = "-- Executed via yourfilename.php:
SELECT * from table;"
$resulr = mysql_query($sql,$connection);

By doing this you can now find out where your query got executed. Easy and handy, No? :-)