You are here

function DB_pgsql::simpleQuery in Flickr API 5

Sends a query to the database server

Parameters

string the SQL query string:

Return value

mixed + a PHP result resrouce for successful SELECT queries + the DB_OK constant for other successful queries + a DB_Error object on failure

File

phpFlickr/PEAR/DB/pgsql.php, line 320

Class

DB_pgsql
The methods PEAR DB uses to interact with PHP's pgsql extension for interacting with PostgreSQL databases

Code

function simpleQuery($query) {
  $ismanip = DB::isManip($query);
  $this->last_query = $query;
  $query = $this
    ->modifyQuery($query);
  if (!$this->autocommit && $ismanip) {
    if ($this->transaction_opcount == 0) {
      $result = @pg_exec($this->connection, 'begin;');
      if (!$result) {
        return $this
          ->pgsqlRaiseError();
      }
    }
    $this->transaction_opcount++;
  }
  $result = @pg_exec($this->connection, $query);
  if (!$result) {
    return $this
      ->pgsqlRaiseError();
  }

  // Determine which queries that should return data, and which
  // should return an error code only.
  if ($ismanip) {
    $this->affected = @pg_affected_rows($result);
    return DB_OK;
  }
  elseif (preg_match('/^\\s*\\(*\\s*(SELECT|EXPLAIN|SHOW)\\s/si', $query)) {

    /* PostgreSQL commands:
          ABORT, ALTER, BEGIN, CLOSE, CLUSTER, COMMIT, COPY,
          CREATE, DECLARE, DELETE, DROP TABLE, EXPLAIN, FETCH,
          GRANT, INSERT, LISTEN, LOAD, LOCK, MOVE, NOTIFY, RESET,
          REVOKE, ROLLBACK, SELECT, SELECT INTO, SET, SHOW,
          UNLISTEN, UPDATE, VACUUM
       */
    $this->row[(int) $result] = 0;

    // reset the row counter.
    $numrows = $this
      ->numRows($result);
    if (is_object($numrows)) {
      return $numrows;
    }
    $this->_num_rows[(int) $result] = $numrows;
    $this->affected = 0;
    return $result;
  }
  else {
    $this->affected = 0;
    return DB_OK;
  }
}