\Disco\classesPDO

Wrapper around the native \PDO class.

Uses options set in your application configuration to make connections to the mysql instance.

Summary

Methods
Properties
Constants
__construct()
foreignKeyChecksOn()
foreignKeyChecksOff()
inTransaction()
beginTransaction()
commit()
rollback()
query()
insert()
create()
delete()
update()
select()
lastId()
set()
clean()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
setAssocativeArrayPlaceHolders()
setQuestionMarkPlaceHolders()
prepareType()
$transactionCounter
N/A

Properties

$transactionCounter

$transactionCounter : integer

Type

integer — The number of transactions open.

Methods

__construct()

__construct(null|string  $host = null, null|\Disco\classes\user  $user = null, null|string  $pw = null, null|string  $db = null, string  $engine = 'mysql', string  $charset = 'utf8') : void

Connect to the mysql instance. Uses the application configuration keys: - `PDO_ENGINE` - `DB_HOST` - `DB_USER` - `DB_PASSWORD` - `DB_DB` - `DB_CHARSET`

or the passed arguents as credentials.

Sets:

  • \PDO::ATTR_PERSISTENT = true
  • \PDO::ATTR_DEFAULT_FETCH_MOD = \PDO::FETCH_ASSOC
  • \PDO::ATTR_ERRMODE = \PDO::ERRMODE_EXCEPTION

Parameters

null|string $host

The host to connect to.

null|\Disco\classes\user $user

The user to connect with.

null|string $pw

The password to connect with.

null|string $db

The schema to connect to.

string $engine

The engine type to use, default is mysql.

string $charset

The charset to use, default is utf8.

foreignKeyChecksOn()

foreignKeyChecksOn() : void

Turn on foreign key checks (by default on, unless your local mysql is configured with `FOREIGN_KEY_CHECKS=0`).

foreignKeyChecksOff()

foreignKeyChecksOff() : void

Turn off foreign key checks.

inTransaction()

inTransaction() : integer

Returns the depth of transactions occuring, 0 means none, 1 or more is true.

Returns

integer —

The depth of transactions.

beginTransaction()

beginTransaction() : boolean

Begin a transaction.

Returns

boolean

commit()

commit() : boolean

Commit a transaction.

Returns

boolean

rollback()

rollback() : boolean

Roll back a transaction.

Returns

boolean

query()

query(string  $query,   $data = null) : mixed

Execute a query binding in any passed `$data` and returning the result.

Parameters

string $query

The query to execute.

$data

Throws

\Disco\exceptions\DBQuery

Returns

mixed

insert()

insert(string  $query,   $data = null) : null|integer

Perform an insert statement working just like `$this->query()` but returning the newly generated Auto Increment ID.

Parameters

string $query

The query to execute.

$data

Throws

\Disco\exceptions\DBQuery

Returns

null|integer

create()

create(string  $table, array  $data) : mixed

Perform an INSERT statement.

Parameters

string $table

The name of the table to insert into.

array $data

The data to insert into the table, must be an associative array.

Throws

\Disco\exceptions\DBQuery

Returns

mixed

delete()

delete(string  $table, array  $data, string  $conjunction = 'AND') : mixed

Perform a DELETE statement.

Parameters

string $table

The name of the table to delete from.

array $data

The conditions specifying what rows to delete from the table, must be an associative array.

string $conjunction

The conjunction used to form the where condition of the delete statement. Default is AND.

Throws

\Disco\exceptions\DBQuery

Returns

mixed

update()

update(string  $table, array  $data, array  $where, string  $conjunction = 'AND') : mixed

Perform an UPDATE statement .

Parameters

string $table

The name of the table to update.

array $data

The data to update the table with, must be an associative array.

array $where

The conditions specifying what rows should be updated in the table, must be an associative array.

string $conjunction

The conjunction used to form the where condition of the update statement. Default is AND.

Throws

\Disco\exceptions\DBQuery

Returns

mixed

select()

select(string  $table, string|array  $select, array  $where, string  $conjunction = 'AND') : mixed

Perform a SELECT statement .

Parameters

string $table

The name of the table to select from.

string|array $select

The fields to select from the table, can be a string of field or an array of fields.

array $where

The conditions specifying what rows should be selected from the table, must be an associative array.

string $conjunction

The conjunction used to form the where condition of the select statement. Default is AND.

Throws

\Disco\exceptions\DBQuery

Returns

mixed

lastId()

lastId() : null|integer

Get the last generated Auto Increment ID from a previous INSERT statement.

Returns

null|integer

set()

set(string  $q, string|array  $args) : string

Bind passed variables into a query string and do proper type checking and escaping before binding.

Parameters

string $q

The query string.

string|array $args

The variables to bind to the $q.

Throws

\Disco\exceptions\DBQuery

When the number of arguements doesn't match the numebr of ? placeholders.

Returns

string —

The $q with $args bound into it.

clean()

clean(mixed  $arg) : mixed

Wrap a arguement in quotes if need be.

Parameters

mixed $arg

The arguement to clean

Returns

mixed —

The cleaned arguement.

setAssocativeArrayPlaceHolders()

setAssocativeArrayPlaceHolders(string  $q, string|array  $args) : string

Set assocative array place holders in the query like `:id` with the corresponding value in the args.

Parameters

string $q

The query string.

string|array $args

The variables to bind to the $q.

Returns

string —

The $q with $args bound into it.

setQuestionMarkPlaceHolders()

setQuestionMarkPlaceHolders(string  $q, string|array  $args) : string

Set `?` mark value placeholders with the values passed in args in the order they are set in the query and the args.

Parameters

string $q

The query string.

string|array $args

The variables to bind to the $q.

Throws

\Disco\exceptions\DBQuery

When the number of arguements doesn't match the numebr of ? placeholders.

Returns

string —

The $q with $args bound into it.

prepareType()

prepareType(string|integer|float  $arg) : string|integer|float

Determine the type of variable being bound into the query, either a String or Numeric.

Parameters

string|integer|float $arg

The variable to prepare.

Returns

string|integer|float —

The $arg prepared.