Code Duplication    Length = 26-26 lines in 2 locations

src/voku/db/DB.php 1 location

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

src/voku/db/Prepare.php 1 location

@@ 74-99 (lines=26) @@
71
   *
72
   * @throws \Exception
73
   */
74
  protected function queryErrorHandling($errorMsg, $sql)
75
  {
76
    if ($errorMsg === 'DB server has gone away' || $errorMsg === 'MySQL server has gone away') {
77
      static $reconnectCounter;
78
79
      // exit if we have more then 3 "DB server has gone away"-errors
80
      if ($reconnectCounter > 3) {
81
        $this->_debug->mailToAdmin('SQL-Fatal-Error', $errorMsg . ":\n<br />" . $sql, 5);
82
        throw new \Exception($errorMsg);
83
      } else {
84
        $this->_debug->mailToAdmin('SQL-Error', $errorMsg . ":\n<br />" . $sql);
85
86
        // reconnect
87
        $reconnectCounter++;
88
        $this->_db->reconnect(true);
89
90
        // re-run the current query
91
        $this->execute();
92
      }
93
    } else {
94
      $this->_debug->mailToAdmin('SQL-Warning', $errorMsg . ":\n<br />" . $sql);
95
96
      // this query returned an error, we must display it (only for dev) !!!
97
      $this->_debug->displayError($errorMsg . ' | ' . $sql);
98
    }
99
  }
100
101
  /**
102
   * Prepare an SQL statement for execution