Facile\DoctrineMySQLComeBack\Doctrine\DBAL\Connection::isRetryableException PHP Method

isRetryableException() public method

public isRetryableException ( Exception $e, string | null $query = null ) : boolean
$e Exception
$query string | null
return boolean
    public function isRetryableException(\Exception $e, $query = null)
    {
        if (null === $query || $this->isUpdateQuery($query)) {
            return $this->_driver->isGoneAwayInUpdateException($e);
        }
        return $this->_driver->isGoneAwayException($e);
    }

Usage Example

 /**
  * @param array|null $params
  *
  * @return bool
  *
  * @throws \Exception
  */
 public function execute($params = null)
 {
     $stmt = null;
     $attempt = 0;
     $retry = true;
     while ($retry) {
         $retry = false;
         try {
             $stmt = $this->stmt->execute($params);
         } catch (\Exception $e) {
             if ($this->conn->canTryAgain($attempt) && $this->conn->isRetryableException($e, $this->sql)) {
                 $this->conn->close();
                 $this->createStatement();
                 ++$attempt;
                 $retry = true;
             } else {
                 throw $e;
             }
         }
     }
     return $stmt;
 }