Overview

Packages

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

Classes

  • AwlDatabase
  • AwlDBDialect
  • AwlQuery
  • AwlUpgrader

Functions

  • _awl_connect_configured_database
  • Overview
  • Package
  • Class

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, $options = null )

Use a different database connection for this query

Use a different database connection for this query

Parameters

$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
A string identifying the calling location.
$tag
A tag string, e.g. identifying the type of event.
$string
The information to be logged.
$line
The line number where the logged event occurred.
$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
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( mixed $args,… )

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.

Parameters

$args,…
See details above.
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
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

The name of the location for enabling debugging or just to help our children find the source of a problem.

$line
The line number where Exec was called
$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
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

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

number of current row - use accessor to get/set

number of current row - use accessor to get/set

# null
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

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

# 0.3
API documentation generated by ApiGen