死锁发现;尝试重启事务。
你的PHP应用在使用PDO连接MySQL时遇到了死锁问题:
'pdo_code' => '40001',
'db_code' => 1213,
'db_error' => 'Deadlock found when trying to get lock; try restarting transaction'
$maxRetries = 3;
$retryCount = 0;
while ($retryCount < $maxRetries) {
try {
$pdo->beginTransaction();
$pdo->commit();
break;
} catch (PDOException $e) {
if ($e->getCode() == '40001' || $e->getCode() == '1213') {
$retryCount++;
if ($pdo->inTransaction()) {
$pdo->rollBack();
}
usleep(rand(100000, 500000));
} else {
throw $e;
}
}
}
if ($retryCount == $maxRetries) {
throw new Exception("事务在重试{$maxRetries}次后仍然失败");
}