简体   繁体   English

在Kohana 3中登录MySQL查询

[英]Log MySQL Query In Kohana 3

I am using Kohana 3. I want to log the MySQL queries being executed by an application. 我正在使用Kohana3。我想记录由应用程序执行的MySQL查询。 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. 确定在一个进程中正在执行的类型为INSERT,UPDATE和DELETE的查询的原因,并将它们存储在具有日期时间的另一个MySQL表中,以供进一步参考。

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. 抱歉,由于存在Kohana标签,我从错误的角度解决了这个问题。 You want the MYSQL server to log the commands directly, so you get ALL of the commands, not just the last one. 您希望MYSQL服务器直接记录命令,因此您将获得所有命令,而不仅仅是最后一个。

See the mysql server docs on logging: http://dev.mysql.com/doc/refman/5.0/en/server-logs.html 请参阅有关日志记录的mysql服务器文档: http : //dev.mysql.com/doc/refman/5.0/en/server-logs.html

I did this using after() method of the controller. 我使用控制器的after()方法进行了此操作。 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. 执行完每个控制器动作后,将执行after()方法,在其中编写了逻辑以捕获上一次执行的查询,并将其存储在数据库中以供进一步参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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