Docs For Class AwlQuery

## AwlQuery

Description

The AwlQuery Class.

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

Example usage

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

Located in /AwlQuery.php (line 117)

Variable Summary
array $bound_parameters
string $bound_querystring
resource $connection
string $error_info
string $execution_time
string $location
string $querystring
double $query_time_warning
resource $result
int $rownum
int $rows
string $sth
Method Summary
static string quote ([mixed $str = null])
The __construct (string 0, mixed 1)
void Begin ()
void Bind (mixed $args)
void Commit ()
boolean Exec ([string $location = null], [int $line = null], [string $file = null])
void Execute ()
mixed Fetch ([boolean $as_array = false])
void GetConnection ()
void Parameters ()
void Prepare ()
boolean QDo (string 0, mixed 1)
void QueryString ()
void Rollback ()
void rownum ()
void rows ()
void SetConnection (resource $new_connection, [ $options = null])
void SetSql (string $sql)
int TransactionState ()
void _log_query (string $locn, string $tag, string $string, [int $line = 0], [string $file = ""])
Variables
array $bound_parameters (line 144)

The current array of bound parameters

- access: protected

string $bound_querystring (line 138)

The actual query string, after we've replaced parameters in it

- access: protected

resource $connection (line 126)

Our database connection, normally copied from a global one

- access: protected

string $error_info (line 174)

The Database error information, if the query fails.

- access: protected

string $execution_time (line 181)

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

should be read-only

- access: protected

string $location (line 193)

Where we called this query from so we can find it in our code! Debugging may also be selectively enabled for a $location.

- access: public

string $querystring (line 132)

The original query string

- access: protected

double $query_time_warning = 0.3 (line 202)

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

resource $result (line 156)

Result of the last execution

- access: protected

int $rownum = null (line 162)

number of current row - use accessor to get/set

- access: protected

int $rows (line 168)

number of rows from pg_numrows - use accessor to get value

- access: protected

string $sth (line 150)

The PDO statement handle, or null if we don't have one yet.

- access: protected

Methods
static quote (line 311)

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

- return: NULL, TRUE, FALSE, a plain number, or the original string quoted and with ' and \ characters escaped
- access: public

static string quote ([mixed $str = null])

- mixed $str: Data to be converted to a string suitable for including as a value in SQL.

Constructor __construct (line 212)

Constructor

- return: AwlQuery object

The __construct (string 0, mixed 1)

- string 0: The query string in PDO syntax with replacable '?' characters or bindable parameters.
- mixed 1: The values to replace into the SQL string.

Begin (line 467)

Wrap the parent DB class Begin() so we can $qry->Begin() sometime before we $qry->Exec()

- access: public

void Begin ()
Bind (line 330)

Bind some parameters. This can be called in three ways:

1) As Bind(':key','value), when using named parameters 2) As Bind('value'), when using ? placeholders 3) As Bind(array()), to overwrite the existing bound parameters. The array may be ':name' => 'value' pairs or ordinal values, depending on whether the SQL is using ':name' or '?' style placeholders.

void Bind (mixed $args)

- mixed $args: See details above.

Commit (line 480)

Wrap the parent DB class Commit() so we can $qry->Commit() sometime after we $qry->Exec()

- access: public

void Commit ()
Exec (line 556)

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: Success (true) or Failure (false)

boolean Exec ([string $location = null], [int $line = null], [string $file = null])

- 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

Execute (line 374)

Tell the database to execute the query

void Execute ()
Fetch (line 622)

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

GetConnection (line 272)

Get the current database connection for this query

void GetConnection ()
Parameters (line 428)

Return the parameters we are planning to substitute into the query string

void Parameters ()
Prepare (line 351)

Tell the database to prepare the query that we will execute

void Prepare ()
QDo (line 523)

Simple QDo() class which will re-use this query for whatever was passed in, and execute it returning the result of the Exec() call. We can't call it Do() since that's a reserved word...

- return: Success (true) or Failure (false)
- access: public

boolean QDo (string 0, mixed 1)

- string 0: The query string in PDO syntax with replacable '?' characters or bindable parameters.
- mixed 1: The values to replace into the SQL string.

QueryString (line 420)

Return the query string we are planning to execute

void QueryString ()
Rollback (line 491)

Wrap the parent DB class Rollback() so we can $qry->Rollback() sometime after we $qry->Exec()

- access: public

void Rollback ()
rownum (line 444)

Return the current rownum in the retrieved set

void rownum ()
rows (line 436)

Return the count of rows retrieved/affected

void rows ()
SetConnection (line 241)

Use a different database connection for this query

void SetConnection (resource $new_connection, [ $options = null])

- resource $new_connection: The database connection to use.
- $options

SetSql (line 503)

Simple SetSql() class which will reset the object with the querystring from the first argument.

- access: public

void SetSql (string $sql)

- string $sql: The query string in PDO syntax with replacable '?' characters or bindable parameters.

TransactionState (line 454)

Returns the current state of a transaction, indicating if we have begun a transaction, whether the transaction has failed, or if we are not in a transaction.

- return: 0 = not started, 1 = in progress, -1 = error pending rollback/commit

int TransactionState ()
_log_query (line 289)

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

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

void _log_query (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 Fri, 13 Jan 2012 23:40:13 +1300 by phpDocumentor 1.4.3