\Anax\DatabaseDatabase

Database wrapper, provides a database API on top of PHP PDO for enhancing the API and dealing with error reporting and tracking.

Summary

Methods
Properties
Constants
__construct()
setOptions()
setOption()
connect()
executeFetchAll()
executeFetch()
executeFetchClass()
executeFetchInto()
fetchAll()
fetch()
fetchClass()
fetchAllClass()
fetchInto()
execute()
lastInsertId()
rowCount()
fetchObject()
fetchOne()
No public properties found
No constants found
createException()
pdoException()
statementException()
$options
N/A
expandParamArray()
$pdo
$stmt
N/A

Properties

$options

$options : array

Type

array — used when creating the PDO object

$pdo

$pdo : 

Type

$stmt

$stmt : 

Type

Methods

__construct()

__construct(array  $options = array()) 

Constructor creating a PDO object connecting to a choosen database.

Parameters

array $options

containing details for connecting to the database.

setOptions()

setOptions(array  $options = array()) : void

Set options and connection details.

Parameters

array $options

containing details for connecting to the database.

setOption()

setOption(string  $option, mixed  $value) : self

Set a single option.

Parameters

string $option

which to set.

mixed $value

to set.

Returns

self

connect()

connect() : self

Connect to the database, allow being called multiple times but ignore when connection is already made.

Throws

\Anax\Database\Exception

Returns

self

executeFetchAll()

executeFetchAll(string  $query, array  $params = array()) : mixed

Execute a select-query with arguments and return the resultset.

Parameters

string $query

the SQL statement

array $params

the params array

Returns

mixed —

with resultset

executeFetch()

executeFetch(string  $query, array  $params = array()) : mixed

Execute a select-query with arguments and return the first row in the resultset.

Parameters

string $query

the SQL statement

array $params

the params array

Returns

mixed —

with resultset

executeFetchClass()

executeFetchClass(string  $query, array  $params, string  $class) : object

Execute a select-query with arguments and insert the results into a new object of the class.

Parameters

string $query

the SQL statement

array $params

the params array

string $class

the class to create an object of and insert into

Returns

object —

with resultset

executeFetchInto()

executeFetchInto(string  $query, array  $params, string  $object = null) : object

Execute a select-query with arguments and insert the results into an existing object.

Parameters

string $query

the SQL statement

array $params

the params array

string $object

the existing object to insert into

Returns

object —

with resultset

fetchAll()

fetchAll() : array

Fetch all resultset.

Returns

array —

with resultset.

fetch()

fetch() : mixed

Fetch one resultset.

Returns

mixed —

with resultset.

fetchClass()

fetchClass(string  $classname) : object

Fetch one resultset as a new object from this class.

Parameters

string $classname

which type of object to instantiate.

Returns

object —

with resultset.

fetchAllClass()

fetchAllClass(string  $classname) : array

Fetch full resultset as new objects from this class.

Parameters

string $classname

which type of object to instantiate.

Returns

array —

with resultset.

fetchInto()

fetchInto(object  $object) : array

Fetch one resultset into an object.

Parameters

object $object

to insert values into.

Returns

array —

with resultset.

execute()

execute(string  $query, array  $params = array()) : self

Execute a SQL-query and ignore the resultset.

Parameters

string $query

the SQL statement

array $params

the params array

Throws

\Anax\Database\Exception\Exception

when failing to prepare question or when not connected.

Returns

self

lastInsertId()

lastInsertId() : integer

Return last insert id from autoincremented key on INSERT.

Returns

integer —

as last insert id.

rowCount()

rowCount() : integer

Return rows affected of last INSERT, UPDATE, DELETE

Returns

integer —

as rows affected on last statement

fetchObject()

fetchObject(string  $classname) : object

Fetch one resultset as an object from this class.

OBSOLETE replaced by fetchClass

Parameters

string $classname

which type of object to instantiate.

Returns

object —

with resultset.

fetchOne()

fetchOne() : mixed

Fetch one resultset. OBSOLETE replace by fetch()

Returns

mixed —

with resultset.

createException()

createException(string  $msg, string  $query, array  $param) : void

Throw exception using detailed message.

Parameters

string $msg

detailed error message from PDO

string $query

query to execute

array $param

to match ? in statement

Throws

\Anax\Database\Exception

pdoException()

pdoException(string  $query, array  $param) : void

Throw exception when pdo failed using detailed message.

Parameters

string $query

query to execute

array $param

to match ? in statement

Throws

\Anax\Database\Exception

statementException()

statementException(string  $query, array  $param) : void

Throw exception when statement failed using detailed message.

Parameters

string $query

query to execute

array $param

to match ? in statement

Throws

\Anax\Database\Exception

expandParamArray()

expandParamArray(string  $query, array  $params) : array

Support arrays in params, extract array items and add to $params and insert ? for each entry in the array.

Parameters

string $query

as the query to prepare.

array $params

the parameters that may contain arrays.

Returns

array —

with query and params.