SQLite for Production. Powered by libSQL and libSQL Extension for PHP.
Turso · Quickstart · Examples · Docs · Discord · Blog & Tutorials
LibSQL is a fork of SQLite and this package is #1 LibSQL Driver that run natively using LibSQL Native Extension/Driver/Whatever and support Doctrine DBAL.
Before using this package, you need to install and configure LibSQL Native Extension for PHP. You can download from LibSQL Extension - Release
- 📦 Extract the archive
- 🗃 Locate somewhere in your machine
- 💽 Copy a relative path that address that extension/driver
- 📂 Open
php.ini
search;extension
if you using nano (ctrl+w) then searching for it - 📝 add in the next-line
extension=liblibsql_php.so
(in Linux) without;
at the begining
composer require tursodatabase/turso-doctrine-dbal
LibSQL has 4 types of connections to interact with the database: In-Memory Connection, Local Connection, Remote Connection, and Remote Replica Connection (Embedded Replica).
$params = [
"url" => ":memory:",
'driverClass' => \Turso\Doctrine\DBAL\Driver::class,
];
$params = [
"url" => "database.db",
'driverClass' => \Turso\Doctrine\DBAL\Driver::class,
];
If you want to create Remote Connection or Remote Replica (Embedded Replica) Connection, you will need an existing database to continue. If you don’t have one, create one.
Get the database URL:
turso db show --url <database-name>
Get the database authentication token:
turso db tokens create <database-name>
If you use .env
file, assign credentials to the environment variables inside .env
.
TURSO_DATABASE_URL=
TURSO_AUTH_TOKEN=
$params = [
"auth_token" => "<your-database-auth-token-from-turso>",
"sync_url" => "<your-database-url-from-turso>",
'driverClass' => \Turso\Doctrine\DBAL\Driver::class,
];
$params = [
"url" => "database.db",
"auth_token" => "<your-database-auth-token-from-turso>",
"sync_url" => "<your-database-url-from-turso>",
"sync_interval" => 5, // Optional, default is: 5 in seconds
"read_your_writes" => true, // Optional, default is: true
"encryption_key" => "", // Optional, default is: empty
'driverClass' => \Turso\Doctrine\DBAL\Driver::class,
];
use Doctrine\DBAL\DriverManager;
require_once __DIR__ . '/vendor/autoload.php';
$params = [
"url" => ":memory:",
'driverClass' => \Turso\Doctrine\DBAL\Driver::class,
];
$db = DriverManager::getConnection($params);
$createTable = "CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
age INTEGER
)";
$db->executeStatement($createTable);
$insertUsers = <<<SQL
INSERT INTO users (name, age) VALUES ('Budi Dalton', 49);
INSERT INTO users (name, age) VALUES ('Sujiwo Tedjo', 50);
SQL;
$db->getNativeConnection()->executeBatch($insertUsers);
$result = $db->executeQuery("SELECT * FROM users")->fetchAllAssociative();
var_dump($result);
$db->close();
- Turso Quickstart — Learn how create and connect your first database.
- SDK Quickstart — Learn how to install and execute queries using the libSQL client.
- SDK Reference — Dive deeper with the libSQL SDK reference and examples.
Turso is a SQLite-compatible database built on libSQL, the Open Contribution fork of SQLite. It enables scaling to hundreds of thousands of databases per organization and supports replication to any location, including your own servers, for microsecond-latency access.
Learn more about what you can do with Turso: