4

我在这里发现了同样的问题,但没有得到解答,我在这里提供了更简单的例子,然后再试一次......

代码:

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

为什么会发生,如何解决?
提前致谢!

4

2 回答 2

3

我认为这debugDumpParams完全是一个错误。事实上,它仅在标准输出中吐出数据!

所以我无论如何都不会使用它,并且出于日志记录的目的,要么为 mysql 启用通用日志,要么创建一个具有日志记录功能的 PDO 包装器(这个解决方案更便携)。

于 2016-12-01T08:11:24.043 回答
0

Why it occurs?- 我没有找到任何关于它的信息。
How fix it?- 我没有找到任何线索如何使用本机 PDO 修复它。

这个问题的主要目的 - 是如何查看某些 php 脚本的所有查询,
我发现只有一种方法可以实现 - 是to enable general log for mysql.

于 2016-08-30T06:58:44.903 回答