interface ConnectionInterface (View source)

Defines the lifecycle, execution, escaping, and atomic transaction operations of one database connection.

Methods

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

Executes a result query with bound parameters and materializes its associative rows.

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

Streams a result query while retaining connection ownership until the generator is exhausted.

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

Executes a data-changing statement and returns its affected row count.

int
void

Begins a physical transaction when the connection supports it.

void
void
commit()

Commits the active physical transaction.

void
void

Rolls back the active physical transaction.

void
bool

Indicates whether a physical transaction is currently active on this connection.

bool
mixed
transaction(callable $callback)

Executes the callback atomically. A call made while this connection already has an active transaction reuses that outer transaction; it must not issue a second physical BEGIN.

mixed
int|string|null

Returns the identifier generated by the most recent insert when the driver exposes one.

int|string|null
int

Returns the affected-row count reported by the most recently executed statement.

int
void

Re-establishes the physical connection after a recoverable disconnect.

void
void
close()

Releases the physical connection and associated driver resources.

void
string

Returns the server version reported by the active database engine.

string
string
escapeString(string $value)

Escapes a string literal according to the active connection's SQL dialect.

string

Details

select

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

Executes a result query with bound parameters and materializes its associative rows.

Parameters

string $sql
array $bindings

Return Value

array

cursor

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

Streams a result query while retaining connection ownership until the generator is exhausted.

Parameters

string $sql
array $bindings

Return Value

Generator

statement

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

Executes a data-changing statement and returns its affected row count.

Parameters

string $sql
array $bindings

Return Value

int

beginTransaction

void beginTransaction()

Begins a physical transaction when the connection supports it.

Return Value

void

commit

void commit()

Commits the active physical transaction.

Return Value

void

rollBack

void rollBack()

Rolls back the active physical transaction.

Return Value

void

inTransaction

bool inTransaction()

Indicates whether a physical transaction is currently active on this connection.

Return Value

bool

transaction

mixed transaction(callable $callback)

Executes the callback atomically. A call made while this connection already has an active transaction reuses that outer transaction; it must not issue a second physical BEGIN.

Parameters

callable $callback

Return Value

mixed

lastInsertId

int|string|null lastInsertId()

Returns the identifier generated by the most recent insert when the driver exposes one.

Return Value

int|string|null

affectedRows

int affectedRows()

Returns the affected-row count reported by the most recently executed statement.

Return Value

int

reconnect

void reconnect()

Re-establishes the physical connection after a recoverable disconnect.

Return Value

void

close

void close()

Releases the physical connection and associated driver resources.

Return Value

void

serverVersion

string serverVersion()

Returns the server version reported by the active database engine.

Return Value

string

escapeString

string escapeString(string $value)

Escapes a string literal according to the active connection's SQL dialect.

Parameters

string $value

Return Value

string