Methods |
public
|
__construct(PDO|Closure $pdo, string $database = '', string $tablePrefix = '', array $config = []): void
Create a new database connection instance.
Create a new database connection instance.
|
#
|
public
|
useDefaultQueryGrammar(): void
Set the query grammar to the default implementation.
Set the query grammar to the default implementation.
|
#
|
protected
|
getDefaultQueryGrammar(): Grammar
Get the default query grammar instance.
Get the default query grammar instance.
|
#
|
public
|
useDefaultSchemaGrammar(): void
Set the schema grammar to the default implementation.
Set the schema grammar to the default implementation.
|
#
|
protected
|
getDefaultSchemaGrammar(): Grammar|null
Get the default schema grammar instance.
Get the default schema grammar instance.
|
#
|
public
|
useDefaultPostProcessor(): void
Set the query post processor to the default implementation.
Set the query post processor to the default implementation.
|
#
|
protected
|
getDefaultPostProcessor(): Processor
Get the default post processor instance.
Get the default post processor instance.
|
#
|
public
|
getSchemaBuilder(): Builder
Get a schema builder instance for the connection.
Get a schema builder instance for the connection.
|
#
|
public
|
table(Closure|Builder|Expression|string $table, string|null $as = null): Builder
Begin a fluent query against a database table.
Begin a fluent query against a database table.
Implements
|
#
|
public
|
query(): Builder
Get a new query builder instance.
Get a new query builder instance.
|
#
|
public
|
selectOne(string $query, array $bindings = [], bool $useReadPdo = true): mixed
Run a select statement and return a single result.
Run a select statement and return a single result.
Implements
|
#
|
public
|
scalar(string $query, array $bindings = [], bool $useReadPdo = true): mixed
Run a select statement and return the first column of the first row.
Run a select statement and return the first column of the first row.
Throws
Implements
|
#
|
public
|
selectFromWriteConnection(string $query, array $bindings = []): array
Run a select statement against the database.
Run a select statement against the database.
|
#
|
public
|
select(string $query, array $bindings = [], bool $useReadPdo = true): array
Run a select statement against the database.
Run a select statement against the database.
Implements
|
#
|
public
|
selectResultSets(string $query, array $bindings = [], bool $useReadPdo = true): array
Run a select statement against the database and returns all of the result sets.
Run a select statement against the database and returns all of the result sets.
|
#
|
public
|
cursor(string $query, array $bindings = [], bool $useReadPdo = true): Generator<int, stdClass>
Run a select statement against the database and returns a generator.
Run a select statement against the database and returns a generator.
Implements
|
#
|
protected
|
prepared(PDOStatement $statement): PDOStatement
Configure the PDO prepared statement.
Configure the PDO prepared statement.
|
#
|
protected
|
getPdoForSelect(bool $useReadPdo = true): PDO
Get the PDO connection to use for a select query.
Get the PDO connection to use for a select query.
|
#
|
public
|
insert(string $query, array $bindings = []): bool
Run an insert statement against the database.
Run an insert statement against the database.
Implements
|
#
|
public
|
update(string $query, array $bindings = []): int
Run an update statement against the database.
Run an update statement against the database.
Implements
|
#
|
public
|
delete(string $query, array $bindings = []): int
Run a delete statement against the database.
Run a delete statement against the database.
Implements
|
#
|
public
|
statement(string $query, array $bindings = []): bool
Execute an SQL statement and return the boolean result.
Execute an SQL statement and return the boolean result.
Implements
|
#
|
public
|
affectingStatement(string $query, array $bindings = []): int
Run an SQL statement and get the number of rows affected.
Run an SQL statement and get the number of rows affected.
Implements
|
#
|
public
|
unprepared(string $query): bool
Run a raw, unprepared query against the PDO connection.
Run a raw, unprepared query against the PDO connection.
Implements
|
#
|
public
|
threadCount(): int|null
Get the number of open connections for the database.
Get the number of open connections for the database.
|
#
|
public
|
pretend(Closure $callback): array
Execute the given callback in "dry run" mode.
Execute the given callback in "dry run" mode.
Implements
|
#
|
public
|
withoutPretending(Closure $callback): mixed
Execute the given callback without "pretending".
Execute the given callback without "pretending".
|
#
|
protected
|
withFreshQueryLog(Closure $callback): array
Execute the given callback in "dry run" mode.
Execute the given callback in "dry run" mode.
|
#
|
public
|
bindValues(PDOStatement $statement, array $bindings): void
Bind values to their parameters in the given statement.
Bind values to their parameters in the given statement.
|
#
|
public
|
prepareBindings(array $bindings): array
Prepare the query bindings for execution.
Prepare the query bindings for execution.
Implements
|
#
|
protected
|
run(string $query, array $bindings, Closure $callback): mixed
Run a SQL statement and log its execution context.
Run a SQL statement and log its execution context.
Throws
|
#
|
protected
|
runQueryCallback(string $query, array $bindings, Closure $callback): mixed
Run a SQL statement.
|
#
|
protected
|
isUniqueConstraintError(Exception $exception): bool
Determine if the given database exception was caused by a unique constraint violation.
Determine if the given database exception was caused by a unique constraint violation.
|
#
|
public
|
logQuery(string $query, array $bindings, float|null $time = null): void
Log a query in the connection's query log.
Log a query in the connection's query log.
|
#
|
protected
|
getElapsedTime(float $start): float
Get the elapsed time since a given starting point.
Get the elapsed time since a given starting point.
|
#
|
public
|
whenQueryingForLongerThan(DateTimeInterface|CarbonInterval|float|int $threshold, callable $handler): void
Register a callback to be invoked when the connection queries for longer than a given amount of time.
Register a callback to be invoked when the connection queries for longer than a given amount of time.
|
#
|
public
|
allowQueryDurationHandlersToRunAgain(): void
Allow all the query duration handlers to run again, even if they have already run.
Allow all the query duration handlers to run again, even if they have already run.
|
#
|
public
|
totalQueryDuration(): float
Get the duration of all run queries in milliseconds.
Get the duration of all run queries in milliseconds.
|
#
|
public
|
resetTotalQueryDuration(): void
Reset the duration of all run queries.
Reset the duration of all run queries.
|
#
|
protected
|
handleQueryException(QueryException $e, string $query, array $bindings, Closure $callback): mixed
Handle a query exception.
Handle a query exception.
Throws
|
#
|
protected
|
tryAgainIfCausedByLostConnection(QueryException $e, string $query, array $bindings, Closure $callback): mixed
Handle a query exception that occurred during query execution.
Handle a query exception that occurred during query execution.
Throws
|
#
|
public
|
reconnect(): mixed|false
Reconnect to the database.
Reconnect to the database.
Throws
|
#
|
public
|
reconnectIfMissingConnection(): void
Reconnect to the database if a PDO connection is missing.
Reconnect to the database if a PDO connection is missing.
|
#
|
public
|
disconnect(): void
Disconnect from the underlying PDO connection.
Disconnect from the underlying PDO connection.
|
#
|
public
|
beforeStartingTransaction(Closure $callback): $this
Register a hook to be run just before a database transaction is started.
Register a hook to be run just before a database transaction is started.
|
#
|
public
|
beforeExecuting(Closure $callback): $this
Register a hook to be run just before a database query is executed.
Register a hook to be run just before a database query is executed.
|
#
|
public
|
listen(Closure $callback): void
Register a database query listener with the connection.
Register a database query listener with the connection.
|
#
|
protected
|
fireConnectionEvent(string $event): array|null
Fire an event for this connection.
Fire an event for this connection.
|
#
|
protected
|
event(mixed $event): void
Fire the given event if possible.
Fire the given event if possible.
|
#
|
public
|
raw(mixed $value): Expression
Get a new raw query expression.
Get a new raw query expression.
Implements
|
#
|
public
|
escape(string|float|int|bool|null $value, bool $binary = false): string
Escape a value for safe SQL embedding.
Escape a value for safe SQL embedding.
|
#
|
protected
|
escapeString(string $value): string
Escape a string value for safe SQL embedding.
Escape a string value for safe SQL embedding.
|
#
|
protected
|
escapeBool(bool $value): string
Escape a boolean value for safe SQL embedding.
Escape a boolean value for safe SQL embedding.
|
#
|
protected
|
escapeBinary(string $value): string
Escape a binary value for safe SQL embedding.
Escape a binary value for safe SQL embedding.
|
#
|
public
|
hasModifiedRecords(): bool
Determine if the database connection has modified any database records.
Determine if the database connection has modified any database records.
|
#
|
public
|
recordsHaveBeenModified(bool $value = true): void
Indicate if any records have been modified.
Indicate if any records have been modified.
|
#
|
public
|
setRecordModificationState(bool $value): $this
Set the record modification state.
Set the record modification state.
|
#
|
public
|
forgetRecordModificationState(): void
Reset the record modification state.
Reset the record modification state.
|
#
|
public
|
useWriteConnectionWhenReading(bool $value = true): $this
Indicate that the connection should use the write PDO connection for reads.
Indicate that the connection should use the write PDO connection for reads.
|
#
|
public
|
getPdo(): PDO
Get the current PDO connection.
Get the current PDO connection.
|
#
|
public
|
getRawPdo(): PDO|Closure|null
Get the current PDO connection parameter without executing any reconnect logic.
Get the current PDO connection parameter without executing any reconnect logic.
|
#
|
public
|
getReadPdo(): PDO
Get the current PDO connection used for reading.
Get the current PDO connection used for reading.
|
#
|
public
|
getRawReadPdo(): PDO|Closure|null
Get the current read PDO connection parameter without executing any reconnect logic.
Get the current read PDO connection parameter without executing any reconnect logic.
|
#
|
public
|
setPdo(PDO|Closure|null $pdo): $this
Set the PDO connection.
|
#
|
public
|
setReadPdo(PDO|Closure|null $pdo): $this
Set the PDO connection used for reading.
Set the PDO connection used for reading.
|
#
|
public
|
setReconnector(callable $reconnector): $this
Set the reconnect instance on the connection.
Set the reconnect instance on the connection.
|
#
|
public
|
getName(): string|null
Get the database connection name.
Get the database connection name.
|
#
|
public
|
getNameWithReadWriteType(): string|null
Get the database connection full name.
Get the database connection full name.
|
#
|
public
|
getConfig(string|null $option = null): mixed
Get an option from the configuration options.
Get an option from the configuration options.
|
#
|
public
|
getDriverName(): string
Get the PDO driver name.
|
#
|
public
|
getDriverTitle(): string
Get a human-readable name for the given connection driver.
Get a human-readable name for the given connection driver.
|
#
|
public
|
getQueryGrammar(): Grammar
Get the query grammar used by the connection.
Get the query grammar used by the connection.
|
#
|
public
|
setQueryGrammar(Grammar $grammar): $this
Set the query grammar used by the connection.
Set the query grammar used by the connection.
|
#
|
public
|
getSchemaGrammar(): Grammar
Get the schema grammar used by the connection.
Get the schema grammar used by the connection.
|
#
|
public
|
setSchemaGrammar(Grammar $grammar): $this
Set the schema grammar used by the connection.
Set the schema grammar used by the connection.
|
#
|
public
|
getPostProcessor(): Processor
Get the query post processor used by the connection.
Get the query post processor used by the connection.
|
#
|
public
|
setPostProcessor(Processor $processor): $this
Set the query post processor used by the connection.
Set the query post processor used by the connection.
|
#
|
public
|
getEventDispatcher(): Dispatcher
Get the event dispatcher used by the connection.
Get the event dispatcher used by the connection.
|
#
|
public
|
setEventDispatcher(Dispatcher $events): $this
Set the event dispatcher instance on the connection.
Set the event dispatcher instance on the connection.
|
#
|
public
|
unsetEventDispatcher(): void
Unset the event dispatcher for this connection.
Unset the event dispatcher for this connection.
|
#
|
public
|
setTransactionManager(DatabaseTransactionsManager $manager): $this
Set the transaction manager instance on the connection.
Set the transaction manager instance on the connection.
|
#
|
public
|
unsetTransactionManager(): void
Unset the transaction manager for this connection.
Unset the transaction manager for this connection.
|
#
|
public
|
pretending(): bool
Determine if the connection is in a "dry run".
Determine if the connection is in a "dry run".
|
#
|
public
|
getQueryLog(): array
Get the connection query log.
Get the connection query log.
|
#
|
public
|
getRawQueryLog(): array
Get the connection query log with embedded bindings.
Get the connection query log with embedded bindings.
|
#
|
public
|
flushQueryLog(): void
Clear the query log.
|
#
|
public
|
enableQueryLog(): void
Enable the query log on the connection.
Enable the query log on the connection.
|
#
|
public
|
disableQueryLog(): void
Disable the query log on the connection.
Disable the query log on the connection.
|
#
|
public
|
logging(): bool
Determine whether we're logging queries.
Determine whether we're logging queries.
|
#
|
public
|
getDatabaseName(): string
Get the name of the connected database.
Get the name of the connected database.
Implements
|
#
|
public
|
setDatabaseName(string $database): $this
Set the name of the connected database.
Set the name of the connected database.
|
#
|
public
|
setReadWriteType(string|null $readWriteType): $this
Set the read / write type of the connection.
Set the read / write type of the connection.
|
#
|
public
|
getTablePrefix(): string
Get the table prefix for the connection.
Get the table prefix for the connection.
|
#
|
public
|
setTablePrefix(string $prefix): $this
Set the table prefix in use by the connection.
Set the table prefix in use by the connection.
|
#
|
public
|
withoutTablePrefix(Closure $callback): mixed
Execute the given callback without table prefix.
Execute the given callback without table prefix.
|
#
|
public
|
getServerVersion(): string
Get the server version for the connection.
Get the server version for the connection.
|
#
|
public
static
|
resolverFor(string $driver, Closure $callback): void
Register a connection resolver.
Register a connection resolver.
|
#
|
public
static
|
getResolver(string $driver): Closure|null
Get the connection resolver for the given driver.
Get the connection resolver for the given driver.
|
#
|