Retrieve (or simulate) full query from PDO prepared statement(从 PDO 准备好的语句中检索(或模拟)完整查询)
问题描述
我在两年前偶然发现了这个问题.
I stumbled upon this question from two years ago.
有没有办法在准备好的语句上调用 PDOStatement::execute() 时执行原始 SQL 字符串?出于调试目的,这将非常有用.
Is there a way to get the raw SQL string executed when calling PDOStatement::execute() on a prepared statement? For debugging purposes this would be extremely useful.
获胜答案指出
[...] 你也可以得到你想要的设置 PDO 属性PDO::ATTR_EMULATE_PREPARES.在这模式,PDO 将参数插入到SQL查询并发送整个执行时查询.
[...] You can also get what you want if you set the PDO attribute PDO::ATTR_EMULATE_PREPARES. In this mode, PDO interpolate parameters into the SQL query and sends the whole query when you execute().
但它没有提到如何获取结果查询字符串.我知道在性能方面这是一个坏主意,但这在调试模式下不会打扰我.有人知道怎么做吗?
But it doesn't mention how to get the resulting query string. I know it's a bad idea performance wise but that doesn't bother me in debug mode. Does anybody know how to do this?
PS 如果有什么办法可以让我重新打开/引起人们对原来两年前的话题的关注而不是打开一个新话题,请告诉我.
推荐答案
我相信这是在这个问题中引用的原始问题中提到的.然而实际上应该有一种方法来检索这些数据.
I believe this is mentioned in the original question that was reference in this one. However there is actually supposed to be a method for retrieving this data.
PDOStatement::debugDumpParams
然而,它目前并没有按照文档工作.这里有一个错误报告和补丁提交给它http://bugs.php.net/bug.php?id=52384 以防有人对它感兴趣.在修复之前,您似乎只能使用查询日志记录或使用 PDO::ATTR_STATEMENT_CLASS 属性设置自定义语句类.
However it isn't currently working as documented. There is a bug report and patch submitted for it here http://bugs.php.net/bug.php?id=52384 in case anyone is interested in voting on it. Until it's fixed it seems like you are left to use query logging or setting a custom statement class using the PDO::ATTR_STATEMENT_CLASS attribute.
这篇关于从 PDO 准备好的语句中检索(或模拟)完整查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 PDO 准备好的语句中检索(或模拟)完整查询
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
