final class MysqlConnection implements ConnectionInterface, MysqlConnectionInterface (View source)

Owns a lazily connected MySQLi session, parameter binding, transaction state, and optional database instrumentation.

Methods

__construct(DatabaseConfig $config, DatabaseInstrumentation $instrumentation = new DatabaseInstrumentation())

Creates a lazy MySQLi adapter from normalized connection settings and shared optional database instrumentation.

mysqli
mysqli()

Returns the live MySQLi handle, creating and configuring it only on first use.

mysqli
execute(string $sql, array $bindings = [])

Executes SQL directly or as a prepared statement and records its timing and write metadata.

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

Materializes a result-producing query and releases its native result buffer afterwards.

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

Streams rows from a native result buffer and always frees it when iteration finishes.

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

Executes a statement and returns the affected-row count captured by execute().

int
void

Begins a physical MySQL transaction and records it as active for nested transaction users.

void
void
commit()

Commits the active MySQL transaction and clears local transaction state.

void
void

Rolls back the active MySQL transaction and clears local transaction state.

void
bool

Reports whether this adapter currently owns an active physical MySQL transaction.

bool
mixed
transaction(callable $callback)

Executes a callback atomically, reusing an existing transaction rather than opening a nested physical one.

mixed
int|string|null

Returns the latest auto-generated identifier reported by the MySQLi handle.

int|string|null
int

Returns the affected-row count captured by the latest execution through this adapter.

int
void

Verifies the existing handle or replaces it after a failed ping.

void
void
close()

Closes the live MySQLi handle and clears local connection and transaction state.

void
string

Returns the server version from the current MySQLi handle.

string
bool
setCharset(string $charset)

Requests a connection character set from MySQLi.

bool
string
escapeString(string $value)

Escapes a value for a MySQL string literal without surrounding quotes.

string
void
selectDatabase(string $database)

Selects a database and translates MySQLi failures to the framework connection exception.

void
array
listTables(bool $prefixLimit = false)

Lists tables in the configured database and can constrain the result to the configured prefix.

array
array
listColumns(string $table)

Lists column names through MySQL SHOW COLUMNS metadata.

array
array

Returns the latest native MySQLi error while tolerating an unopened connection.

array

Details

__construct

__construct(DatabaseConfig $config, DatabaseInstrumentation $instrumentation = new DatabaseInstrumentation())

Creates a lazy MySQLi adapter from normalized connection settings and shared optional database instrumentation.

Parameters

DatabaseConfig $config
DatabaseInstrumentation $instrumentation

mysqli

mysqli mysqli()

Returns the live MySQLi handle, creating and configuring it only on first use.

Return Value

mysqli

Exceptions

DatabaseException

execute

MysqlExecutionResult execute(string $sql, array $bindings = [])

Executes SQL directly or as a prepared statement and records its timing and write metadata.

Parameters

string $sql
array $bindings

Return Value

MysqlExecutionResult

select

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

Materializes a result-producing query and releases its native result buffer afterwards.

Parameters

string $sql
array $bindings

Return Value

array

cursor

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

Streams rows from a native result buffer and always frees it when iteration finishes.

Parameters

string $sql
array $bindings

Return Value

Generator

statement

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

Executes a statement and returns the affected-row count captured by execute().

Parameters

string $sql
array $bindings

Return Value

int

beginTransaction

void beginTransaction()

Begins a physical MySQL transaction and records it as active for nested transaction users.

Return Value

void

commit

void commit()

Commits the active MySQL transaction and clears local transaction state.

Return Value

void

rollBack

void rollBack()

Rolls back the active MySQL transaction and clears local transaction state.

Return Value

void

inTransaction

bool inTransaction()

Reports whether this adapter currently owns an active physical MySQL transaction.

Return Value

bool

transaction

mixed transaction(callable $callback)

Executes a callback atomically, reusing an existing transaction rather than opening a nested physical one.

Parameters

callable $callback

Return Value

mixed

lastInsertId

int|string|null lastInsertId()

Returns the latest auto-generated identifier reported by the MySQLi handle.

Return Value

int|string|null

affectedRows

int affectedRows()

Returns the affected-row count captured by the latest execution through this adapter.

Return Value

int

reconnect

void reconnect()

Verifies the existing handle or replaces it after a failed ping.

Return Value

void

close

void close()

Closes the live MySQLi handle and clears local connection and transaction state.

Return Value

void

serverVersion

string serverVersion()

Returns the server version from the current MySQLi handle.

Return Value

string

setCharset

bool setCharset(string $charset)

Requests a connection character set from MySQLi.

Parameters

string $charset

Return Value

bool

escapeString

string escapeString(string $value)

Escapes a value for a MySQL string literal without surrounding quotes.

Parameters

string $value

Return Value

string

selectDatabase

void selectDatabase(string $database)

Selects a database and translates MySQLi failures to the framework connection exception.

Parameters

string $database

Return Value

void

listTables

array listTables(bool $prefixLimit = false)

Lists tables in the configured database and can constrain the result to the configured prefix.

Parameters

bool $prefixLimit

Return Value

array

listColumns

array listColumns(string $table)

Lists column names through MySQL SHOW COLUMNS metadata.

Parameters

string $table

Return Value

array

lastError

array lastError()

Returns the latest native MySQLi error while tolerating an unopened connection.

Return Value

array