Connection
class Connection implements ConnectionInterface
Traits
Properties
| protected PDO|Closure | $pdo | The active PDO connection. |
|
| protected PDO|Closure | $readPdo | The active PDO connection used for reads. |
|
| protected string | $database | The name of the connected database. |
|
| protected string | $tablePrefix | The table prefix for the connection. |
|
| protected array | $config | The database connection configuration options. |
|
| protected callable | $reconnector | The reconnector instance for the connection. |
|
| protected Grammar | $queryGrammar | The query grammar implementation. |
|
| protected Grammar | $schemaGrammar | The schema grammar implementation. |
|
| protected Processor | $postProcessor | The query post processor implementation. |
|
| protected Dispatcher | $events | The event dispatcher instance. |
|
| protected int | $fetchMode | The default fetch mode of the connection. |
|
| protected int | $transactions | The number of active transactions. |
|
| protected array | $queryLog | All of the queries run against the connection. |
|
| protected bool | $loggingQueries | Indicates whether queries are being logged. |
|
| protected bool | $pretending | Indicates if the connection is in a "dry run". |
|
| protected Connection | $doctrineConnection | The instance of Doctrine connection. |
|
| static protected array | $resolvers | The connection resolvers. |
Methods
Determine if the given exception was caused by a lost connection.
Handle an exception encountered when running a transacted statement.
Rollback the active database transaction.
Create a new database connection instance.
Set the query grammar to the default implementation.
Get the default query grammar instance.
Set the schema grammar to the default implementation.
Get the default schema grammar instance.
Set the query post processor to the default implementation.
Get the default post processor instance.
Get a schema builder instance for the connection.
Run a select statement and return a single result.
Run a select statement against the database.
Run a select statement against the database.
Run a select statement against the database and returns a generator.
Get the PDO connection to use for a select query.
Run an insert statement against the database.
Run an update statement against the database.
Run a delete statement against the database.
Execute an SQL statement and return the boolean result.
Run an SQL statement and get the number of rows affected.
Run a raw, unprepared query against the PDO connection.
Bind values to their parameters in the given statement.
Prepare the query bindings for execution.
Log a query in the connection's query log.
Get the elapsed time since a given starting point.
Handle a query exception.
Handle a query exception that occurred during query execution.
Reconnect to the database.
Reconnect to the database if a PDO connection is missing.
Disconnect from the underlying PDO connection.
Fire an event for this connection.
Fire the given event if possible.
Get a new raw query expression.
Is Doctrine available?
Get a Doctrine Schema Column instance.
Get the Doctrine DBAL schema manager for the connection.
Get the Doctrine DBAL database connection instance.
Get the current PDO connection used for reading.
Set the reconnect instance on the connection.
Get the database connection name.
Get an option from the configuration options.
Get the PDO driver name.
Get the query grammar used by the connection.
Get the schema grammar used by the connection.
Get the query post processor used by the connection.
Get the event dispatcher used by the connection.
Determine if the connection in a "dry run".
Get the connection query log.
Clear the query log.
Enable the query log on the connection.
Disable the query log on the connection.
Determine whether we're logging queries.
Get the name of the connected database.
Set the name of the connected database.
Get the table prefix for the connection.
Set the table prefix in use by the connection.
Get the connection resolver for the given driver.
Details
in
DetectsDeadlocks at line 16
protected bool
causedByDeadlock(Exception $e)
Determine if the given exception was caused by a deadlock.
in
DetectsLostConnections at line 16
protected bool
causedByLostConnection(Exception $e)
Determine if the given exception was caused by a lost connection.
in
ManagesTransactions at line 20
mixed
transaction(Closure $callback, int $attempts = 1)
Execute a Closure within a transaction.
in
ManagesTransactions at line 59
protected void
handleTransactionException(Exception $e, int $currentAttempt, int $maxAttempts)
Handle an exception encountered when running a transacted statement.
in
ManagesTransactions at line 90
void
beginTransaction()
Start a new database transaction.
in
ManagesTransactions at line 104
protected void
createTransaction()
Create a transaction within the database.
in
ManagesTransactions at line 122
protected void
createSavepoint()
Create a save point within the database.
in
ManagesTransactions at line 137
protected void
handleBeginTransactionException(Exception $e)
Handle an exception from a transaction beginning.
in
ManagesTransactions at line 153
void
commit()
Commit the active database transaction.
in
ManagesTransactions at line 170
void
rollBack(int|null $toLevel = null)
Rollback the active database transaction.
in
ManagesTransactions at line 199
protected void
performRollBack(int $toLevel)
Perform a rollback within the database.
in
ManagesTransactions at line 215
int
transactionLevel()
Get the number of active transactions.
at line 155
void
__construct(PDO|Closure $pdo, string $database = '', string $tablePrefix = '', array $config = [])
Create a new database connection instance.
at line 181
void
useDefaultQueryGrammar()
Set the query grammar to the default implementation.
at line 191
protected Grammar
getDefaultQueryGrammar()
Get the default query grammar instance.
at line 201
void
useDefaultSchemaGrammar()
Set the schema grammar to the default implementation.
at line 211
protected Grammar
getDefaultSchemaGrammar()
Get the default schema grammar instance.
at line 221
void
useDefaultPostProcessor()
Set the query post processor to the default implementation.
at line 231
protected Processor
getDefaultPostProcessor()
Get the default post processor instance.
at line 241
Builder
getSchemaBuilder()
Get a schema builder instance for the connection.
at line 256
Builder
table(string $table)
Begin a fluent query against a database table.
at line 266
Builder
query()
Get a new query builder instance.
at line 281
mixed
selectOne(string $query, array $bindings = [], bool $useReadPdo = true)
Run a select statement and return a single result.
at line 295
array
selectFromWriteConnection(string $query, array $bindings = [])
Run a select statement against the database.
at line 308
array
select(string $query, array $bindings = [], bool $useReadPdo = true)
Run a select statement against the database.
at line 337
Generator
cursor(string $query, array $bindings = [], bool $useReadPdo = true)
Run a select statement against the database and returns a generator.
at line 373
protected PDOStatement
prepared(PDOStatement $statement)
Configure the PDO prepared statement.
at line 390
protected PDO
getPdoForSelect(bool $useReadPdo = true)
Get the PDO connection to use for a select query.
at line 402
bool
insert(string $query, array $bindings = [])
Run an insert statement against the database.
at line 414
int
update(string $query, array $bindings = [])
Run an update statement against the database.
at line 426
int
delete(string $query, array $bindings = [])
Run a delete statement against the database.
at line 438
bool
statement(string $query, array $bindings = [])
Execute an SQL statement and return the boolean result.
at line 460
int
affectingStatement(string $query, array $bindings = [])
Run an SQL statement and get the number of rows affected.
at line 486
bool
unprepared(string $query)
Run a raw, unprepared query against the PDO connection.
at line 503
array
pretend(Closure $callback)
Execute the given callback in "dry run" mode.
at line 525
protected array
withFreshQueryLog(Closure $callback)
Execute the given callback in "dry run" mode.
at line 553
void
bindValues(PDOStatement $statement, array $bindings)
Bind values to their parameters in the given statement.
at line 569
array
prepareBindings(array $bindings)
Prepare the query bindings for execution.
at line 597
protected mixed
run(string $query, array $bindings, Closure $callback)
Run a SQL statement and log its execution context.
at line 634
protected mixed
runQueryCallback(string $query, array $bindings, Closure $callback)
Run a SQL statement.
at line 663
void
logQuery(string $query, array $bindings, float|null $time = null)
Log a query in the connection's query log.
at line 678
protected float
getElapsedTime(int $start)
Get the elapsed time since a given starting point.
at line 693
protected mixed
handleQueryException(Exception $e, string $query, array $bindings, Closure $callback)
Handle a query exception.
at line 715
protected mixed
tryAgainIfCausedByLostConnection(QueryException $e, string $query, array $bindings, Closure $callback)
Handle a query exception that occurred during query execution.
at line 733
void
reconnect()
Reconnect to the database.
at line 747
protected void
reconnectIfMissingConnection()
Reconnect to the database if a PDO connection is missing.
at line 759
void
disconnect()
Disconnect from the underlying PDO connection.
at line 770
void
listen(Closure $callback)
Register a database query listener with the connection.
at line 783
protected array|null
fireConnectionEvent(string $event)
Fire an event for this connection.
at line 805
protected void
event(mixed $event)
Fire the given event if possible.
at line 818
Expression
raw(mixed $value)
Get a new raw query expression.
at line 828
bool
isDoctrineAvailable()
Is Doctrine available?
at line 840
Column
getDoctrineColumn(string $table, string $column)
Get a Doctrine Schema Column instance.
at line 852
AbstractSchemaManager
getDoctrineSchemaManager()
Get the Doctrine DBAL schema manager for the connection.
at line 862
Connection
getDoctrineConnection()
Get the Doctrine DBAL database connection instance.
at line 880
PDO
getPdo()
Get the current PDO connection.
at line 894
PDO
getReadPdo()
Get the current PDO connection used for reading.
at line 941
$this
setReconnector(callable $reconnector)
Set the reconnect instance on the connection.
at line 953
string|null
getName()
Get the database connection name.
at line 964
mixed
getConfig(string|null $option = null)
Get an option from the configuration options.
at line 974
string
getDriverName()
Get the PDO driver name.
at line 984
Grammar
getQueryGrammar()
Get the query grammar used by the connection.
at line 995
void
setQueryGrammar(Grammar $grammar)
Set the query grammar used by the connection.
at line 1005
Grammar
getSchemaGrammar()
Get the schema grammar used by the connection.
at line 1016
void
setSchemaGrammar(Grammar $grammar)
Set the schema grammar used by the connection.
at line 1026
Processor
getPostProcessor()
Get the query post processor used by the connection.
at line 1037
void
setPostProcessor(Processor $processor)
Set the query post processor used by the connection.
at line 1047
Dispatcher
getEventDispatcher()
Get the event dispatcher used by the connection.
at line 1058
void
setEventDispatcher(Dispatcher $events)
Set the event dispatcher instance on the connection.
at line 1068
bool
pretending()
Determine if the connection in a "dry run".
at line 1078
array
getQueryLog()
Get the connection query log.
at line 1088
void
flushQueryLog()
Clear the query log.
at line 1098
void
enableQueryLog()
Enable the query log on the connection.
at line 1108
void
disableQueryLog()
Disable the query log on the connection.
at line 1118
bool
logging()
Determine whether we're logging queries.
at line 1128
string
getDatabaseName()
Get the name of the connected database.
at line 1139
string
setDatabaseName(string $database)
Set the name of the connected database.
at line 1149
string
getTablePrefix()
Get the table prefix for the connection.
at line 1160
void
setTablePrefix(string $prefix)
Set the table prefix in use by the connection.
at line 1187
static void
resolverFor(string $driver, Closure $callback)
Register a connection resolver.
at line 1198
static mixed
getResolver(string $driver)
Get the connection resolver for the given driver.