PHP driver
coradb-php is the PHP driver for CoraDB. It is written in plain PHP and speaks the CoraDB broker protocol directly: no C extension to compile, no CCI library, no php.ini changes — composer require is enough.
It has two layers:
- The object-oriented API (
CoraDB\Connection,Statement, …) — the driver itself, for new code. - The
coradb_*functions — a compatibility layer that mirrors the old CUBRID extension'scubrid_*functions, so existing applications can switch by renaming. It will be removed in a future major version.
Features: server-side typed parameter binding, every CoraDB data type (including time-zone types, JSON, collections, BLOB/CLOB and OIDs), TLS, multiple brokers tried in order, with load balancing, timeouts and query cancel, batches, savepoints, schema information, and safe reconnection (a write that may already have run is never sent twice).
Install
Section titled “Install”Requires PHP 8.2 or newer (64-bit). No extension is required; openssl is needed only for TLS connections.
composer require coradb/coradbConnect
Section titled “Connect”<?phprequire 'vendor/autoload.php';
use CoraDB\Connection;
$conn = Connection::open('coradb://dba:@localhost:33000/e-commerce');echo $conn->getServerVersion(), PHP_EOL; // e.g. 1.0.0.1586Connection::open() also accepts an options array, a ConnectionOptions object, or the CCI-style URL used by cubrid_connect_with_url():
$conn = Connection::open([ 'host' => 'db1:33000,db2:33000', // tried in order 'database' => 'e-commerce', 'user' => 'dba', 'password' => '', 'connect_timeout' => 5, // seconds, for the whole connect 'read_timeout' => 60,]);
$conn = Connection::open('cci:CoraDB:localhost:33000:e-commerce:dba::?altHosts=db2:33000&loginTimeout=5000');Main options (all are listed in the API reference):
| Option | Default | Meaning |
|---|---|---|
host, port |
localhost, 33000 |
One broker or a list host:port,host2:port tried in order. |
database |
Required | Database name. |
user, password |
public, empty |
Credentials. |
connect_timeout |
30 s |
Limit for the whole connect, across hosts and retries. |
read_timeout |
none | Socket read timeout; when it expires the query is cancelled and the session closed. |
query_timeout |
none | Server-side limit for each query. |
ssl, ssl_verify |
false, false |
TLS to an SSL broker; certificate verification. |
connect_retries, load_balance |
0, false |
Extra rounds over the host list; shuffle the hosts. |
autocommit |
true |
Initial auto-commit mode. |
Run queries
Section titled “Run queries”Parameters are sent typed and bound on the server, never spliced into the SQL text.
$stmt = $conn->prepare('SELECT name, unit_price FROM product WHERE unit_price > ? ORDER BY unit_price DESC LIMIT 3');$stmt->execute([90]);foreach ($stmt as $row) { // rows are associative arrays by default echo $row['name'], ': ', $row['unit_price'], PHP_EOL;}$stmt->close();
$changed = $conn->execute('UPDATE product SET units_in_stock = ? WHERE id = ?', [25, 1379]); // affected rows$all = $conn->query('SELECT code, name FROM countries ORDER BY name')->fetchAll();A graph query is an ordinary statement:
$top = $conn->query( 'SELECT b.name AS brand, COUNT(cu) AS followers FROM MATCH (cu:customer)-[:follows]->(b:brand) GROUP BY b.name ORDER BY followers DESC LIMIT ?', [3])->fetchAll();// [['brand' => 'Nike', 'followers' => 209], ['brand' => 'Adidas', 'followers' => 132], ['brand' => 'Puma', 'followers' => 94]]Fetch modes: FetchMode::ASSOC (default), NUM, BOTH, OBJECT. NUMERIC values are returned as exact strings ('263.50'), dates and times as strings ('2025-12-31'), collections as lists, BLOB/CLOB as Lob handles.
Transactions
Section titled “Transactions”$conn->setAutoCommit(false);try { $conn->execute('INSERT INTO orders (id, customer_id, order_date, shipping_cost, ship_address) VALUES (?, ?, SYSDATE, ?, ?)', [9001, 5, 4.90, 'Storgatan 1, Luleå']); $conn->savepoint('lines'); $conn->execute('INSERT INTO order_items (order_id, product_id, quantity, discount_pct) VALUES (?, ?, ?, 0)', [9001, 1379, 2]); // $conn->rollbackToSavepoint('lines'); $conn->commit();} catch (\Throwable $e) { $conn->rollback(); throw $e;}As in CCI, changing the auto-commit mode commits an open transaction. setIsolationLevel() and setLockTimeout() set the session's isolation level and lock wait timeout.
Errors
Section titled “Errors”Every error is a CoraDB\Exception\CoraDBException (a RuntimeException): getCode() is the error number (an engine number such as -670, a CAS number -10000…, or a driver number -20000…, the same numbers as the CUBRID extension), getMessage() the text. A lost connection throws ConnectionException; when requestMayHaveRun() is true, the statement may have been executed before the connection broke, and the driver did not repeat it.
use CoraDB\Exception\CoraDBException;
try { $conn->execute('INSERT INTO countries (code, name) VALUES (?, ?)', ['FRA', 'France']);} catch (CoraDBException $e) { printf("[%d] %s\n", $e->getCode(), $e->getMessage()); // unique key violation}Migrating from the CUBRID PHP extension
Section titled “Migrating from the CUBRID PHP extension”The coradb_* functions are the extension's procedural API renamed: replace cubrid_ with coradb_ and CUBRID_ with CORADB_, and load Composer's autoloader. All 93 functions and their arguments and return values are kept.
require 'vendor/autoload.php';
$conn = coradb_connect('localhost', 33000, 'e-commerce', 'dba', '');$req = coradb_prepare($conn, 'SELECT name FROM product WHERE unit_price > ?');coradb_bind($req, 1, 90);coradb_execute($req);while ($row = coradb_fetch_assoc($req)) { echo $row['name'], PHP_EOL;}coradb_close_request($req);coradb_close($conn);The differences from the extension are listed in the API reference. The PDO driver of the CUBRID era is not continued; use CoraDB\Connection.
API reference
Section titled “API reference”The full API — ConnectionOptions, Connection, Statement, data types, batches, schema information, LOBs, objects and collections, errors, enums and the coradb_* functions — is in the PHP driver API reference.