Skip to content

Turso + PHP - libSQL Extension for PHP (Community SDK)

License

Notifications You must be signed in to change notification settings

tursodatabase/turso-client-php

Repository files navigation

Turso + PHP

Turso Client PHP

A community-driven PHP SDK for libSQL — the SQLite fork designed for the edge, replication, and production workloads.

MIT License Discord Contributors Downloads Release


Overview

turso-client-php (libSQL Extension) brings the power of libSQL to PHP applications. It’s more than just SQLite — with built-in support for remote connections, replicas, sync, offline writes, and transactions.

✨ Key features:

  • 🚀 Works with SQLite and libSQL
  • 🔌 Multiple connection modes
    • local
    • in-memory
    • remote
    • remote replica
    • offline-writes also support for libsql-server (sqld)
  • 🔒 Transactions, prepared statements, and batch execution
  • 🐘 Native PHP extension built in Rust for speed
  • 🐳 Easy setup with turso-php-installer

Supported Versions

PHP Versions Build Versions
8.1 TS / NTS
8.2 TS / NTS
8.3 TS / NTS
8.4 TS / NTS
8.5 TS / NTS

TS = Thread Safe, NTS = Non Thread Safe
✅ Supported on Linux, macOS, Windows, WSL


Quick Start

<?php

$libsql = new LibSQL("file:example.db");

// Create a table
$libsql->execute("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)");

// Insert a row
$libsql->execute("INSERT INTO users (name) VALUES (?)", ["Alice"]);

// Query data
$result = $libsql->query("SELECT * FROM users");
$rows = $result->fetchArray(LibSQL::LIBSQL_ASSOC);

foreach ($rows as $row) {
    echo $row["id"] . " - " . $row["name"] . PHP_EOL;
}

➡️ See Quick Start Guide for more details.


Installation

Installing the extension should be not complecated, it's easy and like using Composer Package Installer.

Auto Installer turso-php-installer is a Composer package capable of executing various commands related to libSQL, simplifying the development process, and making it easier to simulate in a local environment.
composer global require darkterminal/turso-php-installer

Add the binary to your PATH:

export COMPOSER_BIN_DIR=$(composer config --global home)/vendor/bin

Run the installer in interactive mode:

turso-php-installer install

Or non-interactive (example for PHP 8.3):

turso-php-installer install -n --php-version=8.3

📦 For alternative methods (manual build, Docker, ARM64), check Installation Docs.


Documentation

👉 Full documentation available in the docs/ folder.


Development

Requirements:

  • PHP ≥ 8.1
  • Rust nightly toolchain
  • Git
  • Docker & Docker Compose (for containerized dev)

Build from source:

git clone git@github.com:<username>/turso-client-php.git
cd turso-client-php
rustup toolchain install nightly
rustup default nightly
cargo build

Or inside Docker:

make compose/up
# or for arm64
make compose-arm64/up

For available commands:

make help

Community & Support


Contributors

Contributors


License

This project is open-sourced under the MIT License.