class ZtdMysqli
    extends mysqli
Public API: explicitly declared with @visibility public.

mysqli proxy that enforces ZTD behavior for reads and writes.

Uses delegation pattern: extends mysqli for type compatibility, but delegates all operations to an inner mysqli instance when using fromMysqli().

All public methods are explicitly overridden to prevent parent class implementation from being called when constructed via fromMysqli().

Properties are delegated via __get/__isset to the inner mysqli instance.

Supports optional SessionFactory injection. If no factory is provided, MySqlSessionFactory is used by default (mysqli is MySQL-only).

Simulate writes without changing the native tabledoctest
$container = \Testcontainers\Testcontainers::run(\Container\MySql80Container::class);
    $native = new \mysqli(str_replace('localhost', '127.0.0.1', $container->getHost()), 'root', 'root', 'test', $container->getMappedPort(3306));
    $native->set_charset('utf8mb4');
    $native->query('CREATE TABLE accounts (id INT PRIMARY KEY, balance INT)');
    $native->query('INSERT INTO accounts VALUES (1, 10)');
    $ztd = \ZtdQuery\Adapter\Mysqli\ZtdMysqli::fromMysqli($native);
    $ztd->query('INSERT INTO accounts VALUES (2, 20)');
    $ztd->lastAffectedRows() // => 1
    $ztd->query('SELECT id FROM accounts')->fetch_all(MYSQLI_ASSOC) // => [['id' => 2]]
    $native->query('SELECT id FROM accounts')->fetch_all(MYSQLI_ASSOC) // => [['id' => '1']]
    $native->query('DROP TABLE accounts');
    $container->stop();

Methods§

public function __construct(
    ?string $hostname = null,
    ?string $username = null,
    ?string $password = null,
    ?string $database = null,
    ?int $port = null,
    ?string $socket = null,
    ?ZtdConfig $config = null,
    ?SessionFactory $factory = null,
)

Configure a new ZTD-enabled mysqli wrapper.

If $factory is provided, it is used directly to create the session. If $factory is null, MySqlSessionFactory is used by default.

Parameters

$hostname?string
$username?string
$password?string
$database?string
$port?int
$socket?string
$config?ZtdConfig
$factory?SessionFactory
Calls 3
public static function fromMysqli(
    mysqli $mysqli,
    ?ZtdConfig $config = null,
    ?SessionFactory $factory = null,
): self

Create a ZtdMysqli wrapper around an existing mysqli instance.

This allows reusing an existing mysqli connection instead of creating a new one. The wrapped mysqli instance will be used for all database operations.

If $factory is provided, it is used directly to create the session. If $factory is null, MySqlSessionFactory is used by default.

Parameters

$mysqlimysqli
$config?ZtdConfig
$factory?SessionFactory

Returns

self
Test cases 104
Calls 4
public function enableZtd(): void

Enable ZTD mode for this connection.

Calls 1
public function disableZtd(): void

Disable ZTD mode for this connection.

Calls 1
public function isZtdEnabled(): bool

Check whether ZTD mode is enabled.

Returns

bool
Test cases 1
Calls 1
public function lastAffectedRows(): int

Get the affected row count from the last ZTD or regular operation.

Note: Direct property access ($this->affected_rows) is not supported because PHP's C extension property handler for mysqli takes precedence over __get when the parent constructor was not called. Use this method instead.

Returns

int
Calls 1
public function __get(string $name): mixed

Delegate property access to the inner mysqli instance.

Handles affected_rows specially when ZTD has tracked affected rows.

Parameters

$namestring

Returns

mixed
Calls 4
public function __isset(string $name): bool

Delegate property isset check to the inner mysqli instance.

Parameters

$namestring

Returns

bool
Calls 3
public function prepare(string $query): mysqli_stmt|false

{@inheritDoc}

Parameters

$querystring

Returns

mysqli_stmt|false

Throws

ZtdMysqliException When ZTD-specific exception occurs (wraps DatabaseException).
mysqli_sql_exception When native execution fails.
Called from 2
Calls 2
public function query(string $query, int $resultMode = MYSQLI_STORE_RESULT): mysqli_result|bool

{@inheritDoc}

Parameters

$querystring
$resultModeint

Returns

mysqli_result|bool

Throws

ZtdMysqliException When ZTD-specific exception occurs (wraps DatabaseException).
mysqli_sql_exception When native execution fails.
Test cases 2
Calls 2
public function real_query(string $query): bool

{@inheritDoc}

Parameters

$querystring

Returns

bool

Throws

ZtdMysqliException When ZTD-specific exception occurs (wraps DatabaseException).
mysqli_sql_exception When native execution fails.
Calls 2
public function multi_query(string $query): bool

{@inheritDoc}

Parameters

$querystring

Returns

bool
Calls 1
public function begin_transaction(int $flags = 0, ?string $name = null): bool

{@inheritDoc}

Parameters

$flagsint
$name?string

Returns

bool
Calls 1
public function commit(int $flags = 0, ?string $name = null): bool

{@inheritDoc}

Parameters

$flagsint
$name?string

Returns

bool
Calls 1
public function rollback(int $flags = 0, ?string $name = null): bool

{@inheritDoc}

Parameters

$flagsint
$name?string

Returns

bool
Calls 1
public function autocommit(bool $enable): bool

{@inheritDoc}

Parameters

$enablebool

Returns

bool
Calls 1
public function select_db(string $database): bool

{@inheritDoc}

Parameters

$databasestring

Returns

bool
Calls 1
public function set_charset(string $charset): bool

{@inheritDoc}

Parameters

$charsetstring

Returns

bool
Calls 1
public function real_escape_string(string $string): string

{@inheritDoc}

Parameters

$stringstring

Returns

string
Calls 1
public function escape_string(string $string): string

{@inheritDoc}

Parameters

$stringstring

Returns

string
Calls 1
public function ping(): bool

{@inheritDoc}

Returns

bool
Calls 1
public function character_set_name(): string

{@inheritDoc}

Returns

string
Calls 1
public function change_user(string $username, string $password, ?string $database): bool

{@inheritDoc}

Parameters

$usernamestring
$passwordstring
$database?string

Returns

bool
Calls 1
public function connect(
    ?string $hostname = null,
    ?string $username = null,
    ?string $password = null,
    ?string $database = null,
    ?int $port = null,
    ?string $socket = null,
): bool

{@inheritDoc}

Parameters

$hostname?string
$username?string
$password?string
$database?string
$port?int
$socket?string

Returns

bool
Calls 1
public function debug(string $options)

{@inheritDoc}

Parameters

$optionsstring
Calls 1
public function dump_debug_info(): bool

{@inheritDoc}

Returns

bool
Calls 1
public function get_charset(): ?object

{@inheritDoc}

Returns

?object
Calls 1
public function get_client_info(): string
Deprecated: 8.1

{@inheritDoc}

Returns

string
Calls 1
public function get_connection_stats(): array<string, mixed>

{@inheritDoc}

Returns

array<string, mixed>
Calls 2
public function get_server_info(): string

{@inheritDoc}

Returns

string
Calls 1
public function get_warnings(): mysqli_warning|false

{@inheritDoc}

Returns

mysqli_warning|false
Calls 1
public function init(): ?bool
Deprecated: 8.1

{@inheritDoc}

Returns

?bool
Calls 1
public function kill(int $process_id): bool

{@inheritDoc}

Parameters

$process_idint

Returns

bool
Calls 1
public function more_results(): bool

{@inheritDoc}

Returns

bool
Calls 1
public function next_result(): bool

{@inheritDoc}

Returns

bool
Calls 1
public function options(int $option, mixed $value): bool

{@inheritDoc}

Parameters

$optionint
$valuemixed

Returns

bool
Calls 1
public function real_connect(
    ?string $hostname = null,
    ?string $username = null,
    ?string $password = null,
    ?string $database = null,
    ?int $port = null,
    ?string $socket = null,
    int $flags = 0,
): bool

{@inheritDoc}

Parameters

$hostname?string
$username?string
$password?string
$database?string
$port?int
$socket?string
$flagsint

Returns

bool
Calls 1
public function reap_async_query(): mysqli_result|bool

{@inheritDoc}

Returns

mysqli_result|bool
Calls 1
public function refresh(int $flags): bool

{@inheritDoc}

Parameters

$flagsint

Returns

bool
Calls 1
public function release_savepoint(string $name): bool

{@inheritDoc}

Parameters

$namestring

Returns

bool
Calls 1
public function savepoint(string $name): bool

{@inheritDoc}

Parameters

$namestring

Returns

bool
Calls 1
public function ssl_set(
    ?string $key,
    ?string $certificate,
    ?string $ca_certificate,
    ?string $ca_path,
    ?string $cipher_algos,
)

{@inheritDoc}

Parameters

$key?string
$certificate?string
$ca_certificate?string
$ca_path?string
$cipher_algos?string
Calls 1
public function stat(): string|false

{@inheritDoc}

Returns

string|false
Calls 1
public function stmt_init(): mysqli_stmt

{@inheritDoc}

Returns

mysqli_stmt
Calls 1
public function store_result(int $mode = 0): mysqli_result|false

{@inheritDoc}

Parameters

$modeint

Returns

mysqli_result|false
Calls 1
public function thread_safe(): bool

{@inheritDoc}

Returns

bool
Calls 1
public function use_result(): mysqli_result|false

{@inheritDoc}

Returns

mysqli_result|false
Calls 1
public function set_opt(int $option, mixed $value): bool

{@inheritDoc}

Parameters

$optionint
$valuemixed

Returns

bool
Calls 1
public static function poll(
    array<mixed, mixed>|null &$read,
    array<mixed, mixed>|null &$error,
    array<mixed, mixed> &$reject,
    int $seconds,
    int $microseconds = 0,
): int|false

{@inheritDoc}

Parameters

$readarray<mixed, mixed>|null
$errorarray<mixed, mixed>|null
$rejectarray<mixed, mixed>
$secondsint
$microsecondsint

Returns

int|false
Test cases 1
Calls 1
public function execute_query(
    string $query,
    array<mixed, mixed>|null $params = null,
): mysqli_result|bool

{@inheritDoc}

Parameters

$querystring
$paramsarray<mixed, mixed>|null

Returns

mysqli_result|bool

Throws

ZtdMysqliException When ZTD-specific exception occurs (wraps DatabaseException).
mysqli_sql_exception When native execution fails.
Called from 1
Calls 3

Private surface 1§

Implementation details, listed for orientation only.

private ConnectionExecution $execution

Test cases 107§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 57
Other tests reaching this symbol 50