准备好的语句中检索

准备好的语句中检索

本文介绍了从 PDO 准备好的语句中检索(或模拟)完整查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在两年前偶然发现了这个问题.

I stumbled upon this question from two years ago.

有没有办法在准备好的语句上调用 PDOStatement::execute() 时执行原始 SQL 字符串?出于调试目的,这将非常有用.

获胜答案指出

[...] 你也可以得到你想要的设置 PDO 属性PDO::ATTR_EMULATE_PREPARES.在这模式,PDO 将参数插入到SQL查询并发送整个执行时查询.

但它没有提到如何获取结果查询字符串.我知道在性能方面这是一个坏主意,但这在调试模式下不会打扰我.有人知道怎么做吗?

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. Howeverthere 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 准备好的语句中检索(或模拟)完整查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 01:47