For example:
SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction ROLLING BACK
I get this message from a PDOEception thrown inside my code. I would like to intercept the error code (1213) and give it specific treatment.
Why?
For example deadlock means I just have to resubmit the query after a microsecond or so. Other errors, means I need to alert developers etc).
Right now I have to code (inside a class inheriting PDO):
try{
$this->lastStatement = $sql;
$this->lastStatement->execute($params);
}catch (PDOException $e){
return $this->error($e);
}
I can not use the getCode of $E as it seems to not have the total range of errors MySQL has. For example, the following error: SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction
will return HY000 Which is a very general code. Used on many different error types.
Should I parse the error message?
$e->getCode()? Does it return anything meaningfull?