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

canTryAgain() public method

public canTryAgain ( $attempt, boolean $ignoreTransactionLevel = false ) : boolean
$attempt
$ignoreTransactionLevel boolean
return boolean
    public function canTryAgain($attempt, $ignoreTransactionLevel = false)
    {
        $canByAttempt = $attempt < $this->reconnectAttempts;
        $canByTransactionNestingLevel = $ignoreTransactionLevel ? true : 0 === $this->getTransactionNestingLevel();
        return $canByAttempt && $canByTransactionNestingLevel;
    }

Usage Example

 /**
  * @param null $params
  * @return null
  * @throws
  */
 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->getDriver()->isGoneAwayException($e)) {
                 $this->conn->close();
                 $this->createStatement();
                 $attempt++;
                 $retry = true;
             } else {
                 throw $e;
             }
         }
     }
     return $stmt;
 }