Connection
class Connection implements IConnection
Dibi connection.
Properties
$onEvent | function (Event $event); Occurs after query is executed |
||
int read-only | $affectedRows | ||
int read-only | $insertId |
Methods
Connection options: (see driver-specific options too)
- lazy (bool) => if true, connection will be established only when required
- result (array) => result set options
- normalize => normalizes result fields (default: true)
- formatDateTime => date-time format empty for decoding as Dibi\DateTime (default) "..." formatted according to given format, see https://www.php.net/manual/en/datetime.format.php "native" for leaving value as is
- formatTimeInterval => time-interval format empty for decoding as DateInterval (default) "..." formatted according to given format, see https://www.php.net/manual/en/dateinterval.format.php "native" for leaving value as is
- formatJson => json format "array" for decoding json as an array (default) "object" for decoding json as \stdClass "native" for leaving value as is
- profiler (array)
- run (bool) => enable profiler?
- file => file to log
- errorsOnly (bool) => log only errors
- substitutes (array) => map of driver specific substitutes (under development)
- onConnect (array) => list of SQL queries to execute (by Connection::query()) after connection is established
Automatically frees the resources allocated for this result set.
Connects to a database.
Disconnects from a database.
Returns true when connection was established.
Returns configuration variable. If no $key is passed, returns the entire array.
Generates SQL query.
Generates and prints SQL query.
Generates (translates) and returns SQL query as DataSource.
Executes the SQL query.
Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.
Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
Begins a transaction (if supported).
Commits statements in a transaction.
Rollback changes in a transaction.
No description
Returns substitution hashmap.
Provides substitution.
Executes SQL query and fetch result - shortcut for query() & fetch().
Executes SQL query and fetch results - shortcut for query() & fetchAll().
Executes SQL query and fetch first column - shortcut for query() & fetchSingle().
Executes SQL query and fetch pairs - shortcut for query() & fetchPairs().
No description
Import SQL dump from file.
Gets a information about the current database.
Prevents unserialization.
Prevents serialization.
No description
Details
at line 68
__construct(array $config, string|null $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
- normalize => normalizes result fields (default: true)
- formatDateTime => date-time format empty for decoding as Dibi\DateTime (default) "..." formatted according to given format, see https://www.php.net/manual/en/datetime.format.php "native" for leaving value as is
- formatTimeInterval => time-interval format empty for decoding as DateInterval (default) "..." formatted according to given format, see https://www.php.net/manual/en/dateinterval.format.php "native" for leaving value as is
- formatJson => json format "array" for decoding json as an array (default) "object" for decoding json as \stdClass "native" for leaving value as is
- profiler (array)
- run (bool) => enable profiler?
- file => file to log
- errorsOnly (bool) => log only errors
- substitutes (array) => map of driver specific substitutes (under development)
- onConnect (array) => list of SQL queries to execute (by Connection::query()) after connection is established
at line 113
__destruct()
Automatically frees the resources allocated for this result set.
at line 124
final void
connect()
Connects to a database.
at line 169
final void
disconnect()
Disconnects from a database.
at line 181
final bool
isConnected()
Returns true when connection was established.
at line 191
final mixed
getConfig(string|null $key = null, $default = null)
Returns configuration variable. If no $key is passed, returns the entire array.
at line 202
final Driver
getDriver()
Returns the driver and connects to a database in lazy mode.
at line 216
final Result
query(...$args)
Generates (translates) and executes SQL query.
at line 226
final string
translate(mixed ...$args)
Generates SQL query.
at line 239
final bool
test(mixed ...$args)
Generates and prints SQL query.
at line 261
final DataSource
dataSource(mixed ...$args)
Generates (translates) and returns SQL query as DataSource.
at line 271
final Result
nativeQuery(string $sql)
Executes the SQL query.
at line 303
int
getAffectedRows()
Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.
at line 322
int
getInsertId(string|null $sequence = null)
Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
at line 340
void
begin(string|null $savepoint = null)
Begins a transaction (if supported).
at line 369
void
commit(string|null $savepoint = null)
Commits statements in a transaction.
at line 398
void
rollback(string|null $savepoint = null)
Rollback changes in a transaction.
at line 424
mixed
transaction(callable $callback)
No description
at line 454
Result
createResultSet(ResultDriver $resultDriver)
Result set factory.
at line 464
Fluent
command()
No description
at line 470
Fluent
select(...$args)
No description
at line 479
Fluent
update(string|string[] $table, iterable $args)
No description
at line 485
Fluent
insert(string $table, iterable $args)
No description
at line 496
Fluent
delete(string $table)
No description
at line 508
HashMap
getSubstitutes()
Returns substitution hashmap.
at line 517
string
substitute(string $value)
Provides substitution.
at line 532
Row|null
fetch(mixed ...$args)
Executes SQL query and fetch result - shortcut for query() & fetch().
at line 543
array
fetchAll(mixed ...$args)
Executes SQL query and fetch results - shortcut for query() & fetchAll().
at line 553
mixed
fetchSingle(mixed ...$args)
Executes SQL query and fetch first column - shortcut for query() & fetchSingle().
at line 563
array
fetchPairs(mixed ...$args)
Executes SQL query and fetch pairs - shortcut for query() & fetchPairs().
at line 569
static Literal
literal(string $value)
No description
at line 575
static Expression
expression(...$args)
No description
at line 589
int
loadFile(string $file, callable|null $onProgress = null)
Import SQL dump from file.
at line 598
Database
getDatabaseInfo()
Gets a information about the current database.
at line 611
__wakeup()
Prevents unserialization.
at line 620
__sleep()
Prevents serialization.
at line 626
protected void
onEvent($arg)
No description
Traits
Better OOP experience.