Familiar DBAL API
Use executeStatement, executeQuery, transactions, schema tools, and parameter binding through Doctrine DBAL.
libSQL · Doctrine DBAL · Turso
A Doctrine DBAL 4 driver for libSQL/Turso built on the native PHP extension. Use familiar DBAL APIs for local files, remote Turso databases, embedded replicas, and offline-write workflows.
use Doctrine\DBAL\DriverManager;
use Turso\Doctrine\DBAL\Driver;
$conn = DriverManager::getConnection([
'url' => 'database.sqlite',
'driverClass' => Driver::class,
]);
$conn->executeStatement(
'INSERT INTO users (name) VALUES (?)',
['Ada']
);
Why this driver
Keep using Doctrine DBAL APIs while the driver handles libSQL connection modes, transactions, result iteration, and binary transport quirks.
Use executeStatement, executeQuery, transactions, schema tools, and parameter binding through Doctrine DBAL.
Run in-memory, local file, remote Turso, or embedded replica mode. Enable offline writes for sqld or Turso Cloud flavors.
Test suite and Docker proof harnesses verify real DBAL flows, migrations, transactions, and offline-write behavior.
Connection modes
The driver selects a connection mode from url, sync_url, and auth options. You can move from local dev to remote or replica without changing your DBAL code style.
Fast ephemeral database for tests and local scripts. url: ':memory:'.
SQLite/libSQL file on disk. Use .db or .sqlite path.
Connect directly to Turso/libSQL over HTTP with sync_url and auth_token.
Local file synced with remote primary. Supports sync_interval and read-your-writes.
Journal writes locally with sqld_offline_mode + offline_writes, then sync.
Journaled writes against Turso Cloud with offline_writes and embedded replica bootstrap sync.
DBAL transactions map to libSQL transaction handles with read/write behavior inside tx.
Binary parameters round-trip through BlobCodec marker transport to avoid extension text-binding limits.
Install
Install the Composer package, enable the libSQL PHP extension, and pass Turso\Doctrine\DBAL\Driver as driverClass.
Require tursodatabase/turso-doctrine-dbal in a PHP 8.2+ project with Doctrine DBAL 4.
Install libsql_php from turso-client-php releases or Laravel installer, then verify with php -m | grep libsql.
Use driverClass => Turso\Doctrine\DBAL\Driver::class and pick local, remote, replica, or offline-write params. See the user manual.
$ composer require tursodatabase/turso-doctrine-dbal
# verify extension
$ php -m | grep libsql
# run tests in this repo
$ composer install && ./vendor/bin/phpunit
The user manual covers configuration, connection modes, DBAL usage, transactions, offline writes, verification harnesses, limitations, troubleshooting, and API reference.