Database
final class Database (View source)
Provides database operations and driver capabilities to framework consumers.
Methods
Creates a facade over the selected connection and its SQL driver capabilities.
Returns the underlying connection for integrations that require connection-level operations.
Reads the complete result set as associative rows using bound values rather than interpolation.
Executes a non-result statement and reports the driver's affected row count.
Streams rows without materializing the result set; callers must consume the generator before reusing the connection.
Runs a callback in the connection transaction boundary and invokes queued after-commit callbacks only after the outer commit.
Schedules a side effect after a Database-owned outer transaction commits, or executes it immediately.
Retrieves the requested value without changing the current database state.
Provides this part of the database contract while preserving the object's current state and driver semantics.
Provides this part of the database contract while preserving the object's current state and driver semantics.
Releases resources retained by this database object so they cannot be reused.
Provides this part of the database contract while preserving the object's current state and driver semantics.
Escapes the supplied value or identifier for safe inclusion in driver-generated SQL.
Determines whether a table is available in the current database schema.
Starts an immutable query builder scoped to a validated table identifier.
Details
__construct
__construct(ConnectionInterface $connection, DatabaseDriverInterface $driver)
Creates a facade over the selected connection and its SQL driver capabilities.
connection
ConnectionInterface
connection()
Returns the underlying connection for integrations that require connection-level operations.
select
array
select(string $sql, array $bindings = [])
Reads the complete result set as associative rows using bound values rather than interpolation.
statement
int
statement(string $sql, array $bindings = [])
Executes a non-result statement and reports the driver's affected row count.
cursor
Generator
cursor(string $sql, array $bindings = [])
Streams rows without materializing the result set; callers must consume the generator before reusing the connection.
transaction
mixed
transaction(callable $callback)
Runs a callback in the connection transaction boundary and invokes queued after-commit callbacks only after the outer commit.
afterCommit
void
afterCommit(callable $callback)
Schedules a side effect after a Database-owned outer transaction commits, or executes it immediately.
lastInsertId
int|string|null
lastInsertId()
Retrieves the requested value without changing the current database state.
affectedRows
int
affectedRows()
Provides this part of the database contract while preserving the object's current state and driver semantics.
reconnect
void
reconnect()
Provides this part of the database contract while preserving the object's current state and driver semantics.
close
void
close()
Releases resources retained by this database object so they cannot be reused.
serverVersion
string
serverVersion()
Provides this part of the database contract while preserving the object's current state and driver semantics.
escapeString
string
escapeString(string $value)
Escapes the supplied value or identifier for safe inclusion in driver-generated SQL.
tableExists
bool
tableExists(string $table)
Determines whether a table is available in the current database schema.
table
QueryBuilder
table(string $table)
Starts an immutable query builder scoped to a validated table identifier.