php – 从PDO准备语句中检索(或模拟)完整查询

我从两年前就绊倒了
this question.

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.

获胜的答案说明

[…] 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().

但是没有提到如何获取生成的查询字符串.我知道这是一个不错的主意性能明智,但这并不打扰我在调试模式.有人知道该怎么做吗

PS如果有一些方法我可以重新开始/提请注意原来的两年老话题,而不是开一个新话题,请让我知道.

我相信这是在原来的问题中提及的.然而

实际上应该是一种检索此数据的方法.

PDOStatement对象:: debugDumpParams

然而,它目前还没有被记录在案.有一个bug报告和补丁提交给它在这里http://bugs.php.net/bug.php?id=52384,以防任何人有兴趣投票.直到它被修复,好像您可以使用查询日志记录或使用PDO :: ATTR_STATEMENT_CLASS属性设置自定义语句类.

dawei

【声明】:唐山站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。