从PDO准备好的语句中检索(或模拟)完整查询 [英] Retrieve (or simulate) full query from PDO prepared statement
问题描述
我偶然发现了两年前的这个问题.
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准备好的语句中检索(或模拟)完整查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!