Connection
class Connection
Database connection.
Properties
protected string | $name | Connection name. | |
protected string. | $queryCompiler | Query compiler. | |
protected string | $queryBuilderHelper | Query builder helper. | |
protected string | $dsn | Connection DSN. | |
protected string | $username | Database username. | |
protected string | $password | Database password. | |
protected bool | $enableLog | Enable the query log? | |
protected bool | $reconnect | Should we reconnect? | |
protected bool | $usePersistentConnection | Should we use a persistent connection? | |
protected array | $options | PDO options. | |
protected array | $onConnectQueries | Queries that should be executed upon connecting. | |
protected PDO | $pdo | PDO object. | |
protected int | $transactionNestingLevel | Transaction nesting level. | |
protected array | $log | Query log. | |
protected bool | $supportsTransactionalDDL | Does the connection support transactional DDL? |
Methods
Constructor.
Closes the database connection.
Does the connection support transactional DDL?
Returns the connection name.
Returns a query builder helper instance.
Enables the query log.
Disables the query log.
Returns the connection options.
Creates a new PDO instance.
Checks if the connection is alive.
Prepares query for logging.
Adds a query to the query log.
Clears the query log.
Returns the query log for the connection.
Prepare query and params.
Should we try to reestablish the connection?
Binds parameter to the prepared statement.
Prepares a query.
Executes the prepared query and returns TRUE on success or FALSE on failure.
Executes the query and returns TRUE on success or FALSE on failure.
Executes the query and return number of affected rows.
Returns the value of the first column of the first row of the result set.
Executes a SELECT query and returns an array containing the values of the indicated 0-indexed column.
Executes a SELECT query and returns an array where the first column is used as keys and the second as values.
Returns the first row of the result set.
Returns an array containing all of the result set rows.
Returns a generator that lets you iterate over the results.
Creates a new savepoint.
Rolls back to the previously created savepoint.
Begin a transaction.
Commits a transaction.
Roll back a transaction.
Returns the transaction nesting level.
Returns TRUE if we're in a transaction and FALSE if not.
Details
at line 161
__construct(string $name, string $queryCompiler, string $queryBuilderHelper, array $config)
Constructor.
at line 197
close()
Closes the database connection.
at line 207
bool
supportsTransactionalDDL()
Does the connection support transactional DDL?
at line 217
string
getName()
Returns the connection name.
at line 227
HelperInterface
getQueryBuilderHelper()
Returns a query builder helper instance.
at line 252
PDO
getPDO()
Returns the PDO instance.
at line 260
enableLog()
Enables the query log.
at line 268
disableLog()
Disables the query log.
at line 278
protected array
getConnectionOptions()
Returns the connection options.
at line 295
protected PDO
connect()
Creates a PDO instance.
at line 323
reconnect()
Creates a new PDO instance.
at line 333
bool
isAlive()
Checks if the connection is alive.
at line 354
protected string
prepareQueryForLog(string $query, array $params)
Prepares query for logging.
at line 394
protected
log(string $query, array $params, float $start)
Adds a query to the query log.
at line 406
clearLog()
Clears the query log.
at line 416
array
getLog()
Returns the query log for the connection.
at line 428
protected array
prepareQueryAndParams(string $query, array $params)
Prepare query and params.
at line 459
protected bool
isConnectionLostAndShouldItBeReestablished()
Should we try to reestablish the connection?
at line 471
protected
bindParameter(PDOStatement $statement, int $key, mixed $value)
Binds parameter to the prepared statement.
at line 514
protected array
prepare(string $query, array $params)
Prepares a query.
at line 558
protected bool
execute(array $prepared)
Executes the prepared query and returns TRUE on success or FALSE on failure.
at line 582
bool
query(string $query, array $params = [])
Executes the query and returns TRUE on success or FALSE on failure.
at line 594
int
queryAndCount(string $query, array $params = [])
Executes the query and return number of affected rows.
at line 610
mixed
column(string $query, array $params = [])
Returns the value of the first column of the first row of the result set.
at line 626
array
columns(string $query, array $params = [])
Executes a SELECT query and returns an array containing the values of the indicated 0-indexed column.
at line 638
array
pairs(string $query, array $params = [])
Executes a SELECT query and returns an array where the first column is used as keys and the second as values.
at line 651
mixed
first(string $query, array $params = [], mixed ...$fetchMode)
Returns the first row of the result set.
at line 673
array
all(string $query, array $params = [], mixed ...$fetchMode)
Returns an array containing all of the result set rows.
at line 690
Generator
yield(string $query, array $params = [], mixed ...$fetchMode)
Returns a generator that lets you iterate over the results.
at line 719
Query
builder()
Returns a query builder instance.
at line 730
Query
table(string|Closure|Subquery|Raw $table)
Returns a query builder instance where we have already chosen the table we want to query.
at line 740
protected bool
createSavepoint()
Creates a new savepoint.
at line 750
protected bool
rollBackSavepoint()
Rolls back to the previously created savepoint.
at line 760
bool
beginTransaction()
Begin a transaction.
at line 775
bool
commitTransaction()
Commits a transaction.
at line 790
bool
rollBackTransaction()
Roll back a transaction.
at line 816
int
getTransactionNestingLevel()
Returns the transaction nesting level.
at line 826
bool
inTransaction()
Returns TRUE if we're in a transaction and FALSE if not.
at line 837
mixed
transaction(Closure $queries)
Executes queries and rolls back the transaction if any of them fail.