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 スクリプトの すべてのクエリを表示する
方法です。これを達成する方法は 1 つしかありませんto enable general log for mysql

于 2016-08-30T06:58:44.903 に答える