【发布时间】:2015-06-07 05:49:38
【问题描述】:
我发现了同样的问题here,但没有得到解答,我在这里提供了更简单的示例,然后再次尝试提问...
代码:
<?php
$dbh = new PDO('mysql:dbname=test;host=127.0.0.1', 'root');
$sth = $dbh->prepare("
SELECT '
Dumps the informations contained by a prepared statement directly on the output. It will provide the SQL query in use, the number of parameters used (Params), the list of parameters, with their name, type (paramtype) as an integer, their key name or position, and the position in the query (if this is supported by the PDO driver, otherwise, it will be -1).
This is a debug function, which dump directly the data on the normal output.
Tip:
As with anything that outputs its result directly to the browser, the output-control functions can be used to capture the output of this function, and save it in a string (for example).
This will only dumps the parameters in the statement at the moment of the dump. Extra parameters are not stored in the statement, and not displayed.
'
");
$sth->execute();
$sth->debugDumpParams();
结果:
SQL: [835]
SELECT '
Dumps the informations contained by a prepared statement directly on the output. It will provide the SQL query in use, the number of parameters used (Params), the list of parameters, with their name, type (paramtype) as an integer, their key name or position, and the position in the query (if this is supported by the PDO driver, otherwise, it will be -1).
This is a debug function, which dump directly the data on the normal output.
Tip:
As with anythi
Params: 0
为什么会发生,如何解决?
提前致谢!
【问题讨论】:
-
我对源代码进行了一些挖掘,虽然我无法找到 exact 答案,但我能够确认它确实将所有查询减少到 500 个字符。从源代码来看,没有办法解决它,因为该方法不接受任何参数,它只是使用您无法用外部参数“控制”的内部方法写入输出流。您唯一的选择是使用 MySQL 并打开
GENERAL_LOG并以这种方式捕获发送到 MySQL 的实际数据(这是我通常做的,我从未使用 PDO 进行调试)。 -
已经创建了错误,bugs.php.net/bug.php?id=69356希望大家修复它。
-
但是如果你仔细想想,你为什么需要查询呢?您已经拥有它,因为您是将它传递给
prepare的人。您的原始问题在变量中也有查询。debugDumpParams唯一有趣的输出是参数,而不是实际的查询。 -
编写新代码时是个不错的选择。但是当我已经编写了项目时,我想查看页面上的所有查询(已经写好的)。这不是解决方案。
-
查询可能很大。你甚至可以将一些 MB 的二进制数据注入其中——相信我——这会使浏览器停止响应。日志记录设施在某处设置限制是正常的。
标签: php mysql sql pdo pdostatement