Overview

Packages

  • awl
    • AuthPlugin
    • AwlDatabase
    • Browser
    • classEditor
    • DataEntry
    • DataUpdate
    • EMail
    • iCalendar
    • MenuSet
    • PgQuery
    • Session
    • Translation
    • User
    • Utilities
    • Validation
    • vCalendar
    • vComponent
    • XMLDocument
    • XMLElement
  • None
  • PHP

Classes

  • AwlDatabase
  • AwlDBDialect
  • AwlQuery
  • AwlUpgrader

Functions

  • _awl_connect_configured_database
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo

Class AwlQuery

The AwlQuery Class.

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

Example usage

$sql = "SELECT * FROM mytable WHERE mytype = ?";
$qry = new AwlQuery( $sql, $myunsanitisedtype );
if ( $qry->Exec("typeselect", __line__, __file__ )
     && $qry->rows > 0 )
{
  while( $row = $qry->Fetch() ) {
    do_something_with($row);
  }
}
Package: awl\AwlDatabase
Copyright: Morphoss Ltd
License: GNU GPL v3 or later
Author: Andrew McMillan <andrew@morphoss.com>
Located at AwlQuery.php
Methods summary
public The
# __construct( )

Constructor

Constructor

Returns

The
AwlQuery object
public
# SetConnection( resource $new_connection, mixed $options = null )

Use a different database connection for this query

Use a different database connection for this query

Parameters

$new_connection
resource
$new_connection The database connection to use.
$options
public
# GetConnection( )

Get the current database connection for this query

Get the current database connection for this query

public
# _log_query( string $locn, string $tag, string $string, integer $line = 0, string $file = "" )

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

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(...);

Parameters

$locn
string
$locn A string identifying the calling location.
$tag
string
$tag A tag string, e.g. identifying the type of event.
$string
string
$string The information to be logged.
$line
integer
$line The line number where the logged event occurred.
$file
string
$file The file name where the logged event occurred.
public static string
# quote( mixed $str = null )

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

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

Parameters

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

Returns

string
NULL, TRUE, FALSE, a plain number, or the original string quoted and with ' and \ characters escaped
public
# Bind( )

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.

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.
public
# Prepare( )

Tell the database to prepare the query that we will execute

Tell the database to prepare the query that we will execute

public
# Execute( )

Tell the database to execute the query

Tell the database to execute the query

public
# QueryString( )

Return the query string we are planning to execute

Return the query string we are planning to execute

public
# Parameters( )

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

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

public
# rows( )

Return the count of rows retrieved/affected

Return the count of rows retrieved/affected

public
# rownum( )

Return the current rownum in the retrieved set

Return the current rownum in the retrieved set

public integer
# TransactionState( )

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.

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.

Returns

integer
0 = not started, 1 = in progress, -1 = error pending rollback/commit
public
# Begin( )

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

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

public
# Commit( )

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

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

public
# Rollback( )

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

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

public
# SetSql( string $sql )

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

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

Parameters

$sql
string
The query string in PDO syntax with replacable '?' characters or bindable parameters.
public boolean
# QDo( )

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...

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...

Returns

boolean
Success (true) or Failure (false)
public boolean
# Exec( string $location = null, integer $line = null, string $file = null )

Execute the query, logging any debugging.

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.

$qry->Exec(__CLASS__, __LINE__, __FILE__);

Parameters

$location
string
$location The name of the location for enabling debugging or just to help our children find the source of a problem.
$line
integer
$line The line number where Exec was called
$file
string
$file The file where Exec was called

Returns

boolean
Success (true) or Failure (false)
public mixed
# Fetch( boolean $as_array = false )

Fetch the next row from the query results

Fetch the next row from the query results

Parameters

$as_array
boolean
$as_array True if thing to be returned is array

Returns

mixed
query row
public
# getErrorInfo( )

Get any error information from the last query

Get any error information from the last query

public float
# SetSlowQueryThreshold( float $new_threshold )

Set the slow query threshold for this query (and subsequent queries using this object). The overall default is $c->slow_query_threshold, or 5 seconds if that is not set.

Set the slow query threshold for this query (and subsequent queries using this object). The overall default is $c->slow_query_threshold, or 5 seconds if that is not set.

Parameters

$new_threshold
float
$new_threshold The new threshold for slow queries to be logged

Returns

float
The old threshold.
Properties summary
protected resource $connection
#

Our database connection, normally copied from a global one

Our database connection, normally copied from a global one

protected string $querystring
#

The original query string

The original query string

protected string $bound_querystring
#

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

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

protected array $bound_parameters
#

The current array of bound parameters

The current array of bound parameters

protected string $sth
#

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

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

protected resource $result
#

Result of the last execution

Result of the last execution

protected integer $rownum null
#

number of current row - use accessor to get/set

number of current row - use accessor to get/set

protected integer $rows
#

number of rows from pg_numrows - use accessor to get value

number of rows from pg_numrows - use accessor to get value

protected string $error_info
#

The Database error information, if the query fails.

The Database error information, if the query fails.

protected string $execution_time
#

Stores the query execution time - used to deal with long queries. should be read-only

Stores the query execution time - used to deal with long queries. should be read-only

public string $location
#

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

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

public float $query_time_warning 5
#

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

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 5 seconds, which can be overridden by setting a value for $c->default_query_warning_threshold

AWL API documentation generated by ApiGen 2.8.0