예제 #1
0
 /**
  * Sends the HTTP status code
  * 
  * 
  * @param int $code The code to send
  * @param type $customDescription (optional) The description of the response code
  */
 public static function _sendHTTPStatusCode($code, $customDescription = FALSE)
 {
     if (!preg_match('/\\d\\d\\d/', $code)) {
         _Log::warn("Invalid status code: {$code} - Using default '200 OK' response");
         $code = 200;
     }
     if ($customDescription === FALSE) {
         $description = isset(_WebResponseIncludes::$STATUS_CODES[$code]) ? _WebResponseIncludes::$STATUS_CODES[$code] : '';
     } else {
         $description = $customDescription;
     }
     header("HTTP/1.0 {$code} {$description}");
 }
예제 #2
0
 /**
  * Creates the connection to the MySQL DB through the MySQLi interface
  * 
  * @param boolean $useExceptions (optional) | Override on whether to use exceptions.  If not passed will use _DB_USE_EXCEPTIONS
  * @return boolean | TRUE on success (connection was made) / FALSE on failure
  * @throws _Exception | If _DB_USE_EXCEPTIONS is TRUE, will throw an exception instead of returning
  * false on connection error
  */
 private function createConnection($useExceptions = _DbConfig::USE_EXCEPTIONS)
 {
     $this->mysqli = new \mysqli($this->host, $this->username, $this->password, $this->dbName, $this->port, $this->socket);
     if (mysqli_connect_errno()) {
         $msg = 'Unable to connect to MySQL | ' . mysqli_connect_error();
         if ($useExceptions) {
             _Log::fatal($msg);
             $_e = new _Exception($msg, 0, $e);
             throw $_e;
         } else {
             _Log::warn($msg);
         }
     }
     if (isset($this->mysqli) && $this->mysqli !== NULL) {
         // set charset
         $rc = $this->mysqli->set_charset(_DbConfig::CHARSET);
         if ($rc !== TRUE) {
             _Log::warn('Error setting character set');
         }
         $this->isConnected = true;
         return TRUE;
     }
     return FALSE;
 }