我發現同樣的問題here但無人接聽,我在這裏提供更簡單的例子,然後嘗試再次問...爲什麼PDO debugDumpParams截斷查詢
代碼:
<?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
爲什麼會出現,以及如何修復它?
在此先感謝!
我對源代碼進行了一點挖掘,雖然我無法找到**確切的**答案,但我能夠確認它確實將所有查詢剪切爲500個字符。從源頭上看,沒有辦法繞過它,因爲該方法不接受任何參數,只是使用內部方法寫入輸出流,而內部方法不能用外部參數「控制」。你唯一的選擇就是使用MySQL並將'GENERAL_LOG'打開並捕獲以這種方式發送到MySQL的實際數據(這是我通常做的,我從來沒有使用過PDO進行調試)。 – 2015-04-02 11:12:37
已經創建的錯誤,https://bugs.php.net/bug.php?id=69356希望大家解決它。 – 2015-04-02 11:50:03
但是,如果你仔細想想,爲什麼你需要查詢?你已經擁有了它,因爲你是通過它來「準備」的人。您的原始問題也包含變量中的查詢。 'debugDumpParams'唯一有趣的輸出是參數,而不是實際的查詢。 – 2015-04-02 12:12:10