class Connection implements IConnection

Dibi connection.

Traits

Better OOP experience.

Properties

array $onEvent

Methods

__construct(array $config, string $name = null)

Connection options: (see driver-specific options too) - lazy (bool) => if true, connection will be established only when required - result (array) => result set options - formatDateTime => date-time format (if empty, DateTime objects will be returned) - formatJson => json format ( "string" for leaving value as is, "object" for decoding json as \stdClass, "array" for decoding json as an array - default ) - profiler (array) - run (bool) => enable profiler? - file => file to log - substitutes (array) => map of driver specific substitutes (under development) - onConnect (array) => list of SQL queries to execute (by Connection::query()) after connection is established

__destruct()

Automatically frees the resources allocated for this result set.

void
connect()

Connects to a database.

void
disconnect()

Disconnects from a database.

bool
isConnected()

Returns true when connection was established.

mixed
getConfig(string $key = null, $default = null)

Returns configuration variable. If no $key is passed, returns the entire array.

getDriver()

Returns the driver and connects to a database in lazy mode.

query(...$args)

Generates (translates) and executes SQL query.

string
translate(mixed ...$args)

Generates SQL query.

bool
test(mixed ...$args)

Generates and prints SQL query.

dataSource(mixed ...$args)

Generates (translates) and returns SQL query as DataSource.

string
translateArgs(array $args)

Generates SQL query.

nativeQuery(string $sql)

Executes the SQL query.

int
getAffectedRows()

Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.

int
getInsertId(string $sequence = null)

Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.

void
begin(string $savepoint = null)

Begins a transaction (if supported).

void
commit(string $savepoint = null)

Commits statements in a transaction.

void
rollback(string $savepoint = null)

Rollback changes in a transaction.

createResultSet(ResultDriver $resultDriver)

Result set factory.

command()

No description

select(...$args)

No description

update($table, iterable $args)

No description

insert(string $table, iterable $args)

No description

delete(string $table)

No description

getSubstitutes()

Returns substitution hashmap.

string
substitute(string $value)

Provides substitution.

Row|null
fetch(mixed ...$args)

Executes SQL query and fetch result - shortcut for query() & fetch().

array
fetchAll(mixed ...$args)

Executes SQL query and fetch results - shortcut for query() & fetchAll().

mixed
fetchSingle(mixed ...$args)

Executes SQL query and fetch first column - shortcut for query() & fetchSingle().

array
fetchPairs(mixed ...$args)

Executes SQL query and fetch pairs - shortcut for query() & fetchPairs().

static Literal
literal(string $value)

No description

static Expression
expression(...$args)

No description

int
loadFile(string $file, callable $onProgress = null)

Import SQL dump from file.

getDatabaseInfo()

Gets a information about the current database.

__wakeup()

Prevents unserialization.

__sleep()

Prevents serialization.

void
onEvent($arg)

No description

Details

at line 58
__construct(array $config, string $name = null)

Connection options: (see driver-specific options too) - lazy (bool) => if true, connection will be established only when required - result (array) => result set options - formatDateTime => date-time format (if empty, DateTime objects will be returned) - formatJson => json format ( "string" for leaving value as is, "object" for decoding json as \stdClass, "array" for decoding json as an array - default ) - profiler (array) - run (bool) => enable profiler? - file => file to log - substitutes (array) => map of driver specific substitutes (under development) - onConnect (array) => list of SQL queries to execute (by Connection::query()) after connection is established

Parameters

array $config
string $name

Exceptions

Exception

at line 96
__destruct()

Automatically frees the resources allocated for this result set.

at line 107
final void connect()

Connects to a database.

Return Value

void

at line 148
final void disconnect()

Disconnects from a database.

Return Value

void

at line 160
final bool isConnected()

Returns true when connection was established.

Return Value

bool

at line 171
final mixed getConfig(string $key = null, $default = null)

Returns configuration variable. If no $key is passed, returns the entire array.

Parameters

string $key
$default

Return Value

mixed

See also

self::__construct

at line 182
final Driver getDriver()

Returns the driver and connects to a database in lazy mode.

Return Value

Driver

at line 196
final Result query(...$args)

Generates (translates) and executes SQL query.

Parameters

...$args

Return Value

Result

Exceptions

Exception

at line 207
final string translate(mixed ...$args)

Generates SQL query.

Parameters

mixed ...$args

Return Value

string

Exceptions

Exception

at line 217
final bool test(mixed ...$args)

Generates and prints SQL query.

Parameters

mixed ...$args

Return Value

bool

at line 239
final DataSource dataSource(mixed ...$args)

Generates (translates) and returns SQL query as DataSource.

Parameters

mixed ...$args

Return Value

DataSource

Exceptions

Exception

at line 248
protected string translateArgs(array $args)

Generates SQL query.

Parameters

array $args

Return Value

string

at line 265
final Result nativeQuery(string $sql)

Executes the SQL query.

Parameters

string $sql

Return Value

Result

Exceptions

Exception

at line 295
int getAffectedRows()

Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.

Return Value

int

Exceptions

Exception

at line 312
int getInsertId(string $sequence = null)

Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.

Parameters

string $sequence

Return Value

int

Exceptions

Exception

at line 328
void begin(string $savepoint = null)

Begins a transaction (if supported).

Parameters

string $savepoint

Return Value

void

at line 352
void commit(string $savepoint = null)

Commits statements in a transaction.

Parameters

string $savepoint

Return Value

void

at line 376
void rollback(string $savepoint = null)

Rollback changes in a transaction.

Parameters

string $savepoint

Return Value

void

at line 400
Result createResultSet(ResultDriver $resultDriver)

Result set factory.

Parameters

ResultDriver $resultDriver

Return Value

Result

at line 412
Fluent command()

Return Value

Fluent

at line 418
Fluent select(...$args)

Parameters

...$args

Return Value

Fluent

at line 427
Fluent update($table, iterable $args)

Parameters

$table
iterable $args

Return Value

Fluent

at line 433
Fluent insert(string $table, iterable $args)

Parameters

string $table
iterable $args

Return Value

Fluent

at line 443
Fluent delete(string $table)

Parameters

string $table

Return Value

Fluent

at line 455
HashMap getSubstitutes()

Returns substitution hashmap.

Return Value

HashMap

at line 464
string substitute(string $value)

Provides substitution.

Parameters

string $value

Return Value

string

at line 480
Row|null fetch(mixed ...$args)

Executes SQL query and fetch result - shortcut for query() & fetch().

Parameters

mixed ...$args

Return Value

Row|null

Exceptions

Exception

at line 492
array fetchAll(mixed ...$args)

Executes SQL query and fetch results - shortcut for query() & fetchAll().

Parameters

mixed ...$args

Return Value

array

Exceptions

Exception

at line 504
mixed fetchSingle(mixed ...$args)

Executes SQL query and fetch first column - shortcut for query() & fetchSingle().

Parameters

mixed ...$args

Return Value

mixed

Exceptions

Exception

at line 515
array fetchPairs(mixed ...$args)

Executes SQL query and fetch pairs - shortcut for query() & fetchPairs().

Parameters

mixed ...$args

Return Value

array

Exceptions

Exception

at line 521
static Literal literal(string $value)

Parameters

string $value

Return Value

Literal

at line 527
static Expression expression(...$args)

Parameters

...$args

Return Value

Expression

at line 541
int loadFile(string $file, callable $onProgress = null)

Import SQL dump from file.

Parameters

string $file
callable $onProgress

Return Value

int count of sql commands

at line 550
Database getDatabaseInfo()

Gets a information about the current database.

Return Value

Database

at line 562
__wakeup()

Prevents unserialization.

at line 571
__sleep()

Prevents serialization.

at line 577
protected void onEvent($arg)

Parameters

$arg

Return Value

void