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.

array
select(string $sql, array $bindings = [])

Reads the complete result set as associative rows using bound values rather than interpolation.

array
int
statement(string $sql, array $bindings = [])

Executes a non-result statement and reports the driver's affected row count.

int
cursor(string $sql, array $bindings = [])

Streams rows without materializing the result set; callers must consume the generator before reusing the connection.

mixed
transaction(callable $callback)

Runs a callback in the connection transaction boundary and invokes queued after-commit callbacks only after the outer commit.

mixed
void
afterCommit(callable $callback)

Schedules a side effect after a Database-owned outer transaction commits, or executes it immediately.

void
int|string|null

Retrieves the requested value without changing the current database state.

int|string|null
int

Provides this part of the database contract while preserving the object's current state and driver semantics.

int
void

Provides this part of the database contract while preserving the object's current state and driver semantics.

void
void
close()

Releases resources retained by this database object so they cannot be reused.

void
string

Provides this part of the database contract while preserving the object's current state and driver semantics.

string
string
escapeString(string $value)

Escapes the supplied value or identifier for safe inclusion in driver-generated SQL.

string
bool
tableExists(string $table)

Determines whether a table is available in the current database schema.

bool
table(string $table)

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.

Parameters

ConnectionInterface $connection
DatabaseDriverInterface $driver

connection

Returns the underlying connection for integrations that require connection-level operations.

Return Value

ConnectionInterface

select

array select(string $sql, array $bindings = [])

Reads the complete result set as associative rows using bound values rather than interpolation.

Parameters

string $sql
array $bindings

Return Value

array

statement

int statement(string $sql, array $bindings = [])

Executes a non-result statement and reports the driver's affected row count.

Parameters

string $sql
array $bindings

Return Value

int

cursor

Generator cursor(string $sql, array $bindings = [])

Streams rows without materializing the result set; callers must consume the generator before reusing the connection.

Parameters

string $sql
array $bindings

Return Value

Generator

transaction

mixed transaction(callable $callback)

Runs a callback in the connection transaction boundary and invokes queued after-commit callbacks only after the outer commit.

Parameters

callable $callback

Return Value

mixed

afterCommit

void afterCommit(callable $callback)

Schedules a side effect after a Database-owned outer transaction commits, or executes it immediately.

Parameters

callable $callback

Return Value

void

lastInsertId

int|string|null lastInsertId()

Retrieves the requested value without changing the current database state.

Return Value

int|string|null

affectedRows

int affectedRows()

Provides this part of the database contract while preserving the object's current state and driver semantics.

Return Value

int

reconnect

void reconnect()

Provides this part of the database contract while preserving the object's current state and driver semantics.

Return Value

void

close

void close()

Releases resources retained by this database object so they cannot be reused.

Return Value

void

serverVersion

string serverVersion()

Provides this part of the database contract while preserving the object's current state and driver semantics.

Return Value

string

escapeString

string escapeString(string $value)

Escapes the supplied value or identifier for safe inclusion in driver-generated SQL.

Parameters

string $value

Return Value

string

tableExists

bool tableExists(string $table)

Determines whether a table is available in the current database schema.

Parameters

string $table

Return Value

bool

table

QueryBuilder table(string $table)

Starts an immutable query builder scoped to a validated table identifier.

Parameters

string $table

Return Value

QueryBuilder