Connection
in package
implements
ConnectionInterface
Uses
DetectsDeadlocks, DetectsLostConnections, ManagesTransactions
Interfaces, Classes and Traits
Table of Contents
- $config : array<string|int, mixed>
- The database connection configuration options.
- $database : string
- The name of the connected database.
- $doctrineConnection : Connection
- The instance of Doctrine connection.
- $events : Dispatcher
- The event dispatcher instance.
- $fetchMode : int
- The default fetch mode of the connection.
- $loggingQueries : bool
- Indicates whether queries are being logged.
- $pdo : PDO|Closure
- The active PDO connection.
- $postProcessor : Processor
- The query post processor implementation.
- $pretending : bool
- Indicates if the connection is in a "dry run".
- $queryGrammar : Grammar
- The query grammar implementation.
- $queryLog : array<string|int, mixed>
- All of the queries run against the connection.
- $readPdo : PDO|Closure
- The active PDO connection used for reads.
- $reconnector : callable
- The reconnector instance for the connection.
- $recordsModified : int
- Indicates if changes have been made to the database.
- $resolvers : array<string|int, mixed>
- The connection resolvers.
- $schemaGrammar : Grammar
- The schema grammar implementation.
- $tablePrefix : string
- The table prefix for the connection.
- $transactions : int
- The number of active transactions.
- __construct() : void
- Create a new database connection instance.
- affectingStatement() : int
- Run an SQL statement and get the number of rows affected.
- beginTransaction() : void
- Start a new database transaction.
- bindValues() : void
- Bind values to their parameters in the given statement.
- commit() : void
- Commit the active database transaction.
- cursor() : Generator
- Run a select statement against the database and returns a generator.
- delete() : int
- Run a delete statement against the database.
- disableQueryLog() : void
- Disable the query log on the connection.
- disconnect() : void
- Disconnect from the underlying PDO connection.
- enableQueryLog() : void
- Enable the query log on the connection.
- flushQueryLog() : void
- Clear the query log.
- getConfig() : mixed
- Get an option from the configuration options.
- getDatabaseName() : string
- Get the name of the connected database.
- getDoctrineColumn() : Column
- Get a Doctrine Schema Column instance.
- getDoctrineConnection() : Connection
- Get the Doctrine DBAL database connection instance.
- getDoctrineSchemaManager() : AbstractSchemaManager
- Get the Doctrine DBAL schema manager for the connection.
- getDriverName() : string
- Get the PDO driver name.
- getEventDispatcher() : Dispatcher
- Get the event dispatcher used by the connection.
- getName() : string|null
- Get the database connection name.
- getPdo() : PDO
- Get the current PDO connection.
- getPostProcessor() : Processor
- Get the query post processor used by the connection.
- getQueryGrammar() : Grammar
- Get the query grammar used by the connection.
- getQueryLog() : array<string|int, mixed>
- Get the connection query log.
- getReadPdo() : PDO
- Get the current PDO connection used for reading.
- getResolver() : mixed
- Get the connection resolver for the given driver.
- getSchemaBuilder() : Builder
- Get a schema builder instance for the connection.
- getSchemaGrammar() : Grammar
- Get the schema grammar used by the connection.
- getTablePrefix() : string
- Get the table prefix for the connection.
- insert() : bool
- Run an insert statement against the database.
- isDoctrineAvailable() : bool
- Is Doctrine available?
- listen() : void
- Register a database query listener with the connection.
- logging() : bool
- Determine whether we're logging queries.
- logQuery() : void
- Log a query in the connection's query log.
- prepareBindings() : array<string|int, mixed>
- Prepare the query bindings for execution.
- pretend() : array<string|int, mixed>
- Execute the given callback in "dry run" mode.
- pretending() : bool
- Determine if the connection in a "dry run".
- query() : Builder
- Get a new query builder instance.
- raw() : Expression
- Get a new raw query expression.
- reconnect() : void
- Reconnect to the database.
- recordsHaveBeenModified() : void
- Indicate if any records have been modified.
- resolverFor() : void
- Register a connection resolver.
- rollBack() : void
- Rollback the active database transaction.
- select() : array<string|int, mixed>
- Run a select statement against the database.
- selectFromWriteConnection() : array<string|int, mixed>
- Run a select statement against the database.
- selectOne() : mixed
- Run a select statement and return a single result.
- setDatabaseName() : string
- Set the name of the connected database.
- setEventDispatcher() : void
- Set the event dispatcher instance on the connection.
- setPdo() : $this
- Set the PDO connection.
- setPostProcessor() : void
- Set the query post processor used by the connection.
- setQueryGrammar() : void
- Set the query grammar used by the connection.
- setReadPdo() : $this
- Set the PDO connection used for reading.
- setReconnector() : $this
- Set the reconnect instance on the connection.
- setSchemaGrammar() : void
- Set the schema grammar used by the connection.
- setTablePrefix() : void
- Set the table prefix in use by the connection.
- statement() : bool
- Execute an SQL statement and return the boolean result.
- table() : Builder
- Begin a fluent query against a database table.
- transaction() : mixed
- Execute a Closure within a transaction.
- transactionLevel() : int
- Get the number of active transactions.
- unprepared() : bool
- Run a raw, unprepared query against the PDO connection.
- update() : int
- Run an update statement against the database.
- useDefaultPostProcessor() : void
- Set the query post processor to the default implementation.
- useDefaultQueryGrammar() : void
- Set the query grammar to the default implementation.
- useDefaultSchemaGrammar() : void
- Set the schema grammar to the default implementation.
- withTablePrefix() : Grammar
- Set the table prefix and return the grammar.
- causedByDeadlock() : bool
- Determine if the given exception was caused by a deadlock.
- causedByLostConnection() : bool
- Determine if the given exception was caused by a lost connection.
- createSavepoint() : void
- Create a save point within the database.
- createTransaction() : void
- Create a transaction within the database.
- event() : void
- Fire the given event if possible.
- fireConnectionEvent() : array<string|int, mixed>|null
- Fire an event for this connection.
- getDefaultPostProcessor() : Processor
- Get the default post processor instance.
- getDefaultQueryGrammar() : Grammar
- Get the default query grammar instance.
- getDefaultSchemaGrammar() : Grammar
- Get the default schema grammar instance.
- getElapsedTime() : float
- Get the elapsed time since a given starting point.
- getPdoForSelect() : PDO
- Get the PDO connection to use for a select query.
- handleBeginTransactionException() : void
- Handle an exception from a transaction beginning.
- handleQueryException() : mixed
- Handle a query exception.
- handleTransactionException() : void
- Handle an exception encountered when running a transacted statement.
- performRollBack() : void
- Perform a rollback within the database.
- prepared() : PDOStatement
- Configure the PDO prepared statement.
- reconnectIfMissingConnection() : void
- Reconnect to the database if a PDO connection is missing.
- run() : mixed
- Run a SQL statement and log its execution context.
- runQueryCallback() : mixed
- Run a SQL statement.
- tryAgainIfCausedByLostConnection() : mixed
- Handle a query exception that occurred during query execution.
- withFreshQueryLog() : array<string|int, mixed>
- Execute the given callback in "dry run" mode.
Properties
$config
The database connection configuration options.
protected
array<string|int, mixed>
$config
= []
$database
The name of the connected database.
protected
string
$database
$doctrineConnection
The instance of Doctrine connection.
protected
Connection
$doctrineConnection
$events
The event dispatcher instance.
protected
Dispatcher
$events
$fetchMode
The default fetch mode of the connection.
protected
int
$fetchMode
= PDO::FETCH_OBJ
$loggingQueries
Indicates whether queries are being logged.
protected
bool
$loggingQueries
= false
$pdo
The active PDO connection.
protected
PDO|Closure
$pdo
$postProcessor
The query post processor implementation.
protected
Processor
$postProcessor
$pretending
Indicates if the connection is in a "dry run".
protected
bool
$pretending
= false
$queryGrammar
The query grammar implementation.
protected
Grammar
$queryGrammar
$queryLog
All of the queries run against the connection.
protected
array<string|int, mixed>
$queryLog
= []
$readPdo
The active PDO connection used for reads.
protected
PDO|Closure
$readPdo
$reconnector
The reconnector instance for the connection.
protected
callable
$reconnector
$recordsModified
Indicates if changes have been made to the database.
protected
int
$recordsModified
= false
$resolvers
The connection resolvers.
protected
static array<string|int, mixed>
$resolvers
= []
$schemaGrammar
The schema grammar implementation.
protected
Grammar
$schemaGrammar
$tablePrefix
The table prefix for the connection.
protected
string
$tablePrefix
= ''
$transactions
The number of active transactions.
protected
int
$transactions
= 0
Methods
__construct()
Create a new database connection instance.
public
__construct(PDO|Closure $pdo[, string $database = '' ][, string $tablePrefix = '' ][, array<string|int, mixed> $config = [] ]) : void
Parameters
- $pdo : PDO|Closure
- $database : string = ''
- $tablePrefix : string = ''
- $config : array<string|int, mixed> = []
Return values
void —affectingStatement()
Run an SQL statement and get the number of rows affected.
public
affectingStatement(string $query[, array<string|int, mixed> $bindings = [] ]) : int
Parameters
- $query : string
- $bindings : array<string|int, mixed> = []
Return values
int —beginTransaction()
Start a new database transaction.
public
beginTransaction() : void
Tags
Return values
void —bindValues()
Bind values to their parameters in the given statement.
public
bindValues(PDOStatement $statement, array<string|int, mixed> $bindings) : void
Parameters
- $statement : PDOStatement
- $bindings : array<string|int, mixed>
Return values
void —commit()
Commit the active database transaction.
public
commit() : void
Return values
void —cursor()
Run a select statement against the database and returns a generator.
public
cursor(string $query[, array<string|int, mixed> $bindings = [] ][, bool $useReadPdo = true ]) : Generator
Parameters
- $query : string
- $bindings : array<string|int, mixed> = []
- $useReadPdo : bool = true
Return values
Generator —delete()
Run a delete statement against the database.
public
delete(string $query[, array<string|int, mixed> $bindings = [] ]) : int
Parameters
- $query : string
- $bindings : array<string|int, mixed> = []
Return values
int —disableQueryLog()
Disable the query log on the connection.
public
disableQueryLog() : void
Return values
void —disconnect()
Disconnect from the underlying PDO connection.
public
disconnect() : void
Return values
void —enableQueryLog()
Enable the query log on the connection.
public
enableQueryLog() : void
Return values
void —flushQueryLog()
Clear the query log.
public
flushQueryLog() : void
Return values
void —getConfig()
Get an option from the configuration options.
public
getConfig([string|null $option = null ]) : mixed
Parameters
- $option : string|null = null
Return values
mixed —getDatabaseName()
Get the name of the connected database.
public
getDatabaseName() : string
Return values
string —getDoctrineColumn()
Get a Doctrine Schema Column instance.
public
getDoctrineColumn(string $table, string $column) : Column
Parameters
- $table : string
- $column : string
Return values
Column —getDoctrineConnection()
Get the Doctrine DBAL database connection instance.
public
getDoctrineConnection() : Connection
Return values
Connection —getDoctrineSchemaManager()
Get the Doctrine DBAL schema manager for the connection.
public
getDoctrineSchemaManager() : AbstractSchemaManager
Return values
AbstractSchemaManager —getDriverName()
Get the PDO driver name.
public
getDriverName() : string
Return values
string —getEventDispatcher()
Get the event dispatcher used by the connection.
public
getEventDispatcher() : Dispatcher
Return values
Dispatcher —getName()
Get the database connection name.
public
getName() : string|null
Return values
string|null —getPdo()
Get the current PDO connection.
public
getPdo() : PDO
Return values
PDO —getPostProcessor()
Get the query post processor used by the connection.
public
getPostProcessor() : Processor
Return values
Processor —getQueryGrammar()
Get the query grammar used by the connection.
public
getQueryGrammar() : Grammar
Return values
Grammar —getQueryLog()
Get the connection query log.
public
getQueryLog() : array<string|int, mixed>
Return values
array<string|int, mixed> —getReadPdo()
Get the current PDO connection used for reading.
public
getReadPdo() : PDO
Return values
PDO —getResolver()
Get the connection resolver for the given driver.
public
static getResolver(string $driver) : mixed
Parameters
- $driver : string
Return values
mixed —getSchemaBuilder()
Get a schema builder instance for the connection.
public
getSchemaBuilder() : Builder
Return values
Builder —getSchemaGrammar()
Get the schema grammar used by the connection.
public
getSchemaGrammar() : Grammar
Return values
Grammar —getTablePrefix()
Get the table prefix for the connection.
public
getTablePrefix() : string
Return values
string —insert()
Run an insert statement against the database.
public
insert(string $query[, array<string|int, mixed> $bindings = [] ]) : bool
Parameters
- $query : string
- $bindings : array<string|int, mixed> = []
Return values
bool —isDoctrineAvailable()
Is Doctrine available?
public
isDoctrineAvailable() : bool
Return values
bool —listen()
Register a database query listener with the connection.
public
listen(Closure $callback) : void
Parameters
- $callback : Closure
Return values
void —logging()
Determine whether we're logging queries.
public
logging() : bool
Return values
bool —logQuery()
Log a query in the connection's query log.
public
logQuery(string $query, array<string|int, mixed> $bindings[, float|null $time = null ]) : void
Parameters
- $query : string
- $bindings : array<string|int, mixed>
- $time : float|null = null
Return values
void —prepareBindings()
Prepare the query bindings for execution.
public
prepareBindings(array<string|int, mixed> $bindings) : array<string|int, mixed>
Parameters
- $bindings : array<string|int, mixed>
Return values
array<string|int, mixed> —pretend()
Execute the given callback in "dry run" mode.
public
pretend(Closure $callback) : array<string|int, mixed>
Parameters
- $callback : Closure
Return values
array<string|int, mixed> —pretending()
Determine if the connection in a "dry run".
public
pretending() : bool
Return values
bool —query()
Get a new query builder instance.
public
query() : Builder
Return values
Builder —raw()
Get a new raw query expression.
public
raw(mixed $value) : Expression
Parameters
- $value : mixed
Return values
Expression —reconnect()
Reconnect to the database.
public
reconnect() : void
Tags
Return values
void —recordsHaveBeenModified()
Indicate if any records have been modified.
public
recordsHaveBeenModified([bool $value = true ]) : void
Parameters
- $value : bool = true
Return values
void —resolverFor()
Register a connection resolver.
public
static resolverFor(string $driver, Closure $callback) : void
Parameters
- $driver : string
- $callback : Closure
Return values
void —rollBack()
Rollback the active database transaction.
public
rollBack([int|null $toLevel = null ]) : void
Parameters
- $toLevel : int|null = null
Return values
void —select()
Run a select statement against the database.
public
select(string $query[, array<string|int, mixed> $bindings = [] ][, bool $useReadPdo = true ]) : array<string|int, mixed>
Parameters
- $query : string
- $bindings : array<string|int, mixed> = []
- $useReadPdo : bool = true
Return values
array<string|int, mixed> —selectFromWriteConnection()
Run a select statement against the database.
public
selectFromWriteConnection(string $query[, array<string|int, mixed> $bindings = [] ]) : array<string|int, mixed>
Parameters
- $query : string
- $bindings : array<string|int, mixed> = []
Return values
array<string|int, mixed> —selectOne()
Run a select statement and return a single result.
public
selectOne(string $query[, array<string|int, mixed> $bindings = [] ][, bool $useReadPdo = true ]) : mixed
Parameters
- $query : string
- $bindings : array<string|int, mixed> = []
- $useReadPdo : bool = true
Return values
mixed —setDatabaseName()
Set the name of the connected database.
public
setDatabaseName(string $database) : string
Parameters
- $database : string
Return values
string —setEventDispatcher()
Set the event dispatcher instance on the connection.
public
setEventDispatcher(Dispatcher $events) : void
Parameters
- $events : Dispatcher
Return values
void —setPdo()
Set the PDO connection.
public
setPdo(PDO|Closure|null $pdo) : $this
Parameters
- $pdo : PDO|Closure|null
Return values
$this —setPostProcessor()
Set the query post processor used by the connection.
public
setPostProcessor(Processor $processor) : void
Parameters
- $processor : Processor
Return values
void —setQueryGrammar()
Set the query grammar used by the connection.
public
setQueryGrammar(Grammar $grammar) : void
Parameters
- $grammar : Grammar
Return values
void —setReadPdo()
Set the PDO connection used for reading.
public
setReadPdo(PDO|Closure|null $pdo) : $this
Parameters
- $pdo : PDO|Closure|null
Return values
$this —setReconnector()
Set the reconnect instance on the connection.
public
setReconnector(callable $reconnector) : $this
Parameters
- $reconnector : callable
Return values
$this —setSchemaGrammar()
Set the schema grammar used by the connection.
public
setSchemaGrammar(Grammar $grammar) : void
Parameters
- $grammar : Grammar
Return values
void —setTablePrefix()
Set the table prefix in use by the connection.
public
setTablePrefix(string $prefix) : void
Parameters
- $prefix : string
Return values
void —statement()
Execute an SQL statement and return the boolean result.
public
statement(string $query[, array<string|int, mixed> $bindings = [] ]) : bool
Parameters
- $query : string
- $bindings : array<string|int, mixed> = []
Return values
bool —table()
Begin a fluent query against a database table.
public
table(string $table) : Builder
Parameters
- $table : string
Return values
Builder —transaction()
Execute a Closure within a transaction.
public
transaction(Closure $callback[, int $attempts = 1 ]) : mixed
Parameters
- $callback : Closure
- $attempts : int = 1
Tags
Return values
mixed —transactionLevel()
Get the number of active transactions.
public
transactionLevel() : int
Return values
int —unprepared()
Run a raw, unprepared query against the PDO connection.
public
unprepared(string $query) : bool
Parameters
- $query : string
Return values
bool —update()
Run an update statement against the database.
public
update(string $query[, array<string|int, mixed> $bindings = [] ]) : int
Parameters
- $query : string
- $bindings : array<string|int, mixed> = []
Return values
int —useDefaultPostProcessor()
Set the query post processor to the default implementation.
public
useDefaultPostProcessor() : void
Return values
void —useDefaultQueryGrammar()
Set the query grammar to the default implementation.
public
useDefaultQueryGrammar() : void
Return values
void —useDefaultSchemaGrammar()
Set the schema grammar to the default implementation.
public
useDefaultSchemaGrammar() : void
Return values
void —withTablePrefix()
Set the table prefix and return the grammar.
public
withTablePrefix(Grammar $grammar) : Grammar
Parameters
- $grammar : Grammar
Return values
Grammar —causedByDeadlock()
Determine if the given exception was caused by a deadlock.
protected
causedByDeadlock(Exception $e) : bool
Parameters
- $e : Exception
Return values
bool —causedByLostConnection()
Determine if the given exception was caused by a lost connection.
protected
causedByLostConnection(Exception $e) : bool
Parameters
- $e : Exception
Return values
bool —createSavepoint()
Create a save point within the database.
protected
createSavepoint() : void
Return values
void —createTransaction()
Create a transaction within the database.
protected
createTransaction() : void
Return values
void —event()
Fire the given event if possible.
protected
event(mixed $event) : void
Parameters
- $event : mixed
Return values
void —fireConnectionEvent()
Fire an event for this connection.
protected
fireConnectionEvent(string $event) : array<string|int, mixed>|null
Parameters
- $event : string
Return values
array<string|int, mixed>|null —getDefaultPostProcessor()
Get the default post processor instance.
protected
getDefaultPostProcessor() : Processor
Return values
Processor —getDefaultQueryGrammar()
Get the default query grammar instance.
protected
getDefaultQueryGrammar() : Grammar
Return values
Grammar —getDefaultSchemaGrammar()
Get the default schema grammar instance.
protected
getDefaultSchemaGrammar() : Grammar
Return values
Grammar —getElapsedTime()
Get the elapsed time since a given starting point.
protected
getElapsedTime(int $start) : float
Parameters
- $start : int
Return values
float —getPdoForSelect()
Get the PDO connection to use for a select query.
protected
getPdoForSelect([bool $useReadPdo = true ]) : PDO
Parameters
- $useReadPdo : bool = true
Return values
PDO —handleBeginTransactionException()
Handle an exception from a transaction beginning.
protected
handleBeginTransactionException(Exception $e) : void
Parameters
- $e : Exception
Tags
Return values
void —handleQueryException()
Handle a query exception.
protected
handleQueryException(Exception $e, string $query, array<string|int, mixed> $bindings, Closure $callback) : mixed
Parameters
- $e : Exception
- $query : string
- $bindings : array<string|int, mixed>
- $callback : Closure
Tags
Return values
mixed —handleTransactionException()
Handle an exception encountered when running a transacted statement.
protected
handleTransactionException(Exception $e, int $currentAttempt, int $maxAttempts) : void
Parameters
- $e : Exception
- $currentAttempt : int
- $maxAttempts : int
Tags
Return values
void —performRollBack()
Perform a rollback within the database.
protected
performRollBack(int $toLevel) : void
Parameters
- $toLevel : int
Return values
void —prepared()
Configure the PDO prepared statement.
protected
prepared(PDOStatement $statement) : PDOStatement
Parameters
- $statement : PDOStatement
Return values
PDOStatement —reconnectIfMissingConnection()
Reconnect to the database if a PDO connection is missing.
protected
reconnectIfMissingConnection() : void
Return values
void —run()
Run a SQL statement and log its execution context.
protected
run(string $query, array<string|int, mixed> $bindings, Closure $callback) : mixed
Parameters
- $query : string
- $bindings : array<string|int, mixed>
- $callback : Closure
Tags
Return values
mixed —runQueryCallback()
Run a SQL statement.
protected
runQueryCallback(string $query, array<string|int, mixed> $bindings, Closure $callback) : mixed
Parameters
- $query : string
- $bindings : array<string|int, mixed>
- $callback : Closure
Tags
Return values
mixed —tryAgainIfCausedByLostConnection()
Handle a query exception that occurred during query execution.
protected
tryAgainIfCausedByLostConnection(QueryException $e, string $query, array<string|int, mixed> $bindings, Closure $callback) : mixed
Parameters
- $e : QueryException
- $query : string
- $bindings : array<string|int, mixed>
- $callback : Closure
Tags
Return values
mixed —withFreshQueryLog()
Execute the given callback in "dry run" mode.
protected
withFreshQueryLog(Closure $callback) : array<string|int, mixed>
Parameters
- $callback : Closure