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[]
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 143
final void connect()

Connects to a database.

Return Value

void

at line 162
final void disconnect()

Disconnects from a database.

Return Value

void

at line 173
final bool isConnected()

Returns true when connection was established.

Return Value

bool

at line 186
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 201
static alias($config, $key, $alias) deprecated

deprecated

No description

Parameters

$config
$key
$alias

at line 212
final Driver getDriver()

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

Return Value

Driver

at line 225
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 238
final string translate($args)

Generates SQL query.

Parameters

$args

Return Value

string

Exceptions

Exception

at line 250
final bool test($args)

Generates and prints SQL query.

Parameters

$args

Return Value

bool

at line 274
final DataSource dataSource($args)

Generates (translates) and returns SQL query as DataSource.

Parameters

$args

Return Value

DataSource

Exceptions

Exception

at line 286
protected string translateArgs($args)

Generates SQL query.

Parameters

$args

Return Value

string

at line 303
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 333
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 347
affectedRows() deprecated

deprecated

No description

at line 360
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 374
insertId($sequence = null) deprecated

deprecated

No description

Parameters

$sequence

at line 386
void begin($savepoint = null)

Begins a transaction (if supported).

Parameters

$savepoint

Return Value

void

at line 406
void commit($savepoint = null)

Commits statements in a transaction.

Parameters

$savepoint

Return Value

void

at line 426
void rollback($savepoint = null)

Rollback changes in a transaction.

Parameters

$savepoint

Return Value

void

at line 446
Result createResultSet(ResultDriver $resultDriver)

Result set factory.

Parameters

ResultDriver $resultDriver

Return Value

Result

at line 460
Fluent command()

No description

Return Value

Fluent

at line 470
Fluent select($args)

No description

Parameters

$args

Return Value

Fluent

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

No description

Parameters

$table
$args

Return Value

Fluent

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

No description

Parameters

$table
$args

Return Value

Fluent

at line 512
Fluent delete($table)

No description

Parameters

$table

Return Value

Fluent

at line 525
HashMap getSubstitutes()

Returns substitution hashmap.

Return Value

HashMap

at line 535
string substitute($value)

Provides substitution.

Parameters

$value

Return Value

string

at line 552
Row|false fetch($args)

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

Parameters

$args

Return Value

Row|false

Exceptions

Exception

at line 565
Row[] fetchAll($args)

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

Parameters

$args

Return Value

Row[]

Exceptions

Exception

at line 578
mixed fetchSingle($args)

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

Parameters

$args

Return Value

mixed

Exceptions

Exception

at line 591
array fetchPairs($args)

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

Parameters

$args

Return Value

array

Exceptions

Exception

at line 601
static Literal literal($value)

No description

Parameters

$value

Return Value

Literal

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

Import SQL dump from file.

Parameters

$file
callable $onProgress

Return Value

int

count of sql commands

at line 626
Database getDatabaseInfo()

Gets a information about the current database.

Return Value

Database

at line 636
__wakeup()

Prevents unserialization.

at line 645
__sleep()

Prevents serialization.

at line 651
protected onEvent($arg)

No description

Parameters

$arg

Traits

Better OOP experience.