skaidb — PHP driver
Repository: github.com/porcupin26/skaidb-php — this page is the driver's README at
v1.5.2; the repository also holds its docs, examples and changelog. Install:
composer require skaidb/skaidb
The official skaidb driver for PHP. The API is
modeled on PDO/PDOStatement: prepare(), execute([...]), fetch(),
fetchAll(), rowCount(). Pure PHP, one file, zero dependencies (only
the bundled hash extension; openssl for TLS).
- PHP 8.1 or newer. No Composer or PECL packages required.
- Speaks skaidb's binary protocol directly: SCRAM-SHA-256 auth, server-side prepared statements with typed parameters, one-round-trip batches, streaming result sets, full type fidelity (Int, Float, Decimal, UUID, Bytes, Timestamp, Array, Document).
- Multi-seed failover, transparent reconnect, TLS, connection pooling balanced across the cluster's members, transactions with a retry on conflict, stream subscriptions.
Full documentation: this README, the docs/ folder
(getting started · API reference ·
types · TLS · streaming ·
pooling), runnable examples/, the
changelog, the
wire protocol specification and the
skaidb documentation.
Install
The package is skaidb/skaidb. It is not registered on Packagist yet, so
point Composer at the GitHub repository:
{
"repositories": [
{ "type": "vcs", "url": "https://github.com/porcupin26/skaidb-php" }
],
"require": {
"skaidb/skaidb": "^1.0"
}
}
composer require skaidb/skaidb:^1.0
Composer resolves ^1.0 to the newest v1.x tag and wires src/Skaidb.php into
vendor/autoload.php. (Once the package is on Packagist the repositories
entry becomes unnecessary; composer require skaidb/skaidb installs the same
thing.)
Without Composer, take src/Skaidb.php from a clone or from the
release asset and
require it directly:
require '/path/to/skaidb-php/src/Skaidb.php';
Quick start
<?php
require 'vendor/autoload.php'; // or require 'src/Skaidb.php';
use Skaidb\Connection;
$db = new Connection('localhost', 7000, 'skaidb', 'secret');
$db->exec('CREATE TABLE users (PRIMARY KEY (id))');
$stmt = $db->prepare('INSERT INTO users (id, name, tags) VALUES (?, ?, ?)');
$stmt->execute([1, 'Ada', ['admin']]);
$stmt = $db->prepare('SELECT id, name, tags FROM users WHERE id = ?');
$stmt->execute([1]);
print_r($stmt->fetch()); // ['id' => 1, 'name' => 'Ada', 'tags' => ['admin']]
$db->close();
Connecting
new Connection(
string $host = 'localhost', // node hostname
int $port = 7000, // binary protocol port
string $user = 'anonymous', // 'anonymous' for a server with auth disabled
string $password = '',
int|string $consistency = 'QUORUM', // 'ONE' | 'QUORUM' | 'ALL' or 0 | 1 | 2
float $timeout = 10.0, // connect and read timeout, seconds
?string $database = null, // optional: `USE <database>` right after the handshake
bool $tls = false, // see TLS below
?string $tlsCa = null,
bool $tlsInsecure = false,
string $tlsServerName = 'skaidb',
array $seeds = [], // ['db1:7000', 'db2:7000']; wins over host/port when given
?string $tlsClientCert = null, // PEM client certificate presented in TLS; implies TLS
?string $tlsClientKey = null, // its PEM key, when not in the certificate file
string $authMechanism = 'scram' // 'scram' (user + password) or 'certificate'
);
Every argument is positional, so PHP named arguments read best:
$db = new Connection(user: 'app', password: $pw, database: 'app',
seeds: ['db1:7000', 'db2:7000', 'db3:7000'],
tlsCa: '/etc/skaidb/skai-ca.crt');
The constructor connects and runs the SCRAM-SHA-256 handshake; it throws
Skaidb\ConnectionException when no node can be reached and a plain
Skaidb\SkaidbException when the login is refused. With a
non-empty password the server's signature is verified too (mutual auth).
With authMechanism: 'certificate' the TLS client certificate is the login
instead (see TLS below).
Seeds and failover
skaidb is leaderless: every node accepts reads and writes, so a seed list is
only "somewhere to land". The seeds are shuffled and tried in turn until one
connects and completes the handshake: a seed that refuses the connection, or
closes it during the handshake (a node at capacity does), is walked past. If
none is left the constructor throws no reachable endpoint in <list>: <last
error>. A refused login stops the walk at once — it would be refused on
every member. The same walk runs again on reconnect, so a connection
survives the node it was talking to going away.
TLS
| Arguments | Meaning |
|---|---|
| (none) | Plaintext. A server with client_tls = required refuses this. |
tls: true |
TLS, server certificate verified against the system trust store. |
tlsCa: '/path/ca.crt' |
TLS, certificate verified against this PEM bundle. Implies tls. |
tlsInsecure: true |
TLS with no certificate verification: encrypts, authenticates nothing. Development only. Implies tls. |
tlsServerName |
SNI and the name the certificate is verified against (default skaidb). Must match a SAN on the server certificate, which is usually not the address you dialled — skaidb's own certificates carry DNS:skaidb. |
tlsClientCert / tlsClientKey |
PEM client certificate (and key, unless the certificate file holds it) presented in the TLS handshake. Implies tls. |
authMechanism: 'certificate' |
Log in with that client certificate (wire mechanism EXTERNAL): its Common Name is the user and no password is sent. The server needs auth.x509_enabled. Pass user only to assert the expected identity. |
See docs/tls.md.
Consistency
consistency selects how many replicas must acknowledge a write or be
consulted for a read: ONE, QUORUM (the default) or ALL. Set it per
connection or per statement:
$db = new Connection(/* ... */, consistency: 'ONE');
$db->setConsistency('ALL'); // from now on
$stmt->setConsistency('QUORUM'); // this statement only
foreach ($db->stream('SELECT ...', consistency: 'ONE') as $row) { ... }
Connection::ONE, Connection::QUORUM and Connection::ALL hold the
numeric codes (0, 1, 2).
That is the level each request carries. The server also takes a session
override, SET CONSISTENCY { ONE | QUORUM | ALL }, sent as a statement:
every statement on the connection then runs at that level whatever its
request says, until SET CONSISTENCY DEFAULT (server ≥ 0.349) clears it.
The driver keeps such an override across a reconnect; see Errors and
reconnect.
Statements and parameters
$db->exec(string $sql): int // run; returns the affected-row count (0 for DDL)
$db->query(string $sql): Statement // run without parameters; fetch the result
$db->prepare(string $sql): Statement // then $stmt->execute([...])
$db->transaction(callable $body): mixed // BEGIN, $body($db), COMMIT; see Transactions
$stmt->execute(array $params = []): bool
$stmt->fetch(): ?array // next row as ['column' => value], or null
$stmt->fetchAll(): array // every remaining row
$stmt->fetchColumn(int $i = 0): mixed // one cell of the next row, or false when exhausted
$stmt->rowCount(): int // rows affected (mutations) or rows returned (SELECT)
$stmt->columnCount(): int
$stmt->columns(): array // column names
$stmt->resultSets(): ?array // every set of a CALL that EMITs, else null
Placeholders are ?, positional, in order; a ? inside a string literal,
a double-quoted identifier or a -- comment is left alone, as the server
reads it. Statements on one connection run one at a time.
With parameters the driver prepares the statement on the server (once
per distinct SQL text per connection; the 240 most recently used stay
prepared, and one pushed out is closed on the server and prepared again
when it is next used) and sends the values as typed binary — no string
interpolation, no injection surface. That is also the only way to send an
Array or a Document, which have no SQL literal form. The statement's
parameter count must match what you pass (a mismatch throws before anything
runs).
A statement the server will not prepare — DDL and session statements — is
sent as text instead, with the same ? parameters quoted into it
client-side; the connection remembers the refusal, so that statement is not
asked about again. Each value is written as a literal, so this works
wherever the statement takes a literal: ALTER TABLE t SET (ttl = ?),
CREATE INDEX … WHERE v > ?, SET SCAN BUDGET ROWS ?. A parameter is a
value, never a name or a keyword: USE ? and SET CONSISTENCY ? are
refused, with the server's error for the text it was sent:
parse error: unexpected token "a string literal", expected identifier
parse error: SET CONSISTENCY takes ONE, QUORUM, ALL, or DEFAULT — found a string literal
Write the name into the statement: $db->exec('USE app'). A server before
0.349 does not say statement kind cannot be prepared for a ? in a
literal's place, so there ALTER TABLE t SET (ttl = ?) throws the parser's
error and the value has to be written into the text too. Arrays and documents have no literal form and throw
(the message names the reason the server would not prepare the statement).
Any other error the server answers a prepare with, a syntax error for one,
is the statement's own: it is thrown as it comes and nothing is sent a
second time.
Prepared ids are scoped to a connection and the cache is dropped on
reconnect. A server keeps at most 256 prepared statements per connection;
the driver stays below that, and a prepare the server refuses with too
many prepared statements is thrown rather than sent as text.
Batches — many rows, one round-trip
$n = $db->prepare('INSERT INTO t (id, tags) VALUES (?, ?)')
->executeBatch([[1, ['a']], [2, []], [3, ['b', 'c']]]); // 3
Runs a prepared statement once per row in a single request and returns the total affected count. Rows autocommit individually: on the first failing row the server answers with an error naming the row index and how many rows applied before it, and those earlier rows stay applied — use idempotent statements. The whole request must fit one 64 MiB frame. An empty batch returns 0 without a round-trip.
A statement the server declines to prepare (DDL, session statements) cannot
travel in one request: executeBatch() runs it once per row, each row's
values quoted client-side as execute() quotes them. The result and the
rules are the same — the total affected count, rows applied one by one, an
error naming the first failing row and how many ran before it — at one
round-trip per row.
Multiple result sets
A CALL of a procedure whose body runs EMIT <select> answers with every
emitted set plus the call's final result:
$stmt = $db->query('CALL report()');
$stmt->fetchAll(); // the LAST set (the call's own result)
$stmt->resultSets(); // every set, in emission order: [['columns' => [...], 'rows' => [...]], ...]
Streaming large results — $db->stream($sql, $params = [], $consistency = null)
query() buffers the whole result; a large scan is also bounded by the
server's scan budgets. stream() asks the server to deliver the rows in
chunks and yields them one at a time, holding one chunk in memory. The
server executes a plain SELECT page by page, and no scan budget applies to
a streamed page (server ≥ 0.330; the rules are under "Streamed queries" in
the query syntax, and EXPLAIN
says which statements page):
foreach ($db->stream('SELECT id, v FROM readings') as $row) {
process($row); // ['id' => ..., 'v' => ...]
}
$params bind the statement's ? placeholders in order, sent as typed
values exactly as a prepared execute() sends them:
foreach ($db->stream('SELECT id, ts, body FROM events WHERE ts >= ? AND ts < ?', [$from, $to]) as $row) {
export($row);
}
A parameterised stream needs server ≥ 0.330; an older server's refusal
throws server does not support parameterised streaming (skaidb >= 0.330):
… and leaves the connection usable. A stream without parameters sends the
original streaming opcode, so it works against any server that streams.
$consistency overrides the connection's level for the statement;
stream($sql, 'ONE'), a consistency in the second position, means the same
as stream($sql, consistency: 'ONE').
A non-row statement streamed this way yields nothing; once the generator has
finished, getReturn() gives ['kind' => 'rows'|'mutation'|'ddl',
'columns' => [...], 'affected' => n]. A CALL whose body EMITs result
sets is answered with all of them in one frame even when streamed: the
generator yields the rows fetch() would return (the last set), and
getReturn() adds 'result_sets', every set as resultSets() returns
them. An error before any row
is an ordinary statement error; an error partway through (a node dying
mid-scan, a scan budget tripping) is thrown after the rows already yielded,
which are valid.
The connection is busy for the whole stream. Any other statement on it
throws connection is busy streaming a result set until the stream ends.
Abandoning the stream — break, return, an exception, or letting the
generator go out of scope — runs the generator's cleanup, which drains the
frames still in flight so the connection is back at a request boundary;
draining a huge scan costs the rest of that scan, so close() the
connection instead if that trade is wrong. See docs/streaming.md.
Following a stream — $db->subscribe($name, $after = null, $poll = 0.5)
For tables with a CREATE STREAM, subscribe() yields the stream's events
as they arrive, forever:
foreach ($db->subscribe('big_orders', after: $lastSeenId) as $ev) {
// $ev = ['id' => ..., 'op' => ..., 'k' => ..., 'ts' => ..., 'doc' => ...]
save($ev['id']); // pass it back as $after to resume exactly here
}
It polls the stream's log (_stream_<name>) with a keyset cursor, 500 events
per page; id is the position — an opaque string that sorts in log
order, so $after takes a saved id or null. break out of the loop to
stop. For push delivery subscribe to $stream/<db>/<name> with any MQTT
client instead — the events are identical.
Pooling — new Pool($connectionArgs, $maxsize = 10)
use Skaidb\Pool;
$pool = new Pool(['db1', 7000, 'app', $pw, 'QUORUM', 10.0, 'app'], 8);
$n = $pool->withConnection(fn (Connection $c) => $c->query('SELECT count(*) AS n FROM t')->fetchColumn());
$conn = $pool->acquire();
try { $conn->exec('...'); } finally { $pool->release($conn); }
$pool->transaction(fn (Connection $c) => $c->exec('...')); // one connection from BEGIN to COMMIT
$pool->close();
$connectionArgs are the Connection constructor arguments (positional, or
named as ['user' => ..., 'seeds' => [...]]), so pooled connections inherit
TLS, credentials and the session database. maxsize bounds the connections
kept idle, not the number checked out: a burst opens extras and the
surplus is closed on release. PHP is share-nothing per request, so a pool
pays off in a worker or a long-running CLI job.
Every borrower gets the pool's own session state: the pool's database
(its database argument; without one, the database every new connection
starts in, default), no consistency override, no scan budget, no
transaction open. What a borrower changes on its connection — USE other,
SET CONSISTENCY ALL, SET SCAN BUDGET ROWS 1, a BEGIN it never ended —
is its own until it releases the connection, also across a reconnect, and
is put back on release: ROLLBACK, USE <the pool's database>, SET SCAN
BUDGET DEFAULT, SET CONSISTENCY DEFAULT, only the ones that are needed,
so a borrower that changed nothing costs no round trip. If one of them is
refused (a server before 0.349 has no SET CONSISTENCY DEFAULT) the
connection is closed instead of kept. Name the database in the pool's
arguments rather than switching on every checkout.
The pool balances across the cluster's members by the rules every skaidb driver shares (PROTOCOL.md §6.1):
$pool = new Pool(['seeds' => ['db1:7000', 'db2:7000', 'db3:7000'], 'user' => 'app', 'password' => $pw], 8,
loadBalancing: 'least_latency', // 'random' (default) | 'round_robin' | 'least_latency'
discover: true, // members from SHOW ENDPOINTS; resyncing ones skipped
readYourWrites: 2.0, // seconds: a key's reads follow its last write's member
);
$pool->withConnection(fn (Connection $c) => $c->prepare('UPDATE users SET seen = ? WHERE id = ?')
->execute([time(), $userId]), $userId); // the affinity key for readYourWrites
print_r($pool->members()); // endpoint, canonical, state, latency_ms, in_use, idle, seed
A member that keeps failing, or turns much slower than the others, is
ejected for a backoff (ejectErrors, ejectLatencyFactor,
ejectBackoff, …; never the last usable one); idleOrder: 'fifo' keeps
every idle connection in use. The fastest of a member's first three round
trips seeds its latency average, so a statement that stalls in your own
process (a CPU-bound start-up) cannot get a healthy member ejected; each
ejection goes to the PHP error log (error_log()) with its reason — for a
latency one the average, the median and the slowest of the member's last
10 round trips. PHP has no background threads, so the probe
that re-admits an ejected member runs on the first acquire() after its
backoff, and the discovery refresh on the first acquire() after the
refresh interval. See docs/pooling.md.
Type mapping
| skaidb | PHP (results) | Bind (parameters) |
|---|---|---|
| Null | null |
null |
| Bool | bool |
bool |
| Int (i64) | int |
int |
| Float | float |
float (NaN/Infinity refused) |
| Decimal | string, exact ('123.45') |
new Skaidb\Decimal('123.45') |
| String | string |
string |
| Bytes | string (binary) |
new Skaidb\Bytes($raw) |
| Uuid | string, canonical lowercase 8-4-4-4-12 |
new Skaidb\Uuid('123e4567-…') |
| Timestamp | DateTimeImmutable in UTC, millisecond precision |
any DateTimeInterface |
| Array | array (list) |
a list array (array_is_list) |
| Document | array (associative, insertion order) |
an associative array |
A plain PHP string binds as a String; wrap it in Bytes, Decimal or
Uuid to send the typed value the server cannot express as a SQL literal.
Decimal is exact across the full 128-bit mantissa without gmp or bcmath.
Details in docs/types.md.
Errors and reconnect
Every error the driver raises is a Skaidb\SkaidbException (an Exception
subclass, modeled on PDOException). Two subclasses tell the cases apart
that code usually treats differently:
try {
$db->prepare('UPDATE stock SET n = ? WHERE id = ?')->execute([$n, $id]);
} catch (Skaidb\ConnectionException $e) {
// the connection was lost: the statement may or may not have run
} catch (Skaidb\SkaidbException $e) {
// the server refused the statement; the connection is fine
}
- Statement errors (
SELECT nope→no such column …) throw a plainSkaidbException; the connection stays usable. ACOMMITthe server refuses because of a conflicting write throws the subclassSkaidb\TransactionConflictException(see Transactions). - Transport errors throw
Skaidb\ConnectionException(connection closed by server,connection timed out,no reachable endpoint in …, a member turning the connection away, a reply the driver cannot place) and mark the connection broken, not closed. Its socket is closed at once, so the server's session — and a transaction open in it — ends there, also after a read timeout. The next statement re-dials (through the seed walk), re-authenticates, puts the session's state back (below) and clears the prepared-statement cache — unless a transaction was open on the connection (see Transactions). Because the failed statement may have executed, the driver never retries it for you: retry a write only if it is idempotent.isUsable()reports the state. - A connection the server closed while it sat idle costs no statement.
A restart, a failover or an idle timeout closes idle connections, and a
write to one still succeeds — only the read would fail, when the
statement can no longer be sent elsewhere. So before it writes a request
the driver looks at the socket (one poll with a zero timeout, no round
trip; under TLS too): a connection found closed, reset, or holding bytes
no request is waiting for is replaced there and then, and the statement
runs on the new one. No error reaches the application, for a read and a
write alike — nothing was sent on the dead connection.
isUsable()makes the same look, and a pool makes it at every checkout. - The session database survives the re-dial. It is the constructor's
$database, or the one the lastUSEthe server accepted moved to: a statement that is exactlyUSE [DATABASE] <name>(the name bare or in double quotes, an optional;,--comments skipped as the server skips them) sent throughexec(),query(),execute()orstream(). Anything the driver cannot read as one such statement is not noticed. If the database cannot be entered on the new connection, the statement throws that error instead of running in another database. - So do the session's settings. A consistency override (
SET CONSISTENCY ALL) and a scan budget (SET SCAN BUDGET ROWS 1000) live on the server's side of the connection, like the database. The driver keeps the text of the lastSET CONSISTENCY …and the lastSET SCAN BUDGET …the server accepted — one statement, comments and a trailing;aside, however it was sent — and sends them again on a new connection, after theUSEand before the statement: the consistency first, then the budget. A setting cleared with… DEFAULTis not sent. If one is refused there, the statement throws that error and is not sent: it never runs under other settings than the ones you set. - A
USEalways gets you out. If the session database was dropped and the connection is lost, every statement fails at the re-dial'sUSE(database "app" does not exist) — except aUSEitself: the new connection is not taken into the old database first, so$db->exec('USE other')succeeds and the session carries on inother. ASET CONSISTENCY …orSET SCAN BUDGET …replaces a setting the new connection refuses the same way. Should that statement be refused in turn, the connection is dropped again rather than used half restored. - Protocol desync (an unexpected frame): the driver drops the connection rather than hand the next caller a misaligned reply; the next statement reconnects.
close()is terminal: a closed connection never reconnects.
Transactions
A transaction is plain SQL on one connection: an opening statement, the
statements, then COMMIT or ROLLBACK. A standalone server opens one with
BEGIN; a cluster with BEGIN ATOMIC or BEGIN ATOMIC PARTITION (col =
literal). Outside a transaction every statement autocommits, and so does
each row of a batch.
$left = $db->transaction(function (Connection $c) use ($id) {
$st = $c->prepare('SELECT n FROM stock WHERE id = ?');
$st->execute([$id]);
$n = $st->fetchColumn() - 1;
$c->prepare('UPDATE stock SET n = ? WHERE id = ?')->execute([$n, $id]);
return $n; // what transaction() returns
});
$db->transaction($body, attempts: 5, begin: 'BEGIN ATOMIC');
transaction(callable $body, int $attempts = 3, string $begin = 'BEGIN')
sends $begin, calls $body($connection), sends COMMIT and returns what
the body returned. If the body throws, it sends ROLLBACK and rethrows the
body's exception unchanged.
A standalone server (≥ 0.346.0) refuses a COMMIT when another writer
changed a row the transaction writes after its BEGIN. The driver throws
that as Skaidb\TransactionConflictException: a SkaidbException for a
server error whose message starts with transaction conflict:, from
whichever call ran the statement. Nothing was committed, the transaction is
over, and the connection is back in autocommit and usable, so running the
whole transaction again is safe. transaction() does that, at once, until
the transaction has run $attempts times; if that COMMIT is refused too,
the conflict is thrown. The body can therefore run more than once: make
it safe to repeat, and keep out of it whatever a repeat would do twice
outside the database (an e-mail, an HTTP call). Nothing else is retried: an
exception out of the body (a conflict included), a COMMIT that fails for
another reason and a connection error are thrown as they come. $attempts
below 1 throws before anything is sent.
The same by hand:
$db->exec('BEGIN'); // throws? stop here
try {
$db->prepare('UPDATE accounts SET balance = ? WHERE id = ?')->execute([$left, $from]);
$db->prepare('UPDATE accounts SET balance = ? WHERE id = ?')->execute([$right, $to]);
} catch (\Throwable $e) {
try {
$db->exec('ROLLBACK');
} catch (SkaidbException $ignored) {
// clean-up only: $e is the error to report
}
throw $e;
}
$db->exec('COMMIT'); // TransactionConflictException: start again from BEGIN
The rules, with the helper or without:
- One connection for the whole transaction. With a pool, use
$pool->transaction($body)— it checks one connection out, runstransaction()on it and returns it — or do everything inside onewithConnection(); never spread a transaction over several checkouts. - Stop if the opening statement fails. No transaction is open then, and every statement after it would autocommit on its own.
- A lost connection ends the transaction, and nothing of it is sent on
a new one. A new session has no transaction open: sent there, the
statements that follow — and the
COMMIT— would each commit on their own. So while a transaction is open the driver does not reconnect. That holds insidetransaction()and for a transaction you open yourself: the driver notes a statement the server accepted whose first word isBEGIN, until aCOMMITor aROLLBACK(alone, or followed byTRANSACTION) has been answered. Until then, once the connection is lost, every statement throws aConnectionException—connection lost inside a transaction: the statement was not sent …— and you end the transaction yourself: ROLLBACKsucceeds without being sent: the server rolled the transaction back when the connection went.COMMITthrowsconnection lost inside a transaction: the COMMIT was not sent, and nothing was committed ….
Either one ends it, and the next statement reconnects as usual
(transaction() does this for you and throws the loss). Only when the
connection is lost under the COMMIT itself is the outcome unknown —
the server may have applied it before its reply went missing — and the
error says so: connection closed by server: the connection was lost
under the COMMIT, so whether the transaction was committed is not known.
A failed COMMIT has ended the transaction, whatever the reason. A
statement that fails inside one has not: the transaction stays open, to
continue or to roll back. A ROLLBACK that finds no transaction open is an
error on servers before 0.347.0, so never let a clean-up ROLLBACK replace
the error being handled.
A stream started in the body must be finished before the body returns: the
connection is busy until then and can take neither the COMMIT nor the
ROLLBACK. If one is still open when the body ends — its generator was
returned, or kept somewhere — transaction() closes the connection, so the
server drops the transaction and no later statement can run inside it, and
throws: the body's exception if it threw, otherwise connection is busy
streaming a result set: …. Nothing was committed. The connection re-dials
on the first statement after the stream is let go; a pool does not take it
back.
Client identification
After authenticating, the driver sends a Hello frame that fills the server's
drivers table: client_name php, client_version = Skaidb\Skaidb::VERSION
(the package version, 1.5.2). An older server without the opcode ignores
it. Prepared statements need server ≥ 0.17.0 (older servers get the
client-side fallback automatically), a batch in one request ≥ 0.87.0 (an
older server is sent the rows one prepared execute each, with the same
result), streaming a server with the streaming opcode, parameterised
streaming ≥ 0.330, multiple result sets a server with EMIT, the
transaction conflict error a standalone server ≥ 0.346.0.
Development
php tests/run.php # unit tests against an in-process fake server, no skaidb needed
SKAIDB_HOST=127.0.0.1 SKAIDB_PORT=7000 SKAIDB_USER=admin SKAIDB_PASSWORD=pw \
php tests/live/live.php # end-to-end against a real node (skipped when SKAIDB_HOST is unset)
php examples/basic.php host 7000 user password
Conformance
tests/conformance.test.php runs the shared skaidb wire-protocol
conformance suite: conformance/vectors.json, generated from the server's
own encoders and vendored byte-identical from
https://skaidb.org/conformance/vectors.json (contract in
conformance/README.md). It decodes every value
vector and encodes every one the driver can bind, recomputes the SCRAM
vectors with the driver's SCRAM code, and drives every case through the
public API (query, stream, prepare/execute, executeBatch) against
a scripted fake server that verifies the client proof independently,
checks each request byte for byte and replays the reference responses; the
three auth outcomes (ok, bad_server_signature must fail, denied) run
too. CI fails when the vendored copy differs from the published one.
Skipped: encoding document_empty — PHP has one empty array, and bound as
a parameter it is an empty Array. No call.method is skipped.
CI runs the suite on PHP 8.1, 8.2, 8.3 and 8.4, validates composer.json,
installs the package through Composer the way the Install section says, and
checks that the Hello version is derived from Skaidb::VERSION. Tagging
vX.Y.Z runs the publish workflow, which refuses a tag that does not equal
Skaidb::VERSION, builds the source zip and attaches it to a GitHub
Release. Packagist has no upload: registering the repository once on
packagist.org (Submit → this repository's URL) makes every tag a version
there. The workflow's last step asks Packagist to re-crawl the repository
when the PACKAGIST_USERNAME and PACKAGIST_TOKEN repository secrets are
set (the packagist.org account name and the API token from its profile page)
and waits until the version is listed; without them, while the package is
not on Packagist, it logs that as a notice and the GitHub release and the
VCS install above are the channels.