本文介紹了PDO 錯誤信息?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
這是我的代碼片段:
$qry = '
INSERT INTO non-existant-table (id, score)
SELECT id, 40
FROM another-non-existant-table
WHERE description LIKE "%:search_string%"
AND available = "yes"
ON DUPLICATE KEY UPDATE score = score + 40
';
$sth = $this->pdo->prepare($qry);
$sth->execute($data);
print_r($this->pdo->errorInfo());
這應該給我一個錯誤,因為這些表甚至不存在.然而,我得到的只是這個:
This should give me an error because the tables don't even exist. All I get however is this:
數組 ( [0] => 00000 )
Array ( [0] => 00000 )
如何更好地描述錯誤以便調試問題?
How can I get a better description of the error so I can debug the issue?
推薦答案
試試這個:
print_r($sth->errorInfo());
在準備之前添加:
$this->pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
這將更改 PDO 錯誤報告類型并使其在出現 PDO 錯誤時發出警告.它應該可以幫助你追蹤它,雖然你的 errorInfo 應該已經下注了.
This will change the PDO error reporting type and cause it to emit a warning whenever there is a PDO error. It should help you track it down, although your errorInfo should have bet set.
這篇關于PDO 錯誤信息?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!