I have a CakePHP 1.2 application that makes a number of AJAX calls using the AjaxHelper object. The AjaxHelper makes a call to a controller function which then returns some data back to the page.
I would like to log the SQL queries that are executed by the AJAX controller functions. Normally, I would just turn the debug level to 2 in config/core.php, however, this breaks my AJAX functionality because it causes the output SQL queries to be appended to the output that is returned to the client side.
To get around this issue, I would like to be able to log any SQL queries performed to a log file. Any suggestions?
I found a nice way of adding this logging functionality at this link:
http://cakephp.1045679.n5.nabble.com/Log-SQL-queries-td1281970.html
Basically, in your
cake/libs/model/datasources/dbo/directory, you can make a subclass of the dbo that you’re using. For example, if you’re using the dbo_mysql.php database driver, then you can make a new class file calleddbo_mysql_with_log.php. The file would contain some code along the lines of the following:In a nutshell, this class modifies (i.e. overrides) the
_executefunction of the superclass to log the SQL query before doing whatever logic it normally does.You can modify your
app/config/database.phpconfiguration file to use the new driver that you just created.