Connection
class Connection implements ConnectionInterface (View source)
Traits
Properties
protected PDO | $pdo | The active PDO connection. | |
protected PDO | $readPdo | The active PDO connection used for reads. | |
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 mixed | $fetchArgument | The argument for the fetch mode. | |
protected array | $fetchConstructorArgument | The constructor arguments for the PDO::FETCH_CLASS fetch mode. | |
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 string | $database | The name of the connected database. | |
protected Connection | $doctrineConnection | The instance of Doctrine connection. | |
protected string | $tablePrefix | The table prefix for the connection. | |
protected array | $config | The database connection configuration options. |
Methods
Determine if the given exception was caused by a lost connection.
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.
Get a new raw query expression.
Run a select statement and return a single result.
Run a select statement against the database.
Run a select statement against the database.
No description
Bind values to their parameters in the given statement.
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.
Prepare the query bindings for execution.
Start a new database transaction.
Commit the active database transaction.
Rollback the active database transaction.
Get the number of active transactions.
Handle a query exception that occurred during query execution.
Disconnect from the underlying PDO connection.
Reconnect to the database.
Reconnect to the database if a PDO connection is missing.
Log a query in the connection's query log.
Fire an event for this connection.
Get the elapsed time since a given starting point.
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 default fetch mode for the connection.
Get the fetch argument to be applied when selecting.
Get custom constructor arguments for the PDO::FETCH_CLASS fetch mode.
Set the default fetch mode for the connection, and optional arguments for the given fetch mode.
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.
Details
protected bool
causedByLostConnection(Exception $e)
Determine if the given exception was caused by a lost connection.
at line 160
void
__construct(PDO|Closure $pdo, string $database = '', string $tablePrefix = '', array $config = [])
Create a new database connection instance.
at line 186
void
useDefaultQueryGrammar()
Set the query grammar to the default implementation.
at line 206
void
useDefaultSchemaGrammar()
Set the schema grammar to the default implementation.
at line 226
void
useDefaultPostProcessor()
Set the query post processor to the default implementation.
at line 284
Expression
raw(mixed $value)
Get a new raw query expression.
at line 296
mixed
selectOne(string $query, array $bindings = [])
Run a select statement and return a single result.
at line 310
array
selectFromWriteConnection(string $query, array $bindings = [])
Run a select statement against the database.
at line 323
array
select(string $query, array $bindings = [], bool $useReadPdo = true)
Run a select statement against the database.
at line 362
cursor($query, $bindings = [], $useReadPdo = true)
at line 405
void
bindValues(PDOStatement $statement, array $bindings)
Bind values to their parameters in the given statement.
at line 421
protected PDO
getPdoForSelect(bool $useReadPdo = true)
Get the PDO connection to use for a select query.
at line 433
bool
insert(string $query, array $bindings = [])
Run an insert statement against the database.
at line 445
int
update(string $query, array $bindings = [])
Run an update statement against the database.
at line 457
int
delete(string $query, array $bindings = [])
Run a delete statement against the database.
at line 469
bool
statement(string $query, array $bindings = [])
Execute an SQL statement and return the boolean result.
at line 491
int
affectingStatement(string $query, array $bindings = [])
Run an SQL statement and get the number of rows affected.
at line 517
bool
unprepared(string $query)
Run a raw, unprepared query against the PDO connection.
at line 534
array
prepareBindings(array $bindings)
Prepare the query bindings for execution.
at line 595
void
beginTransaction()
Start a new database transaction.
at line 621
void
commit()
Commit the active database transaction.
at line 637
void
rollBack()
Rollback the active database transaction.
at line 657
int
transactionLevel()
Get the number of active transactions.
at line 700
protected mixed
run(string $query, array $bindings, Closure $callback)
Run a SQL statement and log its execution context.
at line 741
protected mixed
runQueryCallback(string $query, array $bindings, Closure $callback)
Run a SQL statement.
at line 773
protected mixed
tryAgainIfCausedByLostConnection(QueryException $e, string $query, array $bindings, Closure $callback)
Handle a query exception that occurred during query execution.
at line 789
void
disconnect()
Disconnect from the underlying PDO connection.
at line 801
void
reconnect()
Reconnect to the database.
at line 815
protected void
reconnectIfMissingConnection()
Reconnect to the database if a PDO connection is missing.
at line 830
void
logQuery(string $query, array $bindings, float|null $time = null)
Log a query in the connection's query log.
at line 862
protected void
fireConnectionEvent(string $event)
Fire an event for this connection.
at line 884
protected float
getElapsedTime(int $start)
Get the elapsed time since a given starting point.
at line 894
bool
isDoctrineAvailable()
Is Doctrine available?
at line 906
Column
getDoctrineColumn(string $table, string $column)
Get a Doctrine Schema Column instance.
at line 918
AbstractSchemaManager
getDoctrineSchemaManager()
Get the Doctrine DBAL schema manager for the connection.
at line 928
Connection
getDoctrineConnection()
Get the Doctrine DBAL database connection instance.
at line 1007
$this
setReconnector(callable $reconnector)
Set the reconnect instance on the connection.
at line 1019
string|null
getName()
Get the database connection name.
at line 1030
mixed
getConfig(string $option)
Get an option from the configuration options.
at line 1040
string
getDriverName()
Get the PDO driver name.
at line 1103
void
setPostProcessor(Processor $processor)
Set the query post processor used by the connection.
at line 1113
Dispatcher
getEventDispatcher()
Get the event dispatcher used by the connection.
at line 1124
void
setEventDispatcher(Dispatcher $events)
Set the event dispatcher instance on the connection.
at line 1134
bool
pretending()
Determine if the connection in a "dry run".
at line 1144
int
getFetchMode()
Get the default fetch mode for the connection.
at line 1154
mixed
getFetchArgument()
Get the fetch argument to be applied when selecting.
at line 1164
array
getFetchConstructorArgument()
Get custom constructor arguments for the PDO::FETCH_CLASS fetch mode.
at line 1177
int
setFetchMode(int $fetchMode, mixed $fetchArgument = null, array $fetchConstructorArgument = [])
Set the default fetch mode for the connection, and optional arguments for the given fetch mode.
at line 1189
array
getQueryLog()
Get the connection query log.
at line 1199
void
flushQueryLog()
Clear the query log.
at line 1209
void
enableQueryLog()
Enable the query log on the connection.
at line 1219
void
disableQueryLog()
Disable the query log on the connection.
at line 1229
bool
logging()
Determine whether we're logging queries.
at line 1239
string
getDatabaseName()
Get the name of the connected database.
at line 1250
string
setDatabaseName(string $database)
Set the name of the connected database.
at line 1260
string
getTablePrefix()
Get the table prefix for the connection.
at line 1271
void
setTablePrefix(string $prefix)
Set the table prefix in use by the connection.