2015-04-02 71 views
4

我發現同樣的問題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 

爲什麼會出現,以及如何修復它?
在此先感謝!

+3

我對源代碼進行了一點挖掘,雖然我無法找到**確切的**答案,但我能夠確認它確實將所有查詢剪切爲500個字符。從源頭上看,沒有辦法繞過它,因爲該方法不接受任何參數,只是使用內部方法寫入輸出流,而內部方法不能用外部參數「控制」。你唯一的選擇就是使用MySQL並將'GENERAL_LOG'打開並捕獲以這種方式發送到MySQL的實際數據(這是我通常做的,我從來沒有使用過PDO進行調試)。 – 2015-04-02 11:12:37

+1

已經創建的錯誤,https://bugs.php.net/bug.php?id=69356希望大家解決它。 – 2015-04-02 11:50:03

+0

但是,如果你仔細想想,爲什麼你需要查詢?你已經擁有了它,因爲你是通過它來「準備」的人。您的原始問題也包含變量中的查詢。 'debugDumpParams'唯一有趣的輸出是參數,而不是實際的查詢。 – 2015-04-02 12:12:10

回答

0

Why it occurs? - 我沒有找到任何有關它的信息。
How fix it? - 我沒有發現任何線索如何使用本機PDO修復它。

這個問題的主要目的 - 是怎麼看某些PHP腳本的所有查詢
我發現只有一個辦法做到這一點 - 是to enable general log for mysql

3

我認爲debugDumpParams是一個錯特徵在整個。僅僅在標準輸出中吐出數據的事實!

因此,我不會使用它,併爲日誌記錄目的要麼啓用一個通用的日誌爲MySQL,或創建一個與日誌記錄功能的PDO包裝(此解決方案更便攜)。