简体   繁体   中英

Log MySQL Query In Kohana 3

I am using Kohana 3. I want to log the MySQL queries being executed by an application. The reason to determine the query of type INSERT,UPDATE and DELETE which are being executed in a process and store them in another MySQL table with date-time for further reference.

Can anybody tell how can I achieve this?

An alternative is to enable profiling for the database module, which will log the queries made to a file. This will log ALL queries, not just the last one ;)

It shouldn't be too hard to parse the file, or to extend the profiling/logging/caching classes to save it to a database.

Sorry, because of the Kohana tag I approached the problem from the wrong angle. You want the MYSQL server to log the commands directly, so you get ALL of the commands, not just the last one.

See the mysql server docs on logging: http://dev.mysql.com/doc/refman/5.0/en/server-logs.html

I did this using after() method of the controller. After execution of each controller action this after() method is executed, where I wrote logic to capture last query executed and stored in my db for further reference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM