从 cakephp finder 方法检索 sql 查询
我正在创建一种行为,将控制器中特定模型执行的 SQL 查询记录到表中。寻找一种方法来返回为特定查找器方法执行的sql查询(例如 $this->MyModel->find('all') )我在面包店发现我可以使用 $this->MyModel- >find('sql'),但对我不起作用。有人知道我怎样才能实现这一目标?
提前致谢
I'm creating a behavior that log to a table the sql query executed by a particular Model in a controller. Looking for a method to return me the sql query executed for a particular finder method (like $this->MyModel->find('all') ) I found on the bakery that I can use $this->MyModel->find('sql'), but doesn't work for me. Someone knows how can I achieve this?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将此函数放在 app_model.php 中:
并从任何模型 ($this->getLastQueries()) 或控制器 ($this->Model->getLastQueries()) 调用它来获取它们。
You can put this function in your app_model.php:
And call it from any model ($this->getLastQueries()) or controller ($this->Model->getLastQueries()) to get them.
Cake本身不支持$this->Model->find('sql')。您必须按照 Bakery 文章中的其余说明安装新的 DBO 驱动程序,并在 AppModel 中添加对 find('sql') 方法的支持。一旦你这样做了,它应该能够为你提供你正在寻找的东西。
http ://bakery.cakephp.org/articles/grant_cox/2008/06/23/get-the-find-query-sql-rather-than-query-result
$this->Model->find('sql') is not supported natively by Cake. You have to follow the rest of the instructions in the Bakery article for installing a new DBO driver, and adding support for the find('sql') method in your AppModel. Once you do this, it should be able to get you what you're looking for.
http://bakery.cakephp.org/articles/grant_cox/2008/06/23/get-the-find-query-sql-rather-than-query-result