Exemplo n.º 1
0
 public function testGetInstance()
 {
     $db_1 = DB::getInstance('localhost', 'root', '', 'mysql_test', '', '', false, false);
     self::assertEquals(true, $db_1 instanceof DB);
     $db_2 = DB::getInstance('localhost', 'root', '', 'mysql_test', '', '', true, false);
     self::assertEquals(true, $db_2 instanceof DB);
     $db_3 = DB::getInstance('localhost', 'root', '', 'mysql_test', null, '', true, false);
     self::assertEquals(true, $db_3 instanceof DB);
     $db_4 = DB::getInstance();
     self::assertEquals(true, $db_4 instanceof DB);
     $db_4_serial = serialize($db_4);
     unset($db_4);
     $db_4 = unserialize($db_4_serial);
     self::assertEquals(true, $db_4 instanceof DB);
     $true = $this->db->connect();
     self::assertEquals(true, $true);
     $true = $this->db->connect();
     self::assertEquals(true, $true);
     $true = $this->db->reconnect(false);
     self::assertEquals(true, $true);
     $true = $this->db->reconnect(true);
     self::assertEquals(true, $true);
 }
Exemplo n.º 2
0
 /**
  * Error-handling for the sql-query.
  *
  * @param string $errorMsg
  * @param string $sql
  *
  * @throws \Exception
  *
  * @return bool
  */
 private function queryErrorHandling($errorMsg, $sql)
 {
     if ($errorMsg === 'DB server has gone away' || $errorMsg === 'MySQL server has gone away') {
         static $reconnectCounter;
         // exit if we have more then 3 "DB server has gone away"-errors
         if ($reconnectCounter > 3) {
             $this->_debug->mailToAdmin('SQL-Fatal-Error', $errorMsg . ":\n<br />" . $sql, 5);
             throw new \Exception($errorMsg);
         } else {
             $this->_debug->mailToAdmin('SQL-Error', $errorMsg . ":\n<br />" . $sql);
             // reconnect
             $reconnectCounter++;
             $this->_db->reconnect(true);
             // re-run the current query
             return $this->execute();
         }
     } else {
         $this->_debug->mailToAdmin('SQL-Warning', $errorMsg . ":\n<br />" . $sql);
         // this query returned an error, we must display it (only for dev) !!!
         $this->_debug->displayError($errorMsg . ' | ' . $sql);
     }
     return false;
 }