SqlServerConnection
class SqlServerConnection extends Connection (View source)
Traits
DetectsConcurrencyErrors | |
DetectsLostConnections | |
ManagesTransactions |
Properties
protected PDO|Closure | $pdo | The active PDO connection. | from Connection |
protected PDO|Closure | $readPdo | The active PDO connection used for reads. | from Connection |
protected string | $database | The name of the connected database. | from Connection |
protected string | $tablePrefix | The table prefix for the connection. | from Connection |
protected array | $config | The database connection configuration options. | from Connection |
protected callable | $reconnector | The reconnector instance for the connection. | from Connection |
protected Grammar | $queryGrammar | The query grammar implementation. | from Connection |
protected Grammar | $schemaGrammar | The schema grammar implementation. | from Connection |
protected Processor | $postProcessor | The query post processor implementation. | from Connection |
protected Dispatcher | $events | The event dispatcher instance. | from Connection |
protected int | $fetchMode | The default fetch mode of the connection. | from Connection |
protected int | $transactions | The number of active transactions. | from Connection |
protected int | $recordsModified | Indicates if changes have been made to the database. | from Connection |
protected array | $queryLog | All of the queries run against the connection. | from Connection |
protected bool | $loggingQueries | Indicates whether queries are being logged. | from Connection |
protected bool | $pretending | Indicates if the connection is in a "dry run". | from Connection |
protected Connection | $doctrineConnection | The instance of Doctrine connection. | from Connection |
static protected array | $resolvers | The connection resolvers. | from Connection |
Methods
bool | causedByConcurrencyError(Throwable $e) Determine if the given exception was caused by a concurrency error such as a deadlock or serialization failure. | from DetectsConcurrencyErrors |
bool | causedByLostConnection(Throwable $e) Determine if the given exception was caused by a lost connection. | from DetectsLostConnections |
mixed | transaction(Closure $callback, int $attempts = 1) Execute a Closure within a transaction. | |
void | handleTransactionException(Throwable $e, int $currentAttempt, int $maxAttempts) Handle an exception encountered when running a transacted statement. | from ManagesTransactions |
void | beginTransaction() Start a new database transaction. | from ManagesTransactions |
void | createTransaction() Create a transaction within the database. | from ManagesTransactions |
void | createSavepoint() Create a save point within the database. | from ManagesTransactions |
void | handleBeginTransactionException(Throwable $e) Handle an exception from a transaction beginning. | from ManagesTransactions |
void | commit() Commit the active database transaction. | from ManagesTransactions |
void | handleCommitTransactionException(Throwable $e, int $currentAttempt, int $maxAttempts) Handle an exception encountered when committing a transaction. | from ManagesTransactions |
void | rollBack(int|null $toLevel = null) Rollback the active database transaction. | from ManagesTransactions |
void | performRollBack(int $toLevel) Perform a rollback within the database. | from ManagesTransactions |
void | handleRollBackException(Throwable $e) Handle an exception from a rollback. | from ManagesTransactions |
int | transactionLevel() Get the number of active transactions. | from ManagesTransactions |
void | __construct(PDO|Closure $pdo, string $database = '', string $tablePrefix = '', array $config = []) Create a new database connection instance. | from Connection |
void | useDefaultQueryGrammar() Set the query grammar to the default implementation. | from Connection |
Grammar | getDefaultQueryGrammar() Get the default query grammar instance. | |
void | useDefaultSchemaGrammar() Set the schema grammar to the default implementation. | from Connection |
Grammar | getDefaultSchemaGrammar() Get the default schema grammar instance. | |
void | useDefaultPostProcessor() Set the query post processor to the default implementation. | from Connection |
Processor | getDefaultPostProcessor() Get the default post processor instance. | |
Builder | getSchemaBuilder() Get a schema builder instance for the connection. | |
Builder | table(Closure|Builder|string $table, string|null $as = null) Begin a fluent query against a database table. | from Connection |
Builder | query() Get a new query builder instance. | from Connection |
mixed | selectOne(string $query, array $bindings = [], bool $useReadPdo = true) Run a select statement and return a single result. | from Connection |
array | selectFromWriteConnection(string $query, array $bindings = []) Run a select statement against the database. | from Connection |
array | select(string $query, array $bindings = [], bool $useReadPdo = true) Run a select statement against the database. | from Connection |
Generator | cursor(string $query, array $bindings = [], bool $useReadPdo = true) Run a select statement against the database and returns a generator. | from Connection |
PDOStatement | prepared(PDOStatement $statement) Configure the PDO prepared statement. | from Connection |
PDO | getPdoForSelect(bool $useReadPdo = true) Get the PDO connection to use for a select query. | from Connection |
bool | insert(string $query, array $bindings = []) Run an insert statement against the database. | from Connection |
int | update(string $query, array $bindings = []) Run an update statement against the database. | from Connection |
int | delete(string $query, array $bindings = []) Run a delete statement against the database. | from Connection |
bool | statement(string $query, array $bindings = []) Execute an SQL statement and return the boolean result. | from Connection |
int | affectingStatement(string $query, array $bindings = []) Run an SQL statement and get the number of rows affected. | from Connection |
bool | unprepared(string $query) Run a raw, unprepared query against the PDO connection. | from Connection |
array | pretend(Closure $callback) Execute the given callback in "dry run" mode. | from Connection |
array | withFreshQueryLog(Closure $callback) Execute the given callback in "dry run" mode. | from Connection |
void | bindValues(PDOStatement $statement, array $bindings) Bind values to their parameters in the given statement. | from Connection |
array | prepareBindings(array $bindings) Prepare the query bindings for execution. | from Connection |
mixed | run(string $query, array $bindings, Closure $callback) Run a SQL statement and log its execution context. | from Connection |
mixed | runQueryCallback(string $query, array $bindings, Closure $callback) Run a SQL statement. | from Connection |
void | logQuery(string $query, array $bindings, float|null $time = null) Log a query in the connection's query log. | from Connection |
float | getElapsedTime(int $start) Get the elapsed time since a given starting point. | from Connection |
mixed | handleQueryException(QueryException $e, string $query, array $bindings, Closure $callback) Handle a query exception. | from Connection |
mixed | tryAgainIfCausedByLostConnection(QueryException $e, string $query, array $bindings, Closure $callback) Handle a query exception that occurred during query execution. | from Connection |
void | reconnect() Reconnect to the database. | from Connection |
void | reconnectIfMissingConnection() Reconnect to the database if a PDO connection is missing. | from Connection |
void | disconnect() Disconnect from the underlying PDO connection. | from Connection |
void | listen(Closure $callback) Register a database query listener with the connection. | from Connection |
array|null | fireConnectionEvent(string $event) Fire an event for this connection. | from Connection |
void | event(mixed $event) Fire the given event if possible. | from Connection |
Expression | raw(mixed $value) Get a new raw query expression. | from Connection |
void | recordsHaveBeenModified(bool $value = true) Indicate if any records have been modified. | from Connection |
bool | isDoctrineAvailable() Is Doctrine available? | from Connection |
Column | getDoctrineColumn(string $table, string $column) Get a Doctrine Schema Column instance. | from Connection |
AbstractSchemaManager | getDoctrineSchemaManager() Get the Doctrine DBAL schema manager for the connection. | from Connection |
Connection | getDoctrineConnection() Get the Doctrine DBAL database connection instance. | from Connection |
PDO | getPdo() Get the current PDO connection. | from Connection |
PDO|Closure|null | getRawPdo() Get the current PDO connection parameter without executing any reconnect logic. | from Connection |
PDO | getReadPdo() Get the current PDO connection used for reading. | from Connection |
PDO|Closure|null | getRawReadPdo() Get the current read PDO connection parameter without executing any reconnect logic. | from Connection |
$this | setPdo(PDO|Closure|null $pdo) Set the PDO connection. | from Connection |
$this | setReadPdo(PDO|Closure|null $pdo) Set the PDO connection used for reading. | from Connection |
$this | setReconnector(callable $reconnector) Set the reconnect instance on the connection. | from Connection |
string|null | getName() Get the database connection name. | from Connection |
mixed | getConfig(string|null $option = null) Get an option from the configuration options. | from Connection |
string | getDriverName() Get the PDO driver name. | from Connection |
Grammar | getQueryGrammar() Get the query grammar used by the connection. | from Connection |
$this | setQueryGrammar(Grammar $grammar) Set the query grammar used by the connection. | from Connection |
Grammar | getSchemaGrammar() Get the schema grammar used by the connection. | from Connection |
$this | setSchemaGrammar(Grammar $grammar) Set the schema grammar used by the connection. | from Connection |
Processor | getPostProcessor() Get the query post processor used by the connection. | from Connection |
$this | setPostProcessor(Processor $processor) Set the query post processor used by the connection. | from Connection |
Dispatcher | getEventDispatcher() Get the event dispatcher used by the connection. | from Connection |
$this | setEventDispatcher(Dispatcher $events) Set the event dispatcher instance on the connection. | from Connection |
void | unsetEventDispatcher() Unset the event dispatcher for this connection. | from Connection |
bool | pretending() Determine if the connection is in a "dry run". | from Connection |
array | getQueryLog() Get the connection query log. | from Connection |
void | flushQueryLog() Clear the query log. | from Connection |
void | enableQueryLog() Enable the query log on the connection. | from Connection |
void | disableQueryLog() Disable the query log on the connection. | from Connection |
bool | logging() Determine whether we're logging queries. | from Connection |
string | getDatabaseName() Get the name of the connected database. | from Connection |
$this | setDatabaseName(string $database) Set the name of the connected database. | from Connection |
string | getTablePrefix() Get the table prefix for the connection. | from Connection |
$this | setTablePrefix(string $prefix) Set the table prefix in use by the connection. | from Connection |
Grammar | withTablePrefix(Grammar $grammar) Set the table prefix and return the grammar. | from Connection |
static void | resolverFor(string $driver, Closure $callback) Register a connection resolver. | from Connection |
static mixed | getResolver(string $driver) Get the connection resolver for the given driver. | from Connection |
Driver | getDoctrineDriver() Get the Doctrine DBAL driver. |
Details
protected bool causedByConcurrencyError(Throwable $e)
Determine if the given exception was caused by a concurrency error such as a deadlock or serialization failure.
protected bool causedByLostConnection(Throwable $e)
Determine if the given exception was caused by a lost connection.
mixed transaction(Closure $callback, int $attempts = 1)
Execute a Closure within a transaction.
protected void handleTransactionException(Throwable $e, int $currentAttempt, int $maxAttempts)
Handle an exception encountered when running a transacted statement.
void beginTransaction()
Start a new database transaction.
protected void createTransaction()
Create a transaction within the database.
protected void createSavepoint()
Create a save point within the database.
protected void handleBeginTransactionException(Throwable $e)
Handle an exception from a transaction beginning.
void commit()
Commit the active database transaction.
protected void handleCommitTransactionException(Throwable $e, int $currentAttempt, int $maxAttempts)
Handle an exception encountered when committing a transaction.
void rollBack(int|null $toLevel = null)
Rollback the active database transaction.
protected void performRollBack(int $toLevel)
Perform a rollback within the database.
protected void handleRollBackException(Throwable $e)
Handle an exception from a rollback.
int transactionLevel()
Get the number of active transactions.
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(Closure|Builder|string $table, string|null $as = null)
Begin a fluent query against a database table.
Builder query()
Get a new query builder instance.
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.
protected PDOStatement prepared(PDOStatement $statement)
Configure the PDO prepared 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 pretend(Closure $callback)
Execute the given callback in "dry run" mode.
protected array withFreshQueryLog(Closure $callback)
Execute the given callback in "dry run" mode.
void bindValues(PDOStatement $statement, array $bindings)
Bind values to their parameters in the given statement.
array prepareBindings(array $bindings)
Prepare the query bindings for execution.
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.
void logQuery(string $query, array $bindings, float|null $time = null)
Log a query in the connection's query log.
protected float getElapsedTime(int $start)
Get the elapsed time since a given starting point.
protected mixed handleQueryException(QueryException $e, string $query, array $bindings, Closure $callback)
Handle a query exception.
protected mixed tryAgainIfCausedByLostConnection(QueryException $e, string $query, array $bindings, Closure $callback)
Handle a query exception that occurred during query execution.
void reconnect()
Reconnect to the database.
protected void reconnectIfMissingConnection()
Reconnect to the database if a PDO connection is missing.
void disconnect()
Disconnect from the underlying PDO connection.
void listen(Closure $callback)
Register a database query listener with the connection.
protected array|null fireConnectionEvent(string $event)
Fire an event for this connection.
protected void event(mixed $event)
Fire the given event if possible.
Expression raw(mixed $value)
Get a new raw query expression.
void recordsHaveBeenModified(bool $value = true)
Indicate if any records have been modified.
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|Closure|null getRawPdo()
Get the current PDO connection parameter without executing any reconnect logic.
PDO getReadPdo()
Get the current PDO connection used for reading.
PDO|Closure|null getRawReadPdo()
Get the current read PDO connection parameter without executing any reconnect logic.
$this setReconnector(callable $reconnector)
Set the reconnect instance on the connection.
string|null getName()
Get the database connection name.
mixed getConfig(string|null $option = null)
Get an option from the configuration options.
string getDriverName()
Get the PDO driver name.
Grammar getQueryGrammar()
Get the query grammar used by the connection.
$this setQueryGrammar(Grammar $grammar)
Set the query grammar used by the connection.
Grammar getSchemaGrammar()
Get the schema grammar used by the connection.
$this setSchemaGrammar(Grammar $grammar)
Set the schema grammar used by the connection.
Processor getPostProcessor()
Get the query post processor used by the connection.
$this setPostProcessor(Processor $processor)
Set the query post processor used by the connection.
Dispatcher getEventDispatcher()
Get the event dispatcher used by the connection.
$this setEventDispatcher(Dispatcher $events)
Set the event dispatcher instance on the connection.
void unsetEventDispatcher()
Unset the event dispatcher for this connection.
bool pretending()
Determine if the connection is in a "dry run".
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.
$this setDatabaseName(string $database)
Set the name of the connected database.
string getTablePrefix()
Get the table prefix for the connection.
$this setTablePrefix(string $prefix)
Set the table prefix in use by the connection.
static void resolverFor(string $driver, Closure $callback)
Register a connection resolver.
static mixed getResolver(string $driver)
Get the connection resolver for the given driver.
protected Driver getDoctrineDriver()
Get the Doctrine DBAL driver.
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/7.x/Illuminate/Database/SqlServerConnection.html