Code Duplication    Length = 28-28 lines in 2 locations

src/voku/db/Prepare.php 1 location

@@ 416-443 (lines=28) @@
413
   *
414
   * @return bool
415
   */
416
  private function queryErrorHandling($errorMsg, $sql)
417
  {
418
    if ($errorMsg === 'DB server has gone away' || $errorMsg === 'MySQL server has gone away') {
419
      static $reconnectCounter;
420
421
      // exit if we have more then 3 "DB server has gone away"-errors
422
      if ($reconnectCounter > 3) {
423
        $this->_debug->mailToAdmin('SQL-Fatal-Error', $errorMsg . ":\n<br />" . $sql, 5);
424
        throw new \Exception($errorMsg);
425
      }
426
427
      $this->_debug->mailToAdmin('SQL-Error', $errorMsg . ":\n<br />" . $sql);
428
429
      // reconnect
430
      $reconnectCounter++;
431
      $this->_db->reconnect(true);
432
433
      // re-run the current query
434
      return $this->execute();
435
    }
436
437
    $this->_debug->mailToAdmin('SQL-Warning', $errorMsg . ":\n<br />" . $sql);
438
439
    // this query returned an error, we must display it (only for dev) !!!
440
    $this->_debug->displayError($errorMsg . ' | ' . $sql);
441
442
    return false;
443
  }
444
445
}
446

src/voku/db/DB.php 1 location

@@ 783-810 (lines=28) @@
780
   *
781
   * @return bool
782
   */
783
  protected function queryErrorHandling($errorMsg, $sql, $sqlParams = false)
784
  {
785
    if ($errorMsg === 'DB server has gone away' || $errorMsg === 'MySQL server has gone away') {
786
      static $RECONNECT_COUNTER;
787
788
      // exit if we have more then 3 "DB server has gone away"-errors
789
      if ($RECONNECT_COUNTER > 3) {
790
        $this->_debug->mailToAdmin('SQL-Fatal-Error', $errorMsg . ":\n<br />" . $sql, 5);
791
        throw new \Exception($errorMsg);
792
      }
793
794
      $this->_debug->mailToAdmin('SQL-Error', $errorMsg . ":\n<br />" . $sql);
795
796
      // reconnect
797
      $RECONNECT_COUNTER++;
798
      $this->reconnect(true);
799
800
      // re-run the current query
801
      return $this->query($sql, $sqlParams);
802
    }
803
804
    $this->_debug->mailToAdmin('SQL-Warning', $errorMsg . ":\n<br />" . $sql);
805
806
    // this query returned an error, we must display it (only for dev) !!!
807
    $this->_debug->displayError($errorMsg . ' | ' . $sql);
808
809
    return false;
810
  }
811
812
  /**
813
   * Reconnect to the MySQL-Server.