/** * Prints SQL error message * * @param string Additional error message * @return @e mixed */ public function throwFatalError($the_error = '') { //----------------------------------------- // INIT //----------------------------------------- $this->error = $this->_getErrorString(); $this->error_no = $this->_getErrorNumber(); $errTemplate = 'ipsDriverError'; $nonIPSErrors = array('1012-1021', '1023-1027', '1030-1031', '1034-1043', '1129-1131', '1150-1153', 1194, 1195, '1203-1207'); /* MySQL: Is this non IPS error? */ if ($this->usingClass == 'db_driver_mysql') { if (stristr($this->error, 'has gone away') or stristr($this->error, 'connect to local mysql server through socket')) { $errTemplate = 'ipsServerError'; } else { if ($this->error_no) { foreach ($nonIPSErrors as $id) { if (strstr($id, '-')) { list($a, $b) = explode('-', $id); if ($a and $b) { if ($this->error_no >= $a and $this->error_no <= $b) { $errTemplate = 'ipsServerError'; } } } else { if ($this->error_no == intval($id)) { $errTemplate = 'ipsServerError'; } } } } } } /* Fetch debug information */ $_debug = debug_backtrace(); $_dString = ''; if (is_array($_debug) and count($_debug)) { foreach ($_debug as $idx => $data) { /* Remove non-essential items */ if ($data['class'] == 'dbMain' or $data['class'] == 'ips_DBRegistry' or $data['class'] == 'ipsRegistry' or $data['class'] == 'ipsController' or $data['class'] == 'ipsCommand' or $data['class'] == 'db_driver_mysql') { continue; } $_dbString[$idx] = array('file' => $data['file'], 'line' => $data['line'], 'function' => $data['function'], 'class' => $data['class']); } } $_error_string = "\n ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"; $_error_string .= "\n Date: " . date('r'); $_error_string .= "\n Error: " . $this->error_no . ' - ' . $this->error; $_error_string .= "\n IP Address: " . $_SERVER['REMOTE_ADDR'] . ' - ' . $_SERVER['REQUEST_URI']; $_error_string .= "\n ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"; $_error_string .= "\n " . $the_error; $_error_string .= "\n .--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------."; if (count($_dbString)) { $_error_string .= "\n | File | Function | Line No. |"; $_error_string .= "\n |----------------------------------------------------------------------------+-------------------------------------------------------------------------------+-------------------|"; foreach ($_dbString as $i => $data) { if (defined('DOC_IPS_ROOT_PATH')) { $data['file'] = str_replace(DOC_IPS_ROOT_PATH, '', $data['file']); } /* Reset */ $data['func'] = "[" . $data['class'] . '].' . $data['function']; /* Pad right */ $data['file'] = str_pad($data['file'], 75); $data['func'] = str_pad($data['func'], 78); $data['line'] = str_pad($data['line'], 18); $_error_string .= "\n | " . $data['file'] . "| " . $data['func'] . '| ' . $data['line'] . '|'; $_error_string .= "\n '----------------------------------------------------------------------------+-------------------------------------------------------------------------------+-------------------'"; } } if ($this->return_die == true) { $this->error = $this->error == "" ? $the_error : $this->error; $this->failed = true; return; } else { if ($this->obj['use_error_log'] and $this->obj['error_log']) { if ($FH = @fopen($this->obj['error_log'], 'a')) { @fwrite($FH, $_error_string); @fclose($FH); } /* Write to latest log also */ if (is_dir(IPS_CACHE_PATH . 'cache')) { @file_put_contents(IPS_CACHE_PATH . 'cache/sql_error_latest.cgi', trim($_error_string)); } else { if (is_dir(DOC_IPS_ROOT_PATH . 'cache')) { @file_put_contents(DOC_IPS_ROOT_PATH . 'cache/sql_error_latest.cgi', trim($_error_string)); } } if (isset($_SERVER['SERVER_PROTOCOL']) and strstr($_SERVER['SERVER_PROTOCOL'], '/1.0')) { @header("HTTP/1.0 503 Service Unavailable"); } else { @header("HTTP/1.1 503 Service Unavailable"); } if ($this->use_template) { require_once IPS_ROOT_PATH . 'sources/classes/output/systemTemplates.php'; $systemTemplates = new systemTemplates(); $template = $systemTemplates->getClass($errTemplate); $errorBlock = ''; if ($errTemplate == 'ipsServerError' and $the_error) { $_errorMessage = htmlspecialchars($the_error); $errorBlock = <<<EOF \t\t\t\t\t<div class='database-error'> \t\t\t\t \t<form name='mysql'> \t\t\t\t \t\t<textarea rows="15" cols="60">{$the_error}</textarea> \t\t\t\t \t</form> \t\t\t \t</div> EOF; } print $template->getTemplate($_SERVER['HTTP_HOST'], nl2br(trim($the_error)), $errorBlock); } else { print "<html><head><title>Ошибка базы данных</title>\n\t\t\t\t\t\t<style>P,BODY{ font-family:arial,sans-serif; font-size:11px; }</style></head><body>\n\t\t\t \t\t <blockquote><h1>IPS Driver Error</h1><b>There appears to be an error with the database.</b><br>\n\t\t\t \t\t You can try to refresh the page by clicking <a href=\"javascript:window.location=window.location;\">here</a>\n\t\t\t\t\t </body></html>"; } } else { $the_error .= "\n\nSQL error: " . $this->error . "\n"; $the_error .= "SQL error code: " . $this->error_no . "\n"; $the_error .= "Date: " . date("l dS F Y h:i:s A"); $the_error .= "\n\n" . $_error_string; if (isset($_SERVER['SERVER_PROTOCOL']) and strstr($_SERVER['SERVER_PROTOCOL'], '/1.0')) { @header("HTTP/1.0 503 Service Unavailable"); } else { @header("HTTP/1.1 503 Service Unavailable"); } if ($this->use_template) { require_once IPS_ROOT_PATH . 'sources/classes/output/systemTemplates.php'; $systemTemplates = new systemTemplates(); $template = $systemTemplates->getClass($errTemplate); $errorBlock = ''; if ($the_error) { $_errorMessage = htmlspecialchars($the_error); $errorBlock = <<<EOF \t\t\t\t\t<div class='database-error'> \t\t\t\t \t<form name='mysql'> \t\t\t\t \t\t<textarea rows="15" cols="60">{$the_error}</textarea> \t\t\t\t \t</form> \t\t\t \t</div> EOF; } print $template->getTemplate($_SERVER['HTTP_HOST'], nl2br(trim($the_error)), $errorBlock, ipsRegistry::$settings); } else { print "<html><head><title>IPS Driver Error</title>\n\t\t \t\t <style>P,BODY{ font-family:arial,sans-serif; font-size:11px; }</style></head><body>\n\t\t \t\t <blockquote><h1>IPS Driver Error</h1><b>There appears to be an error with the database.</b><br>\n\t\t \t\t You can try to refresh the page by clicking <a href=\"javascript:window.location=window.location;\">here</a>.\n\t\t \t\t <br><br><b>Error Returned</b><br>\n\t\t \t\t <form name='mysql'><textarea rows=\"15\" cols=\"60\">" . htmlspecialchars($the_error) . "</textarea></form><br>We apologise for any inconvenience</blockquote></body></html>"; } } } //----------------------------------------- // Need to clear this for shutdown queries //----------------------------------------- $this->cur_query = ''; exit; }