Mysql
 sql >> Database >  >> RDS >> Mysql

Codice di eccezione deadlock per PHP, MySQL PDOException?

PDO::errorInfo, PDOException::errorInfo

Codici di errore e messaggi di MySQL Server; Errore: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;
}