/** * Show an error message to the user and log the error if needed. * Current 404 errors are not logged. This function ends execution. * @param $errNum int the HTTP error code to return, typically 404 for missing page or 500. * @param $info string (optional) with the message to log, not displayed in production. */ public static function showError($errNum, $info = null) { Language::load('Errors'); ob_get_clean(); $defError = Language::tr('500_default_error'); switch ($errNum) { case 404: Error::error404(); die; break; case 500: default: break; } if ($info != null) { Logger::error('[' . $errNum . '] ' . strip_tags($info)); } $data['title'] = Language::tr('500_title'); $data['error'] = $info != null ? Config::SITE_ENVIRONMENT() == 'development' ? $defError . '<br/>' . $info : $defError : $defError; View::addHeader("HTTP/1.0 500 Internal Server Error"); View::renderTemplate('header', $data); View::render('error/500', $data); View::renderTemplate('footer', $data); die; }
/** * Create the table in the database. * @param $onlyNew (optional) - only create the table if its not already there. * @return true if the table was created or already exists, false otherwise. */ public function create($onlyNew = false) { $compiled = $this->compile(); if ($compiled === null) { return false; } $sql = "CREATE TABLE "; if ($onlyNew) { $sql .= "IF NOT EXISTS "; } $sql .= $compiled . ';'; if ($this->db === null) { return false; } try { $this->db->exec($sql); $ret = $this->db->errorCode(); if ($ret == '00000') { return true; } else { $info = $this->db->errorInfo(); \HMC\Logger::error('SQLSTATE[' . $ret . '] ' . $info[0] . $info[1] . ' ' . $info[2]); return false; } } catch (\Exception $e) { \HMC\Logger::error($sql); \HMC\Logger::error(\HMC\Logger::buildExceptionMessage($e)); return false; } }