Code Duplication    Length = 28-28 lines in 2 locations

src/voku/db/Prepare.php 1 location

@@ 400-427 (lines=28) @@
397
   *
398
   * @return bool
399
   */
400
  private function queryErrorHandling($errorMsg, $sql)
401
  {
402
    if ($errorMsg === 'DB server has gone away' || $errorMsg === 'MySQL server has gone away') {
403
      static $reconnectCounter;
404
405
      // exit if we have more then 3 "DB server has gone away"-errors
406
      if ($reconnectCounter > 3) {
407
        $this->_debug->mailToAdmin('SQL-Fatal-Error', $errorMsg . ":\n<br />" . $sql, 5);
408
        throw new \Exception($errorMsg);
409
      } else {
410
        $this->_debug->mailToAdmin('SQL-Error', $errorMsg . ":\n<br />" . $sql);
411
412
        // reconnect
413
        $reconnectCounter++;
414
        $this->_db->reconnect(true);
415
416
        // re-run the current query
417
        return $this->execute();
418
      }
419
    } else {
420
      $this->_debug->mailToAdmin('SQL-Warning', $errorMsg . ":\n<br />" . $sql);
421
422
      // this query returned an error, we must display it (only for dev) !!!
423
      $this->_debug->displayError($errorMsg . ' | ' . $sql);
424
    }
425
426
    return false;
427
  }
428
429
}
430

src/voku/db/DB.php 1 location

@@ 757-784 (lines=28) @@
754
   *
755
   * @return bool
756
   */
757
  protected function queryErrorHandling($errorMsg, $sql, $sqlParams = false)
758
  {
759
    if ($errorMsg === 'DB server has gone away' || $errorMsg === 'MySQL server has gone away') {
760
      static $reconnectCounter;
761
762
      // exit if we have more then 3 "DB server has gone away"-errors
763
      if ($reconnectCounter > 3) {
764
        $this->_debug->mailToAdmin('SQL-Fatal-Error', $errorMsg . ":\n<br />" . $sql, 5);
765
        throw new \Exception($errorMsg);
766
      } else {
767
        $this->_debug->mailToAdmin('SQL-Error', $errorMsg . ":\n<br />" . $sql);
768
769
        // reconnect
770
        $reconnectCounter++;
771
        $this->reconnect(true);
772
773
        // re-run the current query
774
        return $this->query($sql, $sqlParams);
775
      }
776
    } else {
777
      $this->_debug->mailToAdmin('SQL-Warning', $errorMsg . ":\n<br />" . $sql);
778
779
      // this query returned an error, we must display it (only for dev) !!!
780
      $this->_debug->displayError($errorMsg . ' | ' . $sql);
781
    }
782
783
    return false;
784
  }
785
786
  /**
787
   * Reconnect to the MySQL-Server.