本文介紹了PHP、MySQL PDOException 的死鎖異常代碼?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
使用 PHP PDO MySQL,異常模式.
Using PHP PDO MySQL, exception mode.
是否存在 [MySQL] 死鎖的 PDOException 代碼?
Does a PDOException code for [MySQL] deadlocks exist?
如果沒有,還有其他選擇嗎?
Is there an alternative if it doesn't?
推薦答案
PDO::errorInfo, PDOException::errorInfo
MySQL 服務器錯誤代碼和消息;錯誤:1213 SQLSTATE: 40001 (ER_LOCK_DEADLOCK)
/*[...]*/
//error mode is exception
$pdoDBHandle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try
{
/*[...]*/
}
catch(PDOException $exc)
{
if(
$exc->errorInfo[0]==40001 /*(ISO/ANSI) Serialization failure, e.g. timeout or deadlock*/;
&& $pdoDBHandle->getAttribute(PDO::ATTR_DRIVER_NAME)=="mysql"
&& $exc->errorInfo[1]==1213 /*(MySQL SQLSTATE) ER_LOCK_DEADLOCK*/
)
{
/*[...]*/
}
else
throw $exc;
}
這篇關于PHP、MySQL PDOException 的死鎖異常代碼?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!