Database class for all database queries

This database class is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This database class is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

author Andrew Judd
copyright Andrew Judd, 2012
license GPLv3
package Database
version 3.0.0 For full documentation and updates please visit: http://development.andrewjudd.ca

 Methods

The constructor for the database object this will be used in order to set any desired configuration settings and then it will attempt to make a connection to the database.

__construct(DatabaseConfiguration $config) 

Parameters

$config

\DatabaseConfiguration

An object which contains all of the configuration settings for the instance.

This function is used in order to commit a transaction.

commitTransaction() 

Used in order to return the instance of the PDO object.

getConnection() : \PDO

Returns

Retrieves the query execution log.

getLog() : \array<DatabaseLogEntry>

Returns

\array<DatabaseLogEntry>

Retrieves the number of queries which have been executed.

getQueryCount() : int

Returns

int

Retrieves the total time it took to process all requests for the database object.

getTotalTime() : int

Returns

int

This function is the starting function for the query that is being run.

query() : \DatabaseQuery

It will take in the query with the following values for the parameters and then insert the values in their corresponding spots after making sure that the data passed in matches the correct data type (based on regular expression).

var All of the corresponding values for the query (the number of these is based on however many parameters there are in the database query)

Returns

\DatabaseQueryAn object which contains all information about the query which was just executed.

This function is used in order to roll back a transaction

rollbackTransaction() 

This function is used in order to start a transaction.

startTransaction() 

This function is used internally in order to add more time to the internal clock to determine how long each query lasts.

__addTime(int $duration) 

Parameters

$duration

int

The number of milliseconds that the processing took

This function is used internally in order to add a new message to the log.

__addToLog(string $message, int $duration, string $query) 

Parameters

$message

string

The message to add to the log

$duration

int

The time in milliseconds that were spent on this action.

$query

string

The query which was executed

This function is used in order to connect to the database

__connect() 

This function is used internally in order to handle any errors which come up through use of the database object.

__error(Exception $exception) 

Parameters

$exception

\Exception

The exception which was thrown

This function is used internally in order to determine the actual type code of the data.

__getDataTypeCode(string $typecode) : string

Parameters

$typecode

string

The type code that we current have

Returns

stringThe actual data type which is being expected.

This function is used in order to parse the query and put it into a common type.

__parse(array $query) : \DatabaseQuery

Parameters

$query

array

The query and any parameters

Returns

\DatabaseQueryA hydrated object with all of the database query information prepared.

This function is used internally in order to parse the query if provided in the new format.

__parseBasic(array $query) : \DatabaseQuery

Parameters

$query

array

The query and any parameters

Returns

\DatabaseQueryThe hydrated database query object

This function is used internally in order to parse the query if provided in the classic format.

__parseClassic(array $query) : \DatabaseQuery

Parameters

$query

array

The query and any parameters

Returns

\DatabaseQueryThe hydrated database query object

This function is used in order to build the replacement string for the parameter.

__replaceString(string $typecode, mixed $value) : array

Parameters

$typecode

string

The type code

$value

mixed

The value we are binding

Returns

array{ 'query' => The change to the query which will be added in , 'parameter' => The parameters to be bound }

This function is used internally in order to run the query once it was converted to the common form.

__run(DatabaseQuery $query) 

Parameters

$query

\DatabaseQuery

The query information in a common structure.

This function is used in order to verify the data type coming in.

__verifyType(string $typecode, mixed $value, bool $isList) 

Parameters

$typecode

string

The type code

$value

mixed

The value we are comparing

$isList

bool

Whether or not we are verifying a list's elements (defaults to FALSE)

Exceptions

\InvalidArgumentException If the data type doesn't match the requirements

 Properties

 

An instance of the DatabaseConfiguration object which will be used internally to retrieve any settings as specified by the user.

$config : \DatabaseConfiguration

 

The connection to the database

$connection : \PDO

 

Where all of the query logging information will be stored.

$log : \array<DatabaseLogEntry>

 

How many queries have been run?

$queryCount : int

 

Logs the total amount of time spent by the database object.

$totalTime : int