initorm/dbal is a thin layer over PDO. It does not parse SQL, build
queries, or model tables — that is the job of higher layers in the InitORM
stack (initorm/query-builder, initorm/database, initorm/orm). What it
gives you is:
- A
Connectionthat lazily instantiates PDO from a credentials array. - A
DataMapperthat wraps eachPDOStatementand exposes a small, fluent API for binding values and fetching results.
This page walks through the smallest useful program end-to-end. Every snippet runs unmodified against SQLite in-memory.
composer require initorm/dbalRequirements: PHP 8.0+, ext-pdo, and the driver extension for your
database (pdo_mysql, pdo_pgsql, or pdo_sqlite).
use InitORM\DBAL\Connection\Connection;
$db = new Connection([
'driver' => 'sqlite',
'database' => ':memory:',
'charset' => '', // sqlite has no charset concept
]);No connection is opened yet — Connection only instantiates PDO when you
call getPDO(), query(), or any forwarded PDO method.
$db->getPDO()->exec('CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)');
$db->query(
'INSERT INTO users (name) VALUES (:name)',
['name' => 'Alice']
);
$user = $db->query('SELECT * FROM users WHERE id = :id', ['id' => 1])
->asAssoc()
->row();
// ['id' => 1, 'name' => 'Alice']Three things happen on the read:
query()prepares the statement and binds:idwithPARAM_INT.- It returns a
DataMapper. asAssoc()sets the fetch mode;row()returns the next row (ornull).
- 02 · Connection — credentials, lifecycle, cloning.
- 03 · Querying — parameters, prepare options, errors.
- 04 · DataMapper — fetch modes, binding, forwarding.