Connection
Implements
Uses
Properties
$database string
The name of the connected database.
$readWriteType string|null
The type of the connection.
$tablePrefix string
The table prefix for the connection.
$config array
The database connection configuration options.
$reconnector callable
The reconnector instance for the connection.
$fetchMode int
The default fetch mode of the connection.
$transactions int
The number of active transactions.
$transactionsManager DatabaseTransactionsManager
The transaction manager instance.
$recordsModified bool
Indicates if changes have been made to the database.
$readOnWriteConnection bool
Indicates if the connection should use the "write" PDO connection.
$queryLog array
All of the queries run against the connection.
$loggingQueries bool
Indicates whether queries are being logged.
$totalQueryDuration float
The duration of all executed queries in milliseconds.
$queryDurationHandlers array
All of the registered query duration handlers.
$pretending bool
Indicates if the connection is in a "dry run".
$beforeExecutingCallbacks Closure[]
All of the callbacks that should be invoked before a query is executed.
$doctrineConnection Doctrine\...\Connection
The instance of Doctrine connection.
$doctrineTypeMappings
array
Type mappings that should be registered with new Doctrine connections.
$resolvers Closure[]
The connection resolvers.
Methods
__construct ( $pdo , $database , $tablePrefix , array $config ) : void
Create a new database connection instance.
Parameters
useDefaultQueryGrammar ( ) : void
Set the query grammar to the default implementation.
useDefaultSchemaGrammar ( ) : void
Set the schema grammar to the default implementation.
useDefaultPostProcessor ( ) : void
Set the query post processor to the default implementation.
table ( $table , $as ) : Builder
Begin a fluent query against a database table.
Parameters
- $table Closure |Builder |Expression |string
- $as string|null
selectOne ( $query , $bindings , $useReadPdo ) : mixed
Run a select statement and return a single result.
Parameters
- $query string
- $bindings array
- $useReadPdo bool
scalar ( $query , $bindings , $useReadPdo ) : mixed
Run a select statement and return the first column of the first row.
Parameters
- $query string
- $bindings array
- $useReadPdo bool
selectFromWriteConnection ( $query , $bindings ) : array
Run a select statement against the database.
Parameters
- $query string
- $bindings array
select ( $query , $bindings , $useReadPdo ) : array
Run a select statement against the database.
Parameters
- $query string
- $bindings array
- $useReadPdo bool
selectResultSets ( $query , $bindings , $useReadPdo ) : array
Run a select statement against the database and returns all of the result sets.
Parameters
- $query string
- $bindings array
- $useReadPdo bool
cursor ( $query , $bindings , $useReadPdo ) : Generator
Run a select statement against the database and returns a generator.
Parameters
- $query string
- $bindings array
- $useReadPdo bool
prepared ( PDOStatement $statement ) : PDOStatement
Configure the PDO prepared statement.
Parameters
- $statement PDOStatement
getPdoForSelect ( $useReadPdo ) : PDO
Get the PDO connection to use for a select query.
Parameters
- $useReadPdo bool
insert ( $query , $bindings ) : bool
Run an insert statement against the database.
Parameters
- $query string
- $bindings array
update ( $query , $bindings ) : int
Run an update statement against the database.
Parameters
- $query string
- $bindings array
delete ( $query , $bindings ) : int
Run a delete statement against the database.
Parameters
- $query string
- $bindings array
statement ( $query , $bindings ) : bool
Execute an SQL statement and return the boolean result.
Parameters
- $query string
- $bindings array
affectingStatement ( $query , $bindings ) : int
Run an SQL statement and get the number of rows affected.
Parameters
- $query string
- $bindings array
unprepared ( $query ) : bool
Run a raw, unprepared query against the PDO connection.
Parameters
- $query string
pretend ( Closure $callback ) : array
Execute the given callback in "dry run" mode.
Parameters
- $callback Closure
withFreshQueryLog ( $callback ) : array
Execute the given callback in "dry run" mode.
Parameters
- $callback Closure
bindValues ( $statement , $bindings ) : void
Bind values to their parameters in the given statement.
Parameters
- $statement PDOStatement
- $bindings array
prepareBindings ( array $bindings ) : array
Prepare the query bindings for execution.
Parameters
- $bindings array
run ( $query , $bindings , Closure $callback ) : mixed
Run a SQL statement and log its execution context.
Parameters
- $query string
- $bindings array
- $callback Closure
runQueryCallback ( $query , $bindings , Closure $callback ) : mixed
Run a SQL statement.
Parameters
- $query string
- $bindings array
- $callback Closure
logQuery ( $query , $bindings , $time ) : void
Log a query in the connection's query log.
Parameters
- $query string
- $bindings array
- $time float|null
getElapsedTime ( $start ) : float
Get the elapsed time since a given starting point.
Parameters
- $start int
whenQueryingForLongerThan ( $threshold , $handler ) : void
Register a callback to be invoked when the connection queries for longer than a given amount of time.
Parameters
- $threshold DateTimeInterface |Carbon\CarbonInterval|float|int
- $handler callable
allowQueryDurationHandlersToRunAgain ( ) : void
Allow all the query duration handlers to run again, even if they have already run.
totalQueryDuration ( ) : float
Get the duration of all run queries in milliseconds.
resetTotalQueryDuration ( ) : void
Reset the duration of all run queries.
handleQueryException ( QueryException $e , $query , $bindings , Closure $callback ) : mixed
Handle a query exception.
Parameters
- $e QueryException
- $query string
- $bindings array
- $callback Closure
tryAgainIfCausedByLostConnection ( QueryException $e , $query , $bindings , Closure $callback ) : mixed
Handle a query exception that occurred during query execution.
Parameters
- $e QueryException
- $query string
- $bindings array
- $callback Closure
reconnect ( ) : mixed|false
Reconnect to the database.
reconnectIfMissingConnection ( ) : void
Reconnect to the database if a PDO connection is missing.
disconnect ( ) : void
Disconnect from the underlying PDO connection.
beforeExecuting ( Closure $callback ) : $this
Register a hook to be run just before a database query is executed.
Parameters
- $callback Closure
listen ( Closure $callback ) : void
Register a database query listener with the connection.
Parameters
- $callback Closure
fireConnectionEvent ( $event ) : array|null
Fire an event for this connection.
Parameters
- $event string
event ( $event ) : void
Fire the given event if possible.
Parameters
- $event mixed
escape ( $value , $binary ) : string
Escape a value for safe SQL embedding.
Parameters
- $value string|float|int|bool|null
- $binary bool
escapeString ( $value ) : string
Escape a string value for safe SQL embedding.
Parameters
- $value string
escapeBool ( $value ) : string
Escape a boolean value for safe SQL embedding.
Parameters
- $value bool
escapeBinary ( $value ) : string
Escape a binary value for safe SQL embedding.
Parameters
- $value string
hasModifiedRecords ( ) : bool
Determine if the database connection has modified any database records.
recordsHaveBeenModified ( $value ) : void
Indicate if any records have been modified.
Parameters
- $value bool
setRecordModificationState ( bool $value ) : $this
Set the record modification state.
Parameters
- $value bool
forgetRecordModificationState ( ) : void
Reset the record modification state.
useWriteConnectionWhenReading ( $value ) : $this
Indicate that the connection should use the write PDO connection for reads.
Parameters
- $value bool
isDoctrineAvailable ( ) : bool
Is Doctrine available?
usingNativeSchemaOperations ( ) : bool
Indicates whether native alter operations will be used when dropping, renaming, or modifying columns, even if Doctrine DBAL is installed.
getDoctrineColumn ( $table , $column ) : Doctrine\...\Column
Get a Doctrine Schema Column instance.
Parameters
- $table string
- $column string
getDoctrineSchemaManager ( ) : Doctrine\...\AbstractSchemaManager
Get the Doctrine DBAL schema manager for the connection.
getDoctrineConnection ( ) : Doctrine\...\Connection
Get the Doctrine DBAL database connection instance.
registerDoctrineType ( $class , string $name , string $type ) : void
Register a custom Doctrine mapping type.
Parameters
- $class Doctrine\...\Type|class-string<\Type>
- $name string
- $type string
getRawPdo ( ) : PDO |Closure |null
Get the current PDO connection parameter without executing any reconnect logic.
getRawReadPdo ( ) : PDO |Closure |null
Get the current read PDO connection parameter without executing any reconnect logic.
setReadPdo ( $pdo ) : $this
Set the PDO connection used for reading.
Parameters
setReconnector ( callable $reconnector ) : $this
Set the reconnect instance on the connection.
Parameters
- $reconnector callable
getName ( ) : string|null
Get the database connection name.
getNameWithReadWriteType ( ) : string|null
Get the database connection full name.
getConfig ( $option ) : mixed
Get an option from the configuration options.
Parameters
- $option string|null
getDriverName ( ) : string
Get the PDO driver name.
setQueryGrammar ( Grammar $grammar ) : $this
Set the query grammar used by the connection.
Parameters
- $grammar Grammar
setSchemaGrammar ( Grammar $grammar ) : $this
Set the schema grammar used by the connection.
Parameters
- $grammar Grammar
setPostProcessor ( Processor $processor ) : $this
Set the query post processor used by the connection.
Parameters
- $processor Processor
setEventDispatcher ( Dispatcher $events ) : $this
Set the event dispatcher instance on the connection.
Parameters
- $events Dispatcher
unsetEventDispatcher ( ) : void
Unset the event dispatcher for this connection.
setTransactionManager ( $manager ) : $this
Set the transaction manager instance on the connection.
Parameters
- $manager DatabaseTransactionsManager
unsetTransactionManager ( ) : void
Unset the transaction manager for this connection.
pretending ( ) : bool
Determine if the connection is in a "dry run".
getQueryLog ( ) : array
Get the connection query log.
getRawQueryLog ( ) : array
Get the connection query log with embedded bindings.
flushQueryLog ( ) : void
Clear the query log.
enableQueryLog ( ) : void
Enable the query log on the connection.
disableQueryLog ( ) : void
Disable the query log on the connection.
logging ( ) : bool
Determine whether we're logging queries.
getDatabaseName ( ) : string
Get the name of the connected database.
setDatabaseName ( $database ) : $this
Set the name of the connected database.
Parameters
- $database string
setReadWriteType ( $readWriteType ) : $this
Set the read / write type of the connection.
Parameters
- $readWriteType string|null
getTablePrefix ( ) : string
Get the table prefix for the connection.
setTablePrefix ( $prefix ) : $this
Set the table prefix in use by the connection.
Parameters
- $prefix string
withTablePrefix ( Grammar $grammar ) : Grammar
Set the table prefix and return the grammar.
Parameters
- $grammar Grammar
resolverFor ( $driver , Closure $callback ) : void
Register a connection resolver.
Parameters
- $driver string
- $callback Closure
getResolver ( $driver ) : mixed
Get the connection resolver for the given driver.
Parameters
- $driver string