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.

int
affectedRows()

Gets the number of affected rows. Alias for getAffectedRows().

int
getInsertId($sequence = NULL)

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

int
insertId($sequence = NULL)

Retrieves the ID generated for an AUTO_INCREMENT column. Alias for getInsertId().

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)

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 56
__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 138
void __destruct()

Automatically frees the resources allocated for this result set.

Return Value

void

at line 149
final void connect()

Connects to a database.

Return Value

void

at line 168
final void disconnect()

Disconnects from a database.

Return Value

void

at line 179
final bool isConnected()

Returns TRUE when connection was established.

Return Value

bool

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

deprecated

No description

Parameters

$config
$key
$alias

at line 218
final Driver getDriver()

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

Return Value

Driver

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

Generates SQL query.

Parameters

$args

Return Value

string

Exceptions

Exception

at line 256
final bool test($args)

Generates and prints SQL query.

Parameters

$args

Return Value

bool

at line 280
final DataSource dataSource($args)

Generates (translates) and returns SQL query as DataSource.

Parameters

$args

Return Value

DataSource

Exceptions

Exception

at line 292
protected string translateArgs($args)

Generates SQL query.

Parameters

$args

Return Value

string

at line 309
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 339
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 355
int affectedRows()

Gets the number of affected rows. Alias for getAffectedRows().

Return Value

int

number of rows

Exceptions

Exception

at line 367
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 384
int insertId($sequence = NULL)

Retrieves the ID generated for an AUTO_INCREMENT column. Alias for getInsertId().

Parameters

$sequence

Return Value

int

Exceptions

Exception

at line 395
void begin($savepoint = NULL)

Begins a transaction (if supported).

Parameters

$savepoint

Return Value

void

at line 415
void commit($savepoint = NULL)

Commits statements in a transaction.

Parameters

$savepoint

Return Value

void

at line 435
void rollback($savepoint = NULL)

Rollback changes in a transaction.

Parameters

$savepoint

Return Value

void

at line 455
Result createResultSet(ResultDriver $resultDriver)

Result set factory.

Parameters

ResultDriver $resultDriver

Return Value

Result

at line 469
Fluent command()

No description

Return Value

Fluent

at line 479
Fluent select($args)

No description

Parameters

$args

Return Value

Fluent

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

No description

Parameters

$table
$args

Return Value

Fluent

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

No description

Parameters

$table
$args

Return Value

Fluent

at line 521
Fluent delete($table)

No description

Parameters

$table

Return Value

Fluent

at line 534
HashMap getSubstitutes()

Returns substitution hashmap.

Return Value

HashMap

at line 544
string substitute($value)

Provides substitution.

Parameters

$value

Return Value

string

at line 561
Row|false fetch($args)

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

Parameters

$args

Return Value

Row|false

Exceptions

Exception

at line 574
Row[] fetchAll($args)

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

Parameters

$args

Return Value

Row[]

Exceptions

Exception

at line 587
mixed fetchSingle($args)

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

Parameters

$args

Return Value

mixed

Exceptions

Exception

at line 600
array fetchPairs($args)

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

Parameters

$args

Return Value

array

Exceptions

Exception

at line 610
static Literal literal($value)

No description

Parameters

$value

Return Value

Literal

at line 624
int loadFile($file)

Import SQL dump from file.

Parameters

$file

Return Value

int

count of sql commands

at line 634
Database getDatabaseInfo()

Gets a information about the current database.

Return Value

Database

at line 644
__wakeup()

Prevents unserialization.

at line 653
__sleep()

Prevents serialization.

at line 659
protected onEvent($arg)

No description

Parameters

$arg

Traits

Better OOP experience.