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
      } else {
426
        $this->_debug->mailToAdmin('SQL-Error', $errorMsg . ":\n<br />" . $sql);
427
428
        // reconnect
429
        $reconnectCounter++;
430
        $this->_db->reconnect(true);
431
432
        // re-run the current query
433
        return $this->execute();
434
      }
435
    } else {
436
      $this->_debug->mailToAdmin('SQL-Warning', $errorMsg . ":\n<br />" . $sql);
437
438
      // this query returned an error, we must display it (only for dev) !!!
439
      $this->_debug->displayError($errorMsg . ' | ' . $sql);
440
    }
441
442
    return false;
443
  }
444
445
}
446

src/voku/db/DB.php 1 location

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