class Connection implements ConnectionInterface (View source)

Traits

Methods

void
__construct(PDO|Closure $pdo, string $database = '', string $tablePrefix = '', array $config = array())

Create a new database connection instance.

void
useDefaultQueryGrammar()

Set the query grammar to the default implementation.

void
useDefaultSchemaGrammar()

Set the schema grammar to the default implementation.

void
useDefaultPostProcessor()

Set the query post processor to the default implementation.

getSchemaBuilder()

Get a schema builder instance for the connection.

table(string $table)

Begin a fluent query against a database table.

query()

Get a new query builder instance.

raw(mixed $value)

Get a new raw query expression.

mixed
selectOne(string $query, array $bindings = array(), bool $useReadPdo = true)

Run a select statement and return a single result.

array
selectFromWriteConnection(string $query, array $bindings = array())

Run a select statement against the database.

array
select(string $query, array $bindings = array(), bool $useReadPdo = true)

Run a select statement against the database.

cursor(string $query, array $bindings = array(), 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.

bool
insert(string $query, array $bindings = array())

Run an insert statement against the database.

int
update(string $query, array $bindings = array())

Run an update statement against the database.

int
delete(string $query, array $bindings = array())

Run a delete statement against the database.

bool
statement(string $query, array $bindings = array())

Execute an SQL statement and return the boolean result.

int
affectingStatement(string $query, array $bindings = array())

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.

void
disconnect()

Disconnect from the underlying PDO connection.

void
reconnect()

Reconnect to the database.

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.

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.

getQueryGrammar()

Get the query grammar used by the connection.

void
setQueryGrammar(Grammar $grammar)

Set the query grammar used by the connection.

getSchemaGrammar()

Get the schema grammar used by the connection.

void
setSchemaGrammar(Grammar $grammar)

Set the schema grammar used by the connection.

getPostProcessor()

Get the query post processor used by the connection.

void
setPostProcessor(Processor $processor)

Set the query post processor used by the connection.

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 = array())

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.

withTablePrefix(Grammar $grammar)

Set the table prefix and return the grammar.

Details

at line line 159
void __construct(PDO|Closure $pdo, string $database = '', string $tablePrefix = '', array $config = array())

Create a new database connection instance.

Parameters

PDO|Closure $pdo
string $database
string $tablePrefix
array $config

Return Value

void

at line line 185
void useDefaultQueryGrammar()

Set the query grammar to the default implementation.

Return Value

void

at line line 205
void useDefaultSchemaGrammar()

Set the schema grammar to the default implementation.

Return Value

void

at line line 225
void useDefaultPostProcessor()

Set the query post processor to the default implementation.

Return Value

void

at line line 245
Builder getSchemaBuilder()

Get a schema builder instance for the connection.

Return Value

Builder

at line line 260
Builder table(string $table)

Begin a fluent query against a database table.

Parameters

string $table

Return Value

Builder

at line line 270
Builder query()

Get a new query builder instance.

Return Value

Builder

at line line 283
Expression raw(mixed $value)

Get a new raw query expression.

Parameters

mixed $value

Return Value

Expression

at line line 296
mixed selectOne(string $query, array $bindings = array(), bool $useReadPdo = true)

Run a select statement and return a single result.

Parameters

string $query
array $bindings
bool $useReadPdo

Return Value

mixed

at line line 310
array selectFromWriteConnection(string $query, array $bindings = array())

Run a select statement against the database.

Parameters

string $query
array $bindings

Return Value

array

at line line 323
array select(string $query, array $bindings = array(), bool $useReadPdo = true)

Run a select statement against the database.

Parameters

string $query
array $bindings
bool $useReadPdo

Return Value

array

at line line 362
Generator cursor(string $query, array $bindings = array(), bool $useReadPdo = true)

Run a select statement against the database and returns a generator.

Parameters

string $query
array $bindings
bool $useReadPdo

Return Value

Generator

at line line 405
void bindValues(PDOStatement $statement, array $bindings)

Bind values to their parameters in the given statement.

Parameters

PDOStatement $statement
array $bindings

Return Value

void

at line line 433
bool insert(string $query, array $bindings = array())

Run an insert statement against the database.

Parameters

string $query
array $bindings

Return Value

bool

at line line 445
int update(string $query, array $bindings = array())

Run an update statement against the database.

Parameters

string $query
array $bindings

Return Value

int

at line line 457
int delete(string $query, array $bindings = array())

Run a delete statement against the database.

Parameters

string $query
array $bindings

Return Value

int

at line line 469
bool statement(string $query, array $bindings = array())

Execute an SQL statement and return the boolean result.

Parameters

string $query
array $bindings

Return Value

bool

at line line 491
int affectingStatement(string $query, array $bindings = array())

Run an SQL statement and get the number of rows affected.

Parameters

string $query
array $bindings

Return Value

int

at line line 517
bool unprepared(string $query)

Run a raw, unprepared query against the PDO connection.

Parameters

string $query

Return Value

bool

at line line 534
array prepareBindings(array $bindings)

Prepare the query bindings for execution.

Parameters

array $bindings

Return Value

array

at line line 561
mixed transaction(Closure $callback, int $attempts = 1)

Execute a Closure within a transaction.

Parameters

Closure $callback
int $attempts

Return Value

mixed

Exceptions

Throwable

at line line 608
void beginTransaction()

Start a new database transaction.

Return Value

void

Exceptions

Exception

at line line 637
void commit()

Commit the active database transaction.

Return Value

void

at line line 653
void rollBack()

Rollback the active database transaction.

Return Value

void

at line line 673
int transactionLevel()

Get the number of active transactions.

Return Value

int

at line line 684
array pretend(Closure $callback)

Execute the given callback in "dry run" mode.

Parameters

Closure $callback

Return Value

array

at line line 805
void disconnect()

Disconnect from the underlying PDO connection.

Return Value

void

at line line 817
void reconnect()

Reconnect to the database.

Return Value

void

Exceptions

LogicException

at line line 846
void logQuery(string $query, array $bindings, float|null $time = null)

Log a query in the connection's query log.

Parameters

string $query
array $bindings
float|null $time

Return Value

void

at line line 865
void listen(Closure $callback)

Register a database query listener with the connection.

Parameters

Closure $callback

Return Value

void

at line line 910
bool isDoctrineAvailable()

Is Doctrine available?

Return Value

bool

at line line 922
Column getDoctrineColumn(string $table, string $column)

Get a Doctrine Schema Column instance.

Parameters

string $table
string $column

Return Value

Column

at line line 934
AbstractSchemaManager getDoctrineSchemaManager()

Get the Doctrine DBAL schema manager for the connection.

Return Value

AbstractSchemaManager

at line line 944
Connection getDoctrineConnection()

Get the Doctrine DBAL database connection instance.

Return Value

Connection

at line line 962
PDO getPdo()

Get the current PDO connection.

Return Value

PDO

at line line 976
PDO getReadPdo()

Get the current PDO connection used for reading.

Return Value

PDO

at line line 995
$this setPdo(PDO|null $pdo)

Set the PDO connection.

Parameters

PDO|null $pdo

Return Value

$this

at line line 1010
$this setReadPdo(PDO|null $pdo)

Set the PDO connection used for reading.

Parameters

PDO|null $pdo

Return Value

$this

at line line 1023
$this setReconnector(callable $reconnector)

Set the reconnect instance on the connection.

Parameters

callable $reconnector

Return Value

$this

at line line 1035
string|null getName()

Get the database connection name.

Return Value

string|null

at line line 1046
mixed getConfig(string $option)

Get an option from the configuration options.

Parameters

string $option

Return Value

mixed

at line line 1056
string getDriverName()

Get the PDO driver name.

Return Value

string

at line line 1066
Grammar getQueryGrammar()

Get the query grammar used by the connection.

Return Value

Grammar

at line line 1077
void setQueryGrammar(Grammar $grammar)

Set the query grammar used by the connection.

Parameters

Grammar $grammar

Return Value

void

at line line 1087
Grammar getSchemaGrammar()

Get the schema grammar used by the connection.

Return Value

Grammar

at line line 1098
void setSchemaGrammar(Grammar $grammar)

Set the schema grammar used by the connection.

Parameters

Grammar $grammar

Return Value

void

at line line 1108
Processor getPostProcessor()

Get the query post processor used by the connection.

Return Value

Processor

at line line 1119
void setPostProcessor(Processor $processor)

Set the query post processor used by the connection.

Parameters

Processor $processor

Return Value

void

at line line 1129
Dispatcher getEventDispatcher()

Get the event dispatcher used by the connection.

Return Value

Dispatcher

at line line 1140
void setEventDispatcher(Dispatcher $events)

Set the event dispatcher instance on the connection.

Parameters

Dispatcher $events

Return Value

void

at line line 1150
bool pretending()

Determine if the connection in a "dry run".

Return Value

bool

at line line 1160
int getFetchMode()

Get the default fetch mode for the connection.

Return Value

int

at line line 1170
mixed getFetchArgument()

Get the fetch argument to be applied when selecting.

Return Value

mixed

at line line 1180
array getFetchConstructorArgument()

Get custom constructor arguments for the PDO::FETCH_CLASS fetch mode.

Return Value

array

at line line 1193
int setFetchMode(int $fetchMode, mixed $fetchArgument = null, array $fetchConstructorArgument = array())

Set the default fetch mode for the connection, and optional arguments for the given fetch mode.

Parameters

int $fetchMode
mixed $fetchArgument
array $fetchConstructorArgument

Return Value

int

at line line 1205
array getQueryLog()

Get the connection query log.

Return Value

array

at line line 1215
void flushQueryLog()

Clear the query log.

Return Value

void

at line line 1225
void enableQueryLog()

Enable the query log on the connection.

Return Value

void

at line line 1235
void disableQueryLog()

Disable the query log on the connection.

Return Value

void

at line line 1245
bool logging()

Determine whether we're logging queries.

Return Value

bool

at line line 1255
string getDatabaseName()

Get the name of the connected database.

Return Value

string

at line line 1266
string setDatabaseName(string $database)

Set the name of the connected database.

Parameters

string $database

Return Value

string

at line line 1276
string getTablePrefix()

Get the table prefix for the connection.

Return Value

string

at line line 1287
void setTablePrefix(string $prefix)

Set the table prefix in use by the connection.

Parameters

string $prefix

Return Value

void

at line line 1300
Grammar withTablePrefix(Grammar $grammar)

Set the table prefix and return the grammar.

Parameters

Grammar $grammar

Return Value

Grammar