为什么PDO debugDumpParams截断查询 [英] Why PDO debugDumpParams truncate query

查看:100
本文介绍了为什么PDO debugDumpParams截断查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了相同的问题这里,但它没有答案,我在这里提供了更简单的示例,然后尝试再次询问...

I found same question here but it unanswered, and i provide more simple example here, and try ask again...

代码:

<?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

为什么会发生,以及如何解决?
预先感谢!

Why it occurs, and how fix it?
Thanks in advance!

推荐答案

我认为debugDumpParams总体上是功能不完善.事实上,它仅在标准输出中就吐出了数据!

I think that debugDumpParams is a misfeature at whole. The fact it spits the data right in the standard output alone!

所以我还是不会使用它,并且出于日志记录的目的,要么为mysql启用常规日志,要么为具有日志记录功能的PDO创建包装器(此解决方案更具可移植性).

So I wouldn't use it anyway, and for the logging purpose either enable a general log for mysql, or create a wrapper around PDO with logging feature (this solution is more portable).

这篇关于为什么PDO debugDumpParams截断查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆