class Connection

Dibi connection.

Properties

array $onEvent
int read-only $affectedRows
int read-only $insertId

Methods

__construct($config, $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)
  • profiler (array or bool)
    • run (bool) => enable profiler?
    • file => file to log
  • substitutes (array) => map of driver specific substitutes (under development)

void
__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($key = null, $default = null)

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

static 
alias($config, $key, $alias) deprecated

No description

getDriver()

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

Result|int
query($args)

Generates (translates) and executes SQL query.

string
translate($args)

Generates SQL query.

bool
test($args)

Generates and prints SQL query.

dataSource($args)

Generates (translates) and returns SQL query as DataSource.

string
translateArgs($args)

Generates SQL query.

Result|int
nativeQuery($sql)

Executes the SQL query.

int
getAffectedRows()

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

affectedRows() deprecated

No description

int
getInsertId($sequence = null)

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

insertId($sequence = null) deprecated

No description

void
begin($savepoint = null)

Begins a transaction (if supported).

void
commit($savepoint = null)

Commits statements in a transaction.

void
rollback($savepoint = null)

Rollback changes in a transaction.

createResultSet(ResultDriver $resultDriver)

Result set factory.

command()

No description

select($args)

No description

update($table, $args)

No description

insert($table, $args)

No description

delete($table)

No description

getSubstitutes()

Returns substitution hashmap.

string
substitute($value)

Provides substitution.

Row|false
fetch($args)

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

Row[]|array[]
fetchAll($args)

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

mixed
fetchSingle($args)

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

array
fetchPairs($args)

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

static Literal
literal($value)

No description

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

Import SQL dump from file.

getDatabaseInfo()

Gets a information about the current database.

__wakeup()

Prevents unserialization.

__sleep()

Prevents serialization.

onEvent($arg)

No description

Details

at line 55
__construct($config, $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)
  • profiler (array or bool)
    • run (bool) => enable profiler?
    • file => file to log
  • substitutes (array) => map of driver specific substitutes (under development)

Parameters

$config
$name

Exceptions

Exception

at line 132
void __destruct()

Automatically frees the resources allocated for this result set.

Return Value

void

at line 144
final void connect()

Connects to a database.

Return Value

void

at line 167
final void disconnect()

Disconnects from a database.

Return Value

void

at line 178
final bool isConnected()

Returns true when connection was established.

Return Value

bool

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

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

Parameters

$key
$default

Return Value

mixed

See also

self::__construct

at line 206
static alias($config, $key, $alias) deprecated

deprecated

No description

Parameters

$config
$key
$alias

at line 217
final Driver getDriver()

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

Return Value

Driver

at line 232
final Result|int query($args)

Generates (translates) and executes SQL query.

Parameters

$args

Return Value

Result|int

result set or number of affected rows

Exceptions

Exception

at line 245
final string translate($args)

Generates SQL query.

Parameters

$args

Return Value

string

Exceptions

Exception

at line 257
final bool test($args)

Generates and prints SQL query.

Parameters

$args

Return Value

bool

at line 281
final DataSource dataSource($args)

Generates (translates) and returns SQL query as DataSource.

Parameters

$args

Return Value

DataSource

Exceptions

Exception

at line 293
protected string translateArgs($args)

Generates SQL query.

Parameters

$args

Return Value

string

at line 312
final Result|int nativeQuery($sql)

Executes the SQL query.

Parameters

$sql

Return Value

Result|int

result set or number of affected rows

Exceptions

Exception

at line 348
int getAffectedRows()

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

Return Value

int

number of rows

Exceptions

Exception

at line 364
affectedRows() deprecated

deprecated

No description

at line 377
int getInsertId($sequence = null)

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

Parameters

$sequence

Return Value

int

Exceptions

Exception

at line 393
insertId($sequence = null) deprecated

deprecated

No description

Parameters

$sequence

at line 405
void begin($savepoint = null)

Begins a transaction (if supported).

Parameters

$savepoint

Return Value

void

at line 431
void commit($savepoint = null)

Commits statements in a transaction.

Parameters

$savepoint

Return Value

void

at line 457
void rollback($savepoint = null)

Rollback changes in a transaction.

Parameters

$savepoint

Return Value

void

at line 483
Result createResultSet(ResultDriver $resultDriver)

Result set factory.

Parameters

ResultDriver $resultDriver

Return Value

Result

at line 497
Fluent command()

No description

Return Value

Fluent

at line 507
Fluent select($args)

No description

Parameters

$args

Return Value

Fluent

at line 519
Fluent update($table, $args)

No description

Parameters

$table
$args

Return Value

Fluent

at line 533
Fluent insert($table, $args)

No description

Parameters

$table
$args

Return Value

Fluent

at line 549
Fluent delete($table)

No description

Parameters

$table

Return Value

Fluent

at line 562
HashMap getSubstitutes()

Returns substitution hashmap.

Return Value

HashMap

at line 572
string substitute($value)

Provides substitution.

Parameters

$value

Return Value

string

at line 589
Row|false fetch($args)

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

Parameters

$args

Return Value

Row|false

Exceptions

Exception

at line 602
Row[]|array[] fetchAll($args)

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

Parameters

$args

Return Value

Row[]|array[]

Exceptions

Exception

at line 615
mixed fetchSingle($args)

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

Parameters

$args

Return Value

mixed

Exceptions

Exception

at line 628
array fetchPairs($args)

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

Parameters

$args

Return Value

array

Exceptions

Exception

at line 638
static Literal literal($value)

No description

Parameters

$value

Return Value

Literal

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

Import SQL dump from file.

Parameters

$file
callable $onProgress

Return Value

int

count of sql commands

at line 663
Database getDatabaseInfo()

Gets a information about the current database.

Return Value

Database

at line 675
__wakeup()

Prevents unserialization.

at line 684
__sleep()

Prevents serialization.

at line 690
protected onEvent($arg)

No description

Parameters

$arg

Traits

Better OOP experience.