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

Retrieve (or simulate) full query from PDO prepared statement(从 PDO 准备好的语句中检索(或模拟)完整查询)
本文介绍了从 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 准备好的语句中检索(或模拟)完整查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)