Why PDO debugDumpParams truncate query

眉间皱痕 提交于 2019-12-10 15:13:40

问题


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

Code:

<?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();

Result:

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!


回答1:


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

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).




回答2:


Why it occurs? - I didn't find any info about it.
How fix it? - I didn't find any clue how to fix it using native PDO.

The main purpose of this question - is how to see all queries for certain php script,
and I found only one way to achieve this - is to enable general log for mysql.



来源:https://stackoverflow.com/questions/29410151/why-pdo-debugdumpparams-truncate-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!