Class AbstractDB

Description

AbstractDB Main Class

The main AbstractDB class used to interact with various DBMS packages via the use of driver classes.

  • access: public

Located in /abstractdb.class.php (line 18)


	
			
Variable Summary
 array $Support
 array $_arguments
 object $_driver
 string $_error
Method Summary
 AbstractDB AbstractDB (array $arguments)
 void ClearError ()
 bool Close ()
 bool FetchNextResultAssoc (resource &$rs, array &$assoc)
 bool FetchNextResultObject (resource &$rs, object &$object)
 bool FetchNextResultRow (resource &$rs, array &$row)
 bool FetchResultAssoc (resource &$rs, array &$assoc)
 bool FetchResultAssocAll (resource &$rs, array &$all)
 bool FetchResultColumn (resource &$rs, array &$column)
 bool FetchResultField (resource &$rs, mixed &$field)
 bool FetchResultObject (resource &$rs, object &$object)
 bool FetchResultObjectAll (resource &$rs, array &$all)
 bool FetchResultRow (resource &$rs, array &$row)
 bool FetchResultRowAll (resource &$rs, array &$all)
 bool FetchSeekResultAssoc (resource &$rs, int $row_num, array &$assoc)
 bool FetchSeekResultObject (resource &$rs, int $row_num, object &$object)
 bool FetchSeekResultRow (resource &$rs, int $row_num, array &$row)
 bool FreeResult (resource &$rs)
 string GetDatabase ()
 void GetDriverError ()
 int GetFieldCount (resource &$rs)
 bool GetFieldNames (resource &$rs, array &$fields)
 mixed GetInsertID ()
 string GetLastError ()
 int GetRowCount (resource &$rs)
 bool IsResource (resource $resource, string $callee)
 bool LoadDriver ()
 bool ParseArguments (array $arguments)
 bool ParseConnectionArguments (string $connectionString)
 resource Query (string $sql)
 bool QueryAssoc (string $sql, array &$assoc)
 bool QueryAssocAll (string $sql, array &$all)
 bool QueryColumn (string $sql, array &$column)
 bool QueryField (string $sql, mixed &$field)
 bool QueryObject (string $sql, object &$object)
 bool QueryObjectAll (string $sql, array &$all)
 bool QueryRow (string $sql, array &$row)
 bool QueryRowAll (string $sql, array &$all)
 bool Replace (string $table, array $fields)
 string SetDatabase (string $dbName)
 void SetError (string $scope, string $message)
 bool SetErrorHandler (string $functionName)
Variables
array $Support (line 52)

List of supported features of the currently loaded driver.

  • access: public
array $_arguments (line 26)

List of connection arguments.

  • access: private
object $_driver (line 32)

Reference to the AbstractDB driver.

  • access: private
string $_error (line 38)

The last error message.

  • access: private
string $_error_handler (line 44)

Name of an error handling function passed in via SetErrorHandler.

  • access: private
Methods
Constructor AbstractDB (line 93)

AbstractDB Constructor

Initilises an instance of the AbstractDB class.

AbstractDB AbstractDB (array $arguments)
  • array $arguments:

    Database connection and driver specific arguments.

    Arguments must be supplied as an associative array containing one of the following:

    ConnectionString:

    A string composed of the connection arguments and optional or driver specific options in the form of Type://Username:Password@Hostname:Port/Database?Options/option1=value1&Options/option2=value2

    e.g. $args = array("ConnectionString" => "mysql://root:pass@localhost/MyDatabase?Options/Persistent=1");

    or

    Type: The type of database to connect to. AbstractDB is currently only distributed with a MySQL driver.

    Username: The database username.

    Password: The database password.

    Hostname: The database hostname or IP Address.

    Database: The name of the database.

    Options: An associative array of optional or driver specific options. See individual driver documentation for a potential list of driver specific options. The value for Port should be specified in this list, otherwise the default port for the database type will be used.

    e.g. $args = array("Type" => "mysql", "Username" => "root", "Password" => "pass", "Hostname" => "localhost", "Database" => "MyDatabase", "Options" => array("Persistent" => 1));

    Type and Database are required parameters and must be specified.

ClearError (line 826)

Clears the latest error message.

  • access: private
void ClearError ()
Close (line 106)

Closes the Database Connection

  • return: Returns true if the database connection was successfully closed, otherwise false.
  • access: public
bool Close ()
EnsureRequiredArguments (line 838)

Ensures Required Connection Arguments Exist

  • return: Returns true if all required connection arguments have been set, otherwise false.
  • internal: If there are missing arguments an error is set stating which arguments are missing.
  • access: private
bool EnsureRequiredArguments ()
FetchNextResultAssoc (line 121)

Fetches the Next Row as an Associative Array

  • return: Returns true if the operation was successful, otherwise false.
  • example: FetchNextResult example.
  • access: public
bool FetchNextResultAssoc (resource &$rs, array &$assoc)
  • resource $rs: A reference to a resource handle returned by executing a query.
  • array $assoc: A reference to an array that will contain the result row.
FetchNextResultObject (line 143)

Fetches the Next Row as an Object

  • return: Returns true if the operation was successful, otherwise false.
  • example: FetchNextResult example.
  • access: public
bool FetchNextResultObject (resource &$rs, object &$object)
  • resource $rs: A reference to a resource handle returned by executing a query.
  • object $object: A reference to an object that will contain the result row.
FetchNextResultRow (line 165)

Fetches the Next Row

  • return: Returns true if the operation was successful, otherwise false.
  • example: FetchNextResult example.
  • access: public
bool FetchNextResultRow (resource &$rs, array &$row)
  • resource $rs: A reference to a resource handle returned by executing a query.
  • array $row: A reference to an array that will contain the result row.
FetchResultAssoc (line 186)

Fetches a Row as an Associative Array

Fetches the first row as an associative array and then frees the result set.

  • return: Returns true if the operation was successful, otherwise false.
  • example: FetchResult example.
  • access: public
bool FetchResultAssoc (resource &$rs, array &$assoc)
  • resource $rs: A reference to a resource handle returned by executing a query.
  • array $assoc: A reference to an array that will contain the result row.
FetchResultAssocAll (line 209)

Fetches All Rows as Associative Arrays

Fetches all rows as associative arrays and then frees the result set.

  • return: Returns true if the operation was successful, otherwise false.
  • example: FetchResultAll example.
  • access: public
bool FetchResultAssocAll (resource &$rs, array &$all)
  • resource $rs: A reference to a resource handle returned by executing a query.
  • array $all: A reference to an array that will contain the result rows.
FetchResultColumn (line 234)

Fetches a Result Column

Fetches all rows of the first column and then frees the result set.

bool FetchResultColumn (resource &$rs, array &$column)
  • resource $rs: A reference to a resource handle returned by executing a query.
  • array $column: A reference to an array that will contain the result column rows.
FetchResultField (line 259)

Fetches a Result Field

Fetches the value in the first column of the first row and then frees the result set.

bool FetchResultField (resource &$rs, mixed &$field)
  • resource $rs: A reference to a resource handle returned by executing a query.
  • mixed $field: A reference to a variable that will contain the field value.
FetchResultObject (line 282)

Fetches a Row as an Object

Fetches the first row as an object and then frees the result set.

  • return: Returns true if the operation was successful, otherwise false.
  • example: FetchResult example.
  • access: public
bool FetchResultObject (resource &$rs, object &$object)
  • resource $rs: A reference to a resource handle returned by executing a query.
  • object $object: A reference to an object that will contain the result row.
FetchResultObjectAll (line 305)

Fetches All Rows as Objects

Fetches all rows as objects and then frees the result set.

  • return: Returns true if the operation was successful, otherwise false.
  • example: FetchResultAll example.
  • access: public
bool FetchResultObjectAll (resource &$rs, array &$all)
  • resource $rs: A reference to a resource handle returned by executing a query.
  • array $all: A reference to an array that will contain the result rows.
FetchResultRow (line 330)

Fetches a Row

Fetches the first row and then frees the result set.

  • return: Returns true if the operation was successful, otherwise false.
  • example: FetchResult example.
  • access: public
bool FetchResultRow (resource &$rs, array &$row)
  • resource $rs: A reference to a resource handle returned by executing a query.
  • array $row: A reference to an array that will contain the result row.
FetchResultRowAll (line 353)

Fetches All Rows

Fetches all rows and then frees the result set.

  • return: Returns true if the operation was successful, otherwise false.
  • example: FetchResultAll example.
  • access: public
bool FetchResultRowAll (resource &$rs, array &$all)
  • resource $rs: A reference to a resource handle returned by executing a query.
  • array $all: A reference to an array that will contain the result rows.
FetchSeekResultAssoc (line 379)

Fetches a Row as an Associative Array

Fetches the row at the specified position in the result set as an associative array.

  • return: Returns true if the operation was successful, otherwise false.
  • example: FetchSeekResult example.
  • access: public
bool FetchSeekResultAssoc (resource &$rs, int $row_num, array &$assoc)
  • resource $rs: A reference to a resource handle returned by executing a query.
  • int $row_num: The position in the result set of the row to return.
  • array $assoc: A reference to an array that will contain the result row.
FetchSeekResultObject (line 407)

Fetches a Row as an Object

Fetches the row at the specified position in the result set as an object.

  • return: Returns true if the operation was successful, otherwise false.
  • example: FetchSeekResult example.
  • access: public
bool FetchSeekResultObject (resource &$rs, int $row_num, object &$object)
  • resource $rs: A reference to a resource handle returned by executing a query.
  • int $row_num: The position in the result set of the row to return.
  • object $object: A reference to an object that will contain the result row.
FetchSeekResultRow (line 435)

Fetches a Row

Fetches the row at the specified position in the result set.

  • return: Returns true if the operation was successful, otherwise false.
  • example: FetchSeekResult example.
  • access: public
bool FetchSeekResultRow (resource &$rs, int $row_num, array &$row)
  • resource $rs: A reference to a resource handle returned by executing a query.
  • int $row_num: The position in the result set of the row to return.
  • array $row: A reference to an array that will contain the result row.
FreeResult (line 460)

Frees a Result Resource

Frees the resources associated with the given result handle returned by executing a query.

  • return: Returns true if the resource handle was successfully freed.
  • access: public
bool FreeResult (resource &$rs)
  • resource $rs: A reference to a resource handle returned by executing a query.
GetAffectedRows (line 477)

Gets the Number of Affected Rows

  • return: Returns the number of rows affected by the last executed query, or false if the driver does not support this feature.
  • example: GetAffectedRows example.
  • access: public
int GetAffectedRows ()
GetDatabase (line 493)

Gets the Name of the Current Database

  • return: The name of the current database.
  • access: public
string GetDatabase ()
GetDriverError (line 882)

Gets the Latest Error from the Driver

  • internal: Sets an error based on the driver error.
  • access: private
void GetDriverError ()
GetFieldCount (line 507)

Gets the Number of Fields

Gets the number of fields returned by the given result handle.

  • return: Returns the number of fields returned by the last executed query.
  • example: GetFieldCount example.
  • access: public
int GetFieldCount (resource &$rs)
  • resource $rs: A reference to a resource handle returned by executing a query.
GetFieldNames (line 526)

Gets the Field Names of a Query

  • return: Returns true if the operation was successful, otherwise false.
  • example: GetFieldNames example.
  • access: public
bool GetFieldNames (resource &$rs, array &$fields)
  • resource $rs: A reference to a resource handle returned by executing a query.
  • array $fields: A reference to an array that will contain the field names.
GetInsertID (line 544)

Gets the Last Insert ID

  • return: Returns either the ID of the last inserted AUTO_INCREMENT record, or -1 if the last query was not an insert, or false if the driver does not support this feature.
  • example: GetInsertID example.
  • access: public
mixed GetInsertID ()
GetLastError (line 560)

Gets the Last Error.

  • return: The last error message.
  • access: public
string GetLastError ()
GetRowCount (line 574)

Gets the Number of Rows

Gets the number of rows returned by the last query of the given result handle.

  • return: Returns the number of rows returned by the last executed query.
  • example: GetRowCount example.
  • access: public
int GetRowCount (resource &$rs)
  • resource $rs: A reference to a resource handle returned by executing a query.
IsResource (line 909)

Checks That a Parameter is a Resource

Checks that a given parameter is a resource type variable.

  • return: Returns true if the given parameter is a resource, otherwise false.
  • access: private
bool IsResource (resource $resource, string $callee)
  • resource $resource: A variable to ensure is a resource.
  • string $callee: The name of the method calling this function. Used in the setting of the error message.
LoadDriver (line 925)

Loads an AbstractDB Database Driver

Loads the AbstractDB driver for the type of database being connected to.

  • return: Returns true if the driver was successfully loaded, otherwise false.
  • internal: If the driver could not be loaded an error is set explaining the reason for the failure.
  • access: private
bool LoadDriver ()
ParseArguments (line 964)

Parses Connection and Driver Specific Arguments

  • return: Returns true if arguments were successfully parsed, otherwise false.
  • access: private
bool ParseArguments (array $arguments)
  • array $arguments: A list of connection and driver specific arguments.
ParseConnectionArguments (line 1002)

Parses ConnectionString Argument

Parses the ConnectionString argument passed in via the constructor.

  • return: Returns true if the connection string was successfully parsed, otherwise false.
  • todo: There may be a use for the fragment part of the parsed connection string.
  • access: private
bool ParseConnectionArguments (string $connectionString)
  • string $connectionString: A connection string in the format Type://User:Pass@Host:Port/Database?Options/option1=value1&Options/option2=value2
Query (line 596)

Executes an SQL Statement

Executes the given SQL statement.

  • return: The result handle for use in fetch result functions.
  • example: Query example.
  • internal: If the query did not execute successfully an error is set explaining as best as possible the reason for the failure.
  • access: public
resource Query (string $sql)
  • string $sql: The SQL statement to be executed.
QueryAssoc (line 614)

Executes an SQL Statement

Executes the given SQL statement and retrieves the first result row as an associative array, then frees the result set.

  • return: Returns true if the operation was successful, otherwise false.
  • example: Query example.
bool QueryAssoc (string $sql, array &$assoc)
  • string $sql: The SQL statement to be executed.
  • array $assoc: A reference to an array that will contain the result row.
QueryAssocAll (line 633)

Executes an SQL Statement

Executes the given SQL statement and retrieves all result rows as associative arrays, then frees the result set.

  • return: Returns true if the operation was successful, otherwise false.
  • example: Query All example.
bool QueryAssocAll (string $sql, array &$all)
  • string $sql: The SQL statement to be executed.
  • array $all: A reference to an array that will contain the result rows.
QueryColumn (line 653)

Executes an SQL Statement

Executes the given SQL statement and retrieves all rows of the first result column, then frees the result set.

  • return: Returns true if the operation was successful, otherwise false.
  • example: QueryColumn example.
  • access: public
bool QueryColumn (string $sql, array &$column)
  • string $sql: The SQL statement to be executed.
  • array $column: A reference to an array that will contain the result column rows.
QueryField (line 673)

Executes an SQL Statement

Executes the given SQL statement and retrieves the value in the first column of the first row, then frees the result set.

  • return: Returns true if the operation was successful, otherwise false.
  • example: QueryField example.
  • access: public
bool QueryField (string $sql, mixed &$field)
  • string $sql: The SQL statement to be executed.
  • mixed $field: A reference to a variable that will contain the field value.
QueryObject (line 692)

Executes an SQL Statement

Executes the given SQL statement and retrieves the first result row as an object, then frees the result set.

  • return: Returns true if the operation was successful, otherwise false.
  • example: Query example.
bool QueryObject (string $sql, object &$object)
  • string $sql: The SQL statement to be executed.
  • object $object: A reference to an object that will contain the result row.
QueryObjectAll (line 711)

Executes an SQL Statement

Executes the given SQL statement and retrieves all result rows as objects, then frees the result set.

  • return: Returns true if the operation was successful, otherwise false.
  • example: Query All example.
bool QueryObjectAll (string $sql, array &$all)
  • string $sql: The SQL statement to be executed.
  • array $all: A reference to an array that will contain the result rows.
QueryRow (line 730)

Executes an SQL Statement

Executes the given SQL statement and retrieves the first result row, then frees the result set.

  • return: Returns true if the operation was successful, otherwise false.
  • example: Query example.
bool QueryRow (string $sql, array &$row)
  • string $sql: The SQL statement to be executed.
  • array $row: A reference to an array that will contain the result row.
QueryRowAll (line 748)

Executes an SQL Statement

Executes the given SQL statement and retrieves all result rows, then frees the result set.

  • return: Returns true if the operation was successful, otherwise false.
  • example: Query All example.
bool QueryRowAll (string $sql, array &$all)
  • string $sql: The SQL statement to be executed.
  • array $all: A reference to an array that will contain the result rows.
Replace (line 776)

Executes an SQL Replace Query

  • return: Returns true if the operation was successful, otherwise false.
  • example: Replace example.
  • access: public
bool Replace (string $table, array $fields)
  • string $table: The name of the table to execute the replace query on.
  • array $fields:

    An associative array of field definitions. Keys should be the field names and values should be an associative array containing the following keys:

    Key => bool indicating that this field is the primary key or part of a unique index. Key values must not be NULL.

    Type => either "text", "numeric", "bool".

    Value => the value of the field.

    Null => bool indicating if the value of the field should be set to NULL.

    e.g. $fields = array("Field1" => array("Key" => true, "Type" => "numeric", "Value" => 123, "Null" => false));

SetDatabase (line 790)

Sets the Current Database

  • return: The old database name that was set before calling this method, or false if an error occurred.
  • access: public
string SetDatabase (string $dbName)
  • string $dbName: The name of the new database to perform queries on.
SetError (line 1065)

Sets the Latest Error Message.

Sets the latest error message and calls an error handling function if one was set.

  • access: private
void SetError (string $scope, string $message)
  • string $scope: The scope of the error, generally the function in which it occured.
  • string $message: The actual error message.
SetErrorHandler (line 807)

Sets an Error Handling Function.

  • return: Returns true if the error handling function was successfully set, otherwise false.
  • example: SetErrorHandler example.
  • access: public
bool SetErrorHandler (string $functionName)
  • string $functionName: The name of a function to be called when an error occurs.

Documentation generated on Wed, 16 Mar 2005 23:16:48 +1100 by phpDocumentor 1.3.0RC3