Connection
class Connection implements ConnectionInterface (View source)
Traits
DetectsDeadlocks |
DetectsLostConnections |
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
bool | causedByDeadlock(Exception $e) Determine if the given exception was caused by a deadlock. | from DetectsDeadlocks |
bool | causedByLostConnection(Exception $e) Determine if the given exception was caused by a lost connection. | from DetectsLostConnections |
void | __construct(PDO|Closure $pdo, string $database = '', string $tablePrefix = '', array $config = []) Create a new database connection instance. | |
void | useDefaultQueryGrammar() Set the query grammar to the default implementation. | |
Grammar | getDefaultQueryGrammar() Get the default query grammar instance. | |
void | useDefaultSchemaGrammar() Set the schema grammar to the default implementation. | |
Grammar | getDefaultSchemaGrammar() Get the default schema grammar instance. | |
void | useDefaultPostProcessor() Set the query post processor to the default implementation. | |
Processor | getDefaultPostProcessor() Get the default post processor instance. | |
Builder | getSchemaBuilder() Get a schema builder instance for the connection. | |
Builder | table(string $table) Begin a fluent query against a database table. | |
Builder | query() Get a new query builder instance. | |
Expression | raw(mixed $value) Get a new raw query expression. | |
mixed | selectOne(string $query, array $bindings = [], bool $useReadPdo = true) Run a select statement and return a single result. | |
array | selectFromWriteConnection(string $query, array $bindings = []) Run a select statement against the database. | |
array | select(string $query, array $bindings = [], bool $useReadPdo = true) Run a select statement against the database. | |
Generator | cursor(string $query, array $bindings = [], bool $useReadPdo = true) Run a select statement against the database and returns a generator. | |
void | bindValues(PDOStatement $statement, array $bindings) Bind values to their parameters in the given statement. | |
PDO | getPdoForSelect(bool $useReadPdo = true) Get the PDO connection to use for a select query. | |
bool | insert(string $query, array $bindings = []) Run an insert statement against the database. | |
int | update(string $query, array $bindings = []) Run an update statement against the database. | |
int | delete(string $query, array $bindings = []) Run a delete statement against the database. | |
bool | statement(string $query, array $bindings = []) Execute an SQL statement and return the boolean result. | |
int | affectingStatement(string $query, array $bindings = []) Run an SQL statement and get the number of rows affected. | |
bool | unprepared(string $query) Run a raw, unprepared query against the PDO connection. | |
array | prepareBindings(array $bindings) Prepare the query bindings for execution. | |
mixed | transaction(Closure $callback, int $attempts = 1) Execute a Closure within a transaction. | |
void | beginTransaction() Start a new database transaction. | |
void | commit() Commit the active database transaction. | |
void | rollBack() Rollback the active database transaction. | |
int | transactionLevel() Get the number of active transactions. | |
array | pretend(Closure $callback) Execute the given callback in "dry run" mode. | |
mixed | run(string $query, array $bindings, Closure $callback) Run a SQL statement and log its execution context. | |
mixed | runQueryCallback(string $query, array $bindings, Closure $callback) Run a SQL statement. | |
mixed | tryAgainIfCausedByLostConnection(QueryException $e, string $query, array $bindings, Closure $callback) Handle a query exception that occurred during query execution. | |
void | disconnect() Disconnect from the underlying PDO connection. | |
void | reconnect() Reconnect to the database. | |
void | reconnectIfMissingConnection() Reconnect to the database if a PDO connection is missing. | |
void | logQuery(string $query, array $bindings, float|null $time = null) Log a query in the connection's query log. | |
void | listen(Closure $callback) Register a database query listener with the connection. | |
void | fireConnectionEvent(string $event) Fire an event for this connection. | |
float | getElapsedTime(int $start) Get the elapsed time since a given starting point. | |
bool | isDoctrineAvailable() Is Doctrine available? | |
Column | getDoctrineColumn(string $table, string $column) Get a Doctrine Schema Column instance. | |
AbstractSchemaManager | getDoctrineSchemaManager() Get the Doctrine DBAL schema manager for the connection. | |
Connection | getDoctrineConnection() Get the Doctrine DBAL database connection instance. | |
PDO | getPdo() Get the current PDO connection. | |
PDO | getReadPdo() Get the current PDO connection used for reading. | |
$this | setPdo(PDO|null $pdo) Set the PDO connection. | |
$this | setReadPdo(PDO|null $pdo) Set the PDO connection used for reading. | |
$this | setReconnector(callable $reconnector) Set the reconnect instance on the connection. | |
string|null | getName() Get the database connection name. | |
mixed | getConfig(string $option) Get an option from the configuration options. | |
string | getDriverName() Get the PDO driver name. | |
Grammar | getQueryGrammar() Get the query grammar used by the connection. | |
void | setQueryGrammar(Grammar $grammar) Set the query grammar used by the connection. | |
Grammar | getSchemaGrammar() Get the schema grammar used by the connection. | |
void | setSchemaGrammar(Grammar $grammar) Set the schema grammar used by the connection. | |
Processor | getPostProcessor() Get the query post processor used by the connection. | |
void | setPostProcessor(Processor $processor) Set the query post processor used by the connection. | |
Dispatcher | getEventDispatcher() Get the event dispatcher used by the connection. | |
void | setEventDispatcher(Dispatcher $events) Set the event dispatcher instance on the connection. | |
bool | pretending() Determine if the connection in a "dry run". | |
int | getFetchMode() Get the default fetch mode for the connection. | |
mixed | getFetchArgument() Get the fetch argument to be applied when selecting. | |
array | getFetchConstructorArgument() Get custom constructor arguments for the PDO::FETCH_CLASS fetch mode. | |
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. | |
array | getQueryLog() Get the connection query log. | |
void | flushQueryLog() Clear the query log. | |
void | enableQueryLog() Enable the query log on the connection. | |
void | disableQueryLog() Disable the query log on the connection. | |
bool | logging() Determine whether we're logging queries. | |
string | getDatabaseName() Get the name of the connected database. | |
string | setDatabaseName(string $database) Set the name of the connected database. | |
string | getTablePrefix() Get the table prefix for the connection. | |
void | setTablePrefix(string $prefix) Set the table prefix in use by the connection. | |
Grammar | withTablePrefix(Grammar $grammar) Set the table prefix and return the grammar. |
Details
protected bool causedByDeadlock(Exception $e)
Determine if the given exception was caused by a deadlock.
protected bool causedByLostConnection(Exception $e)
Determine if the given exception was caused by a lost connection.
void __construct(PDO|Closure $pdo, string $database = '', string $tablePrefix = '', array $config = [])
Create a new database connection instance.
void useDefaultQueryGrammar()
Set the query grammar to the default implementation.
protected Grammar getDefaultQueryGrammar()
Get the default query grammar instance.
void useDefaultSchemaGrammar()
Set the schema grammar to the default implementation.
protected Grammar getDefaultSchemaGrammar()
Get the default schema grammar instance.
void useDefaultPostProcessor()
Set the query post processor to the default implementation.
protected Processor getDefaultPostProcessor()
Get the default post processor instance.
Builder getSchemaBuilder()
Get a schema builder instance for the connection.
Builder table(string $table)
Begin a fluent query against a database table.
Builder query()
Get a new query builder instance.
Expression raw(mixed $value)
Get a new raw query expression.
mixed selectOne(string $query, array $bindings = [], bool $useReadPdo = true)
Run a select statement and return a single result.
array selectFromWriteConnection(string $query, array $bindings = [])
Run a select statement against the database.
array select(string $query, array $bindings = [], bool $useReadPdo = true)
Run a select statement against the database.
Generator cursor(string $query, array $bindings = [], bool $useReadPdo = true)
Run a select statement against the database and returns a generator.
void bindValues(PDOStatement $statement, array $bindings)
Bind values to their parameters in the given statement.
protected PDO getPdoForSelect(bool $useReadPdo = true)
Get the PDO connection to use for a select query.
bool insert(string $query, array $bindings = [])
Run an insert statement against the database.
int update(string $query, array $bindings = [])
Run an update statement against the database.
int delete(string $query, array $bindings = [])
Run a delete statement against the database.
bool statement(string $query, array $bindings = [])
Execute an SQL statement and return the boolean result.
int affectingStatement(string $query, array $bindings = [])
Run an SQL statement and get the number of rows affected.
bool unprepared(string $query)
Run a raw, unprepared query against the PDO connection.
array prepareBindings(array $bindings)
Prepare the query bindings for execution.
mixed transaction(Closure $callback, int $attempts = 1)
Execute a Closure within a transaction.
void beginTransaction()
Start a new database transaction.
void commit()
Commit the active database transaction.
void rollBack()
Rollback the active database transaction.
int transactionLevel()
Get the number of active transactions.
array pretend(Closure $callback)
Execute the given callback in "dry run" mode.
protected mixed run(string $query, array $bindings, Closure $callback)
Run a SQL statement and log its execution context.
protected mixed runQueryCallback(string $query, array $bindings, Closure $callback)
Run a SQL statement.
protected mixed tryAgainIfCausedByLostConnection(QueryException $e, string $query, array $bindings, Closure $callback)
Handle a query exception that occurred during query execution.
void disconnect()
Disconnect from the underlying PDO connection.
void reconnect()
Reconnect to the database.
protected void reconnectIfMissingConnection()
Reconnect to the database if a PDO connection is missing.
void logQuery(string $query, array $bindings, float|null $time = null)
Log a query in the connection's query log.
void listen(Closure $callback)
Register a database query listener with the connection.
protected void fireConnectionEvent(string $event)
Fire an event for this connection.
protected float getElapsedTime(int $start)
Get the elapsed time since a given starting point.
bool isDoctrineAvailable()
Is Doctrine available?
Column getDoctrineColumn(string $table, string $column)
Get a Doctrine Schema Column instance.
AbstractSchemaManager getDoctrineSchemaManager()
Get the Doctrine DBAL schema manager for the connection.
Connection getDoctrineConnection()
Get the Doctrine DBAL database connection instance.
PDO getPdo()
Get the current PDO connection.
PDO getReadPdo()
Get the current PDO connection used for reading.
$this setPdo(PDO|null $pdo)
Set the PDO connection.
$this setReadPdo(PDO|null $pdo)
Set the PDO connection used for reading.
$this setReconnector(callable $reconnector)
Set the reconnect instance on the connection.
string|null getName()
Get the database connection name.
mixed getConfig(string $option)
Get an option from the configuration options.
string getDriverName()
Get the PDO driver name.
Grammar getQueryGrammar()
Get the query grammar used by the connection.
void setQueryGrammar(Grammar $grammar)
Set the query grammar used by the connection.
Grammar getSchemaGrammar()
Get the schema grammar used by the connection.
void setSchemaGrammar(Grammar $grammar)
Set the schema grammar used by the connection.
Processor getPostProcessor()
Get the query post processor used by the connection.
void setPostProcessor(Processor $processor)
Set the query post processor used by the connection.
Dispatcher getEventDispatcher()
Get the event dispatcher used by the connection.
void setEventDispatcher(Dispatcher $events)
Set the event dispatcher instance on the connection.
bool pretending()
Determine if the connection in a "dry run".
int getFetchMode()
Get the default fetch mode for the connection.
mixed getFetchArgument()
Get the fetch argument to be applied when selecting.
array getFetchConstructorArgument()
Get custom constructor arguments for the PDO::FETCH_CLASS fetch mode.
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.
array getQueryLog()
Get the connection query log.
void flushQueryLog()
Clear the query log.
void enableQueryLog()
Enable the query log on the connection.
void disableQueryLog()
Disable the query log on the connection.
bool logging()
Determine whether we're logging queries.
string getDatabaseName()
Get the name of the connected database.
string setDatabaseName(string $database)
Set the name of the connected database.
string getTablePrefix()
Get the table prefix for the connection.
void setTablePrefix(string $prefix)
Set the table prefix in use by the connection.
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/5.3/Illuminate/Database/Connection.html