Code Duplication    Length = 28-28 lines in 2 locations

src/voku/db/DB.php 1 location

@@ 723-750 (lines=28) @@
720
   *
721
   * @return bool
722
   */
723
  protected function queryErrorHandling($errorMsg, $sql, $sqlParams = false)
724
  {
725
    if ($errorMsg === 'DB server has gone away' || $errorMsg === 'MySQL server has gone away') {
726
      static $reconnectCounter;
727
728
      // exit if we have more then 3 "DB server has gone away"-errors
729
      if ($reconnectCounter > 3) {
730
        $this->_debug->mailToAdmin('SQL-Fatal-Error', $errorMsg . ":\n<br />" . $sql, 5);
731
        throw new \Exception($errorMsg);
732
      } else {
733
        $this->_debug->mailToAdmin('SQL-Error', $errorMsg . ":\n<br />" . $sql);
734
735
        // reconnect
736
        $reconnectCounter++;
737
        $this->reconnect(true);
738
739
        // re-run the current query
740
        return $this->query($sql, $sqlParams);
741
      }
742
    } else {
743
      $this->_debug->mailToAdmin('SQL-Warning', $errorMsg . ":\n<br />" . $sql);
744
745
      // this query returned an error, we must display it (only for dev) !!!
746
      $this->_debug->displayError($errorMsg . ' | ' . $sql);
747
    }
748
749
    return false;
750
  }
751
752
  /**
753
   * Reconnect to the MySQL-Server.

src/voku/db/Prepare.php 1 location

@@ 385-412 (lines=28) @@
382
   *
383
   * @return bool
384
   */
385
  private function queryErrorHandling($errorMsg, $sql)
386
  {
387
    if ($errorMsg === 'DB server has gone away' || $errorMsg === 'MySQL server has gone away') {
388
      static $reconnectCounter;
389
390
      // exit if we have more then 3 "DB server has gone away"-errors
391
      if ($reconnectCounter > 3) {
392
        $this->_debug->mailToAdmin('SQL-Fatal-Error', $errorMsg . ":\n<br />" . $sql, 5);
393
        throw new \Exception($errorMsg);
394
      } else {
395
        $this->_debug->mailToAdmin('SQL-Error', $errorMsg . ":\n<br />" . $sql);
396
397
        // reconnect
398
        $reconnectCounter++;
399
        $this->_db->reconnect(true);
400
401
        // re-run the current query
402
        return $this->execute();
403
      }
404
    } else {
405
      $this->_debug->mailToAdmin('SQL-Warning', $errorMsg . ":\n<br />" . $sql);
406
407
      // this query returned an error, we must display it (only for dev) !!!
408
      $this->_debug->displayError($errorMsg . ' | ' . $sql);
409
    }
410
411
    return false;
412
  }
413
414
}
415