Skip to content

mysqli on top of pdo_mysql: full php.net surface, real async - #492

Merged
blacktrs merged 43 commits into
mainfrom
mysqli
Oct 26, 2026
Merged

blacktrs merged 43 commits into
mainfrom
mysqli

Conversation

@blacktrs

Copy link
Copy Markdown
Contributor

mysqli: the full ext/mysqli surface, in pure PHP over the MySQL wire

Why

Legacy and mainstream PHP code (WordPress, phpMyAdmin-style tools, Adminer, Drupal 7-era code) talks to the database
through mysqli, not PDO. Until now such programs did not compile. Acceptance is parity: any mysqli program prints
the same bytes under php and as a Manticore binary.

What

  • Classes mysqli, mysqli_stmt, mysqli_result (IteratorAggregate), mysqli_driver, mysqli_warning,
    mysqli_sql_exception; all 106 procedural functions and 110 constants with the Zend signatures. Pure PHP prelude
    on the existing MySQL wire class (no libmysqlclient). Demand-gated: a program that never names mysqli links none of it.
  • Wire additions: send/read split, COM_CHANGE_USER, COM_INIT_DB, COM_PROCESS_KILL, COM_REFRESH,
    COM_STMT_SEND_LONG_DATA, unix sockets, OK-packet info. The wire now drops a CALL's OUT-parameter result set
    (SERVER_PS_OUT_PARAMS) for buffered and streamed reads, which also fixes PDO's prepared CALL p(?, ?) with an OUT
    parameter (it showed the OUT set as a rowset, then lost sync with 2027/2006).
  • Report modes (OFF / ERROR / STRICT / INDEX) per Zend 8.1+ defaults; warnings are silent, php's
    warn-and-carry-on paths return false.
  • Prepared statements ported from mysqlnd's state machine (bind_param / bind_result, long data, server cursors,
    execute_query), multi_query chains, transactions and savepoints, field metadata and native types, charsets.
  • The link closes with the mysqli object (Zend's free): a result or statement that outlives it is out of sync / gone.
  • Async: every blocking call yields the fiber; plus Zend's MYSQLI_ASYNC / reap_async_query / mysqli::poll.
  • Docs: docs/mysqli.md (usage, report modes, unix socket, async, stubs, known gaps, every internal member visible to
    introspection); docs/builtins.md regenerated; ROADMAP updated.
  • CI: new mysqli-net job (arm64 + amd64, mysql + mariadb, 2 shards) mirroring pdo-net; runs on push to main and on
    PRs touching mysqli, the mysql wire, prelude/pdo.php, prelude/pdo_sql.php or src/.

Behaviour change outside mysqli (php 8.5.12 oracle)

php 8.5.12's mysqlnd reports no columns on the closing OK of a CALL. PDOStatement::columnCount() after nextRowset()
reaches it now reads 0 (it copied the previous set's columns, measured on 8.5.11), as does mysqli_stmt::$field_count.

Surface audit

tools/mysqli_surface_audit.php diffs Zend's Reflection dump (tests/mysqli_net/surface.json) against the compiled
probe: 6 classes / 106 functions / 110 constants, no missing symbol, no signature difference, 7 accepted extras
(mysqli::__destruct, mysqli_result::__destruct, mysqli_stmt::__destruct, mysqli_warning::__clone, private
mysqli_warning::$__i, $__msg, $__no), listed with every other internal member in docs/mysqli.md.
Server-less cases tests/aot/cases/mysqli_{surface,stubs,not_linked,string_probe,fq_probe,fq_reflection} run in the suite.

Parity (php 8.5.12 with mysqli vs the binary, live servers)

bash tests/mysqli_net/run.sh --server <s>: 33 cases, live php as the oracle, stdout + exit status compared.

  • mysql 8.4: 31 PASS, 1 FAIL, 1 SKIP; mariadb 11: 31 PASS, 1 FAIL, 1 SKIP
  • the FAIL is props: client_info / client_version print the compiler's PHP_VERSION (8.5.11) against php 8.5.12;
    the version constant is main's, not this branch's
  • SKIP: socket (needs MYSQLI_SOCKET); async_fiber has no php oracle (hand-written .expected)

PDO regression (bash tests/pdo_net/run.sh -k mysql): mysql 40 / 0 / 2 skip (was 39 / 0 / 2; + mysql_call_out),
mariadb 34 / 0 / 7. bash tests/aot/run.sh -k: mysqli 6/6, pdo 30/30, byref 135/135, hook 11/11, prop 209/209,
erased 108/108.

Compiler fixes in this PR

Closed by main's bug sweeps before this rebase (this branch's own fixes were dropped in favour of main's):
#69 #347 #434 #435 #436 #438 #439 #440 #441 #442 #443 #444 #445 #446 #448 #449 #459 #460 #465 #466 #468 #469 #472
#473 #474 #480. Still open, each with a repro under tests/aot/repro (XFAIL): #457 #471 #475 #484 #487 #490 #491.

Known gaps

See docs/mysqli.md: no warnings printed, MYSQLI_REPORT_INDEX has no effect, object handle numbers (#457),
get_object_vars / foreach / (array) show internal or virtual properties php hides (#487), mysqli.default_socket
is '', stats not metered.

Gates owed (not run locally)

This PR touches src/ (emitter hook dispatch, ownership of hooked reads, inference, lowering) and the prelude:

  • bash tests/aot/run.sh -j 0
  • bash tests/pdo_net/run.sh --server mysql and --server mariadb (all cases, pgsql too)
  • MYSQLI_SOCKET=... bash tests/mysqli_net/run.sh -k socket once
  • bash tools/docker/run_tests.sh --gate [--amd64] (Linux)
  • bash tools/difftest.sh, a few generations of tools/selfhost_fixpoint.sh

Notes

  • Compiler tracks php 8.5.12 (PHP_VERSION, PHP_VERSION_ID, PHP_RELEASE_VERSION); PDO/mysqli CALL closing-OK column count follows 8.5.12, so the CI php oracle must be 8.5.12.
  • Gates owed (compiler core touched): full AOT suite, difftest, selfhost fixpoint, Linux gate.

…, linked only when a program names mysqli*

Prelude mysqli.php/mysqli_fn.php carry the Zend signatures (bodies throw 'mysqli: not implemented'); the gate is a code mention of any mysqli* identifier. Reflection now emits interface lists for prelude classes. Audit probe is emitted with literal names. Hello-world binary: main 107816 B, branch 107816 B. Repros for #434, #435.
…ass_exists('mysqli'), defined('MYSQLI_X'), dynamic new $cls); strings merely containing the word stay unlinked
…plit, unix transport and socket() to the mysql wire for mysqli
…ectUnix, tighten changeUser state handling, add hasBuffered
… variadic writes, stored bindings written by a later call, by-ref ?array params
…) or a literal compared or passed as data no longer links it, so the compiler itself stops carrying mysqli
…h erased and dynamic-name writes; box a hook's narrowed return to the property's cell (#448 follow-up: main's fix covered typed set hooks only)
…hooked properties, charset and escaping, unix socket for localhost; live parity cases in tests/mysqli_net
…qli_result (fetch modes, fetch_object, data_seek, iteration, unbuffered, out-of-sync); command state for select_db/ping/set_charset; reflect demand for fetch_object
…object's scope; root only the named class for reflection; repros for the compiler bugs found
…) and text-protocol types, MYSQLI_OPT_INT_AND_FLOAT_NATIVE read at each fetch. Defensive only, no test can observe it: the fetch_object reflection gate in Main.php is case-insensitive and falls back to dynamic mode for use aliases and self/static/parent::class
…d get_warnings (mysqli_warning) over the wire commands; cases for SQL text, charsets and escaping, 16 MiB packet splits
…i_warning is uncloneable; cases fail loudly without root, guard the general log, poll for the killed thread
…ram/bind_result by reference, get_result, cursors, long data) and execute_query over the binary protocol
… set ends without MORE_RESULTS), dedupe bind-in-execute and error-keeping close, flat-memory check
…structor callees, not only plain function calls (Fixes #485)
…th mysqlnd's reject/argument rules) over the wire's send/read split, fiber-async cases; multi_query out of sync records the refused multi-statements switch too
…tions (query/real_query/async OFF, multi_query ON) and forgets the flag like mysqli; prepare leaves the flag alone; async_fiber times only the overlapped work; method hop cases for #485
…ion, links) answer like Zend; change_user keeps the multi-statements flag; cases for stubs, info under errors, change_user after multi_query and results after a mid-chain close
… fetch_object( anywhere else (a comment, a user method) no longer turns off class reachability
…hods, $__mc, mysqli_warning's private state, reflection property order) and what get_object_vars / foreach / (array) show now
…DOStatement::columnCount() and mysqli_stmt::$field_count read 0 after next_result / nextRowset reaches it
…AMS) in readChain for buffered and streamed reads alike, so PDO's prepared CALL with an OUT parameter stays in sync and hides that set like mysqlnd; mysqli's own skip goes
…and a statement no longer keeps that object alive; an unbuffered fetch after the link closed throws 'Commands out of sync' under MYSQLI_REPORT_STRICT
…) and untyped no-return call yielding int 0 (#494)
@blacktrs
blacktrs merged commit 56cd802 into main Oct 26, 2026
65 checks passed
@blacktrs
blacktrs deleted the mysqli branch October 26, 2026 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A static method that replaces a by-reference array argument with an array of objects reads back as strings in the caller (a plain function does not).

1 participant