Code Duplication    Length = 28-28 lines in 2 locations

src/voku/db/DB.php 1 location

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

src/voku/db/Prepare.php 1 location

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