Example #1
0
 /**
  * 
  * @param type $sql
  * @param bool $useExceptions Optional - If set to TRUE will throw an _Exception() | If set to FALSE will return FALSE on error
  * @return boolean|string
  * @throws _Exception with code _DB_QUERY_ERROR only if _DB_USE_EXCEPTIONS == TRUE or $useExceptions (override) == TRUE
  */
 public function query($sql, $useExceptions = _DbConfig::USE_EXCEPTIONS)
 {
     if (!$this->isConnected) {
         $rc = $this->createConnection();
         if ($rc === FALSE) {
             return FALSE;
         }
     }
     if (_DbConfig::LOG_SQL) {
         _Log::debug($sql);
     }
     try {
         $this->lastResult = $this->mysqli->query($sql);
     } catch (Exception $e) {
         if ($useExceptions) {
             throw new _Exception('Error executing query | ' . $e->getMessage(), _DbErrors::QUERY_ERROR, $e);
         } else {
             return FALSE;
         }
     }
     if ($this->lastResult === FALSE) {
         // Error occurred
         _Log::crit('Error occurred while executing query');
         if ($useExceptions) {
             throw new _Exception('Error executing query', _DbErrors::QUERY_ERROR);
         } else {
             return FALSE;
         }
     }
     $this->lastCount = $this->mysqli->affected_rows;
     return $this->lastResult;
 }
Example #2
0
 /**
  * 
  * @param string $filename The file to open
  * @param const $permissions The permissions
  * @return boolean TRUE if file was opened / FALSE if file was unable to be opened
  */
 private function openFile($filename, $permissions = _FileConstants::READ_WRITE_END_OF_FILE_CREATE)
 {
     $this->closeFile();
     if ($filename === NULL) {
         _Log::debug('Invalid filename specified');
         return false;
     }
     if ($filename == _FileConstants::TMP) {
         $this->filename = tempnam($this->getTemporaryFileDirectory(), '_');
         $this->fh = tmpfile();
     } else {
         $this->filename = $filename;
         $this->fh = fopen($filename, $permissions);
     }
     if ($this->fh !== FALSE) {
         $this->filePermissions = $permissions;
         return TRUE;
     }
     return FALSE;
 }