Class PgQuery

Description

The PgQuery Class.

This class builds and executes PostgreSQL Queries and traverses the set of results returned from the query.

Example usage

  1.  $sql "SELECT * FROM mytable WHERE mytype = ?";
  2.  $qry new PgQuery$sql$myunsanitisedtype );
  3.  if $qry->Exec("typeselect"__line____file__ )
  4.       && $qry->rows()
  5.  {
  6.    while$row $qry->Fetch() ) {
  7.      do_something_with($row);
  8.    }
  9.  }

Located in /PgQuery.php (line 277)


	
			
Variable Summary
Method Summary
 The __construct (string 0, mixed 1)
 string BuildOptionList ([string $current = ''], [string $location = 'options'], [array $parameters = false])
 resource Exec ([string $location = ''], [int $line = 0], [string $file = ''])
 mixed Fetch ([boolean $as_array = false])
 mixed FetchBackwards ([boolean $as_array = false])
 array Plain (string $field)
 string quote ([mixed $str = null])
 void rows ()
 void SetConnection (resource $new_connection)
 void UnFetch ()
 void _log_error (string $locn, string $tag, string $string, [int $line = 0], [string $file = ""])
Variables
string $errorstring (line 341)

The PostgreSQL error message, if the query fails.

Should be read-only, although any successful Exec should clear it

  • access: public
string $execution_time (line 348)

Stores the query execution time - used to deal with long queries.

should be read-only

  • access: public
double $query_time_warning = 0.3 (line 357)

How long the query should take before a warning is issued.

This is writable, but a method to set it might be a better interface. The default is 0.3 seconds.

  • access: public
int $rows (line 334)

number of rows from pg_numrows - for fetching result

should be read-only

  • access: public
Methods
Constructor __construct (line 367)

Constructor

  • return: PgQuery object
The __construct (string 0, mixed 1)
  • string 0: The query string with replacable '?' characters.
  • mixed 1: The values to replace into the SQL string.
BuildOptionList (line 615)

Build an option list from the query.

  • return: Select box HTML
string BuildOptionList ([string $current = ''], [string $location = 'options'], [array $parameters = false])
  • string $current: Default selection of drop down box (optional)
  • string $location: for debugging purposes
  • array $parameters: an array further parameters, including 'maxwidth' => 20 to set a maximum width
Exec (line 478)

Execute the query, logging any debugging.

Example So that you can nicely enable/disable the queries for a particular class, you could use some of PHPs magic constants in your call.

  1.  $qry->Exec(__CLASS____LINE____FILE__);

  • return: The actual result of the query (FWIW)
resource Exec ([string $location = ''], [int $line = 0], [string $file = ''])
  • string $location: The name of the location for enabling debugging or just to help our children find the source of a problem.
  • int $line: The line number where Exec was called
  • string $file: The file where Exec was called
Fetch (line 525)

Fetch the next row from the query results

  • return: query row
mixed Fetch ([boolean $as_array = false])
  • boolean $as_array: True if thing to be returned is array
FetchBackwards (line 581)

Fetch backwards from the result resource

  • return: query row
mixed FetchBackwards ([boolean $as_array = false])
  • boolean $as_array: True if thing to be returned is array (default: False
Plain (line 455)

Convert a string which has already been quoted and escaped for PostgreSQL into a magic array so that it will be inserted unmodified into the SQL string. Use with care!

  • return: An array with the value associated with a key of 'plain'
array Plain (string $field)
  • string $field: The value which has alread been quoted and escaped.
quote (line 443)

Quote the given string so it can be safely used within string delimiters in a query.

  • return: NULL, TRUE, FALSE, a plain number, or the original string quoted and with ' and \ characters escaped
  • see: qpg() which is where this is really done.
string quote ([mixed $str = null])
  • mixed $str: Data to be converted to a string suitable for including as a value in SQL.
rows (line 429)

Provide a rows() method for forward compatibility with AwlQuery.

void rows ()
SetConnection (line 394)

Use a different database connection for this query

void SetConnection (resource $new_connection)
  • resource $new_connection: The database connection to use.
UnFetch (line 570)

Set row counter back one

In the case that you may like to fetch the same row twice, for example if your SQL returns some columns that are the same for each row, and you want to display them cleanly before displaying the other data repeatedly for each row.

Example

  1.  $master_row $qry->Fetch();
  2.  $qry->UnFetch();
  3.  do_something_first($master_row);
  4.  while$row $qry->Fetch() ) {
  5.    do_something_repeatedly($row);
  6.  }

void UnFetch ()
_log_error (line 412)

Log error, optionally with file and line location of the caller.

This function should not really be used outside of PgQuery. For a more useful generic logging interface consider calling dbg_error_log(...);

void _log_error (string $locn, string $tag, string $string, [int $line = 0], [string $file = ""])
  • string $locn: A string identifying the calling location.
  • string $tag: A tag string, e.g. identifying the type of event.
  • string $string: The information to be logged.
  • int $line: The line number where the logged event occurred.
  • string $file: The file name where the logged event occurred.

Documentation generated on Wed, 04 Jul 2012 07:06:15 +0000 by phpDocumentor 1.4.3