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.
Clears the latest error message.
void
ClearError
()
Closes the Database Connection
bool
Close
()
Ensures Required Connection Arguments Exist
bool
EnsureRequiredArguments
()
Fetches the Next Row as an Associative Array
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.
Fetches the Next Row as an Object
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.
Fetches the Next Row
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.
Fetches a Row as an Associative Array
Fetches the first row as an associative array and then frees the result set.
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.
Fetches All Rows as Associative Arrays
Fetches all rows as associative arrays and then frees the result set.
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.
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.
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.
Fetches a Row as an Object
Fetches the first row as an object and then frees the result set.
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.
Fetches All Rows as Objects
Fetches all rows as objects and then frees the result set.
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.
Fetches a Row
Fetches the first row and then frees the result set.
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.
Fetches All Rows
Fetches all rows and then frees the result set.
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.
Fetches a Row as an Associative Array
Fetches the row at the specified position in the result set as an associative array.
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.
Fetches a Row as an Object
Fetches the row at the specified position in the result set as an object.
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.
Fetches a Row
Fetches the row at the specified position in the result set.
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.
Frees a Result Resource
Frees the resources associated with the given result handle returned by executing a query.
bool
FreeResult
(resource &$rs)
-
resource
$rs: A reference to a resource handle returned by executing a query.
Gets the Number of Affected Rows
int
GetAffectedRows
()
Gets the Name of the Current Database
string
GetDatabase
()
Gets the Latest Error from the Driver
void
GetDriverError
()
Gets the Number of Fields
Gets the number of fields returned by the given result handle.
int
GetFieldCount
(resource &$rs)
-
resource
$rs: A reference to a resource handle returned by executing a query.
Gets the Field Names of a Query
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.
Gets the Last Insert ID
mixed
GetInsertID
()
Gets the Last Error.
string
GetLastError
()
Gets the Number of Rows
Gets the number of rows returned by the last query of the given result handle.
int
GetRowCount
(resource &$rs)
-
resource
$rs: A reference to a resource handle returned by executing a query.
Checks That a Parameter is a Resource
Checks that a given parameter is a resource type variable.
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.
Loads an AbstractDB Database Driver
Loads the AbstractDB driver for the type of database being connected to.
bool
LoadDriver
()
Parses Connection and Driver Specific Arguments
bool
ParseArguments
(array $arguments)
-
array
$arguments: A list of connection and driver specific arguments.
Parses ConnectionString Argument
Parses the ConnectionString argument passed in via the constructor.
bool
ParseConnectionArguments
(string $connectionString)
-
string
$connectionString: A connection string in the format Type://User:Pass@Host:Port/Database?Options/option1=value1&Options/option2=value2
Executes an SQL Statement
Executes the given SQL statement.
resource
Query
(string $sql)
-
string
$sql: The SQL statement to be executed.
Executes an SQL Statement
Executes the given SQL statement and retrieves the first result row as an associative array, then frees the result set.
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.
Executes an SQL Statement
Executes the given SQL statement and retrieves all result rows as associative arrays, then frees the result set.
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.
Executes an SQL Statement
Executes the given SQL statement and retrieves all rows of the first result column, then frees the result set.
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.
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.
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.
Executes an SQL Statement
Executes the given SQL statement and retrieves the first result row as an object, then frees the result set.
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.
Executes an SQL Statement
Executes the given SQL statement and retrieves all result rows as objects, then frees the result set.
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.
Executes an SQL Statement
Executes the given SQL statement and retrieves the first result row, then frees the result set.
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.
Executes an SQL Statement
Executes the given SQL statement and retrieves all result rows, then frees the result set.
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.
Executes an SQL Replace Query
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));
Sets the Current Database
string
SetDatabase
(string $dbName)
-
string
$dbName: The name of the new database to perform queries on.
Sets the Latest Error Message.
Sets the latest error message and calls an error handling function if one was set.
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.
Sets an Error Handling Function.
bool
SetErrorHandler
(string $functionName)
-
string
$functionName: The name of a function to be called when an error occurs.