/** * 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; }
/** * Get the last sql-error. * * @return string false on error */ public function lastError() { $errors = $this->_debug->getErrors(); return count($errors) > 0 ? end($errors) : false; }