Alpha ZealPHP is early-stage and under active development. APIs may change between minor versions until v1.0. Feedback and bug reports welcome on GitHub.
API Index — Namespaces, Packages, Reports, Indices

MysqliDriver
in package
implements PoolDriver

FinalYes

{@see PoolDriver} for \mysqli connections — for code that uses mysqli directly rather than PDO (WordPress's $wpdb, legacy apps, mysqlnd-native code). Like PDO_MYSQL, mysqli rides mysqlnd → php_stream, so its socket I/O IS coroutinized under HOOK_ALL (non-blocking per query) — the full coroutine benefit, not just connection bounding.

Transaction-cleanup limitation (important)

mysqli has no inTransaction() — there is no portable way to ask a mysqli handle "is a transaction open right now?". So rollbackIfNeeded() (the pool's defense against a with() body that opened a transaction and returned without committing) is a no-op for mysqli. Two consequences:

  • Use $pool->transaction($fn) for transactional work — it owns the begin/commit/rollback and is always clean.
  • A raw $mysqli->begin_transaction() inside a plain with() body that you don't commit/rollback yourself can leak the open transaction to the next borrower. Don't do that — commit/rollback it, or use transaction().

The error path is still safe: a with()/transaction() body that throws has its connection discarded (poison-pill), and disconnect() (close()) rolls back any open transaction server-side as the connection drops.

Tags
implements

Table of Contents

Interfaces

PoolDriver
Connection-library adapter for {@see DbConnectionPool}.

Properties

$factory  : callable(): mysqli

Methods

__construct()  : mixed
begin()  : void
commit()  : void
connect()  : TConn
Open a fresh connection. Throwing here propagates out of the pool's fill/refill path (the caller sees the underlying connect error).
disconnect()  : void
Tear down a connection. PDO closes on reference release so this can be a no-op there; mysqli needs an explicit close().
isAlive()  : bool
Liveness probe — run $query and return false if the connection is dead (server closed it while idle). Only called when the pool was configured with a validation query.
params()  : self
Build a driver that connects with the given parameters. $charset defaults to utf8mb4. For SSL / custom init commands, pass your own factory to the constructor instead.
rollback()  : void
rollbackIfNeeded()  : void
Make a borrowed connection transaction-clean before it returns to the pool: roll back any transaction the borrower left open. Drivers that cannot introspect transaction state (mysqli has no inTransaction()) may no-op — see {@see MysqliDriver} for the documented limitation.

Properties

Methods

__construct()

public __construct(callable(): mysqli $factory) : mixed
Parameters
$factory : callable(): mysqli

Builds a fresh mysqli connection.

begin()

public begin(object $conn) : void
Parameters
$conn : object

commit()

public commit(object $conn) : void
Parameters
$conn : object

connect()

Open a fresh connection. Throwing here propagates out of the pool's fill/refill path (the caller sees the underlying connect error).

public connect() : TConn
Return values
TConn

disconnect()

Tear down a connection. PDO closes on reference release so this can be a no-op there; mysqli needs an explicit close().

public disconnect(object $conn) : void
Parameters
$conn : object

isAlive()

Liveness probe — run $query and return false if the connection is dead (server closed it while idle). Only called when the pool was configured with a validation query.

public isAlive(object $conn, string $query) : bool
Parameters
$conn : object
$query : string
Return values
bool

params()

Build a driver that connects with the given parameters. $charset defaults to utf8mb4. For SSL / custom init commands, pass your own factory to the constructor instead.

public static params(string $host[, string|null $username = null ][, string|null $password = null ][, string|null $database = null ][, int $port = 3306 ][, string|null $socket = null ][, string $charset = 'utf8mb4' ]) : self
Parameters
$host : string
$username : string|null = null
$password : string|null = null
$database : string|null = null
$port : int = 3306
$socket : string|null = null
$charset : string = 'utf8mb4'
Return values
self

rollback()

public rollback(object $conn) : void
Parameters
$conn : object

rollbackIfNeeded()

Make a borrowed connection transaction-clean before it returns to the pool: roll back any transaction the borrower left open. Drivers that cannot introspect transaction state (mysqli has no inTransaction()) may no-op — see {@see MysqliDriver} for the documented limitation.

public rollbackIfNeeded(object $conn) : void
Parameters
$conn : object
On this page