LibSQL PHP Driver/Extension/Whatever

LibSQL PHP Driver/Extension/Whatever designed to seamlessly handle local, remote, and remote replica/embedded replica connections, offering versatility and efficiency for your applicationโ€™s data management needs. With an intuitive interface and flexible configuration options, LibSQL empowers developers to effortlessly integrate database operations into your PHP projects.

LibSQL Extension

LibSQL Extension for PHP GitHub Repository


libSQL is an open source, open contribution fork of SQLite, created and maintained by Turso. We aim to evolve it to suit many more use cases than SQLite was originally designed for, and plan to use third-party OSS code wherever it makes sense.

libSQL is licensed under an Open Source License, and we adhere to a clear Code of Conduct.


This extension build using Rust Programming Language and using ext-php-rs framework to create new PHP Extension.

Features

  • Embedded replicas that allow you to have replicated database inside your app.
  • libSQL server for remote SQLite access, similar to PostgreSQL or MySQL
  • Supports Rust, JavaScript, Python, Go, PHP, and more.

Download

Download the latest build extension/driver binary you can see at Release page. Itโ€™s available for:

  • Linux
  • Mac/Darwin
  • Windows (still struggle, but you need to try use WSL)

Installation

  • ๐Ÿ“ฆ 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

Check on your console/terminal

$ php --m | grep libsql
liblibsql_php

Now, you can use LibSQL class in your PHP code!

Quickstart

Remember, this is not a library or ORM, this is the native extension for LibSQL.

<?php

// Instanciate
$db = new LibSQL(":memory:");

// Create table
$sql = "CREATE TABLE IF NOT EXISTS users (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  name TEXT, 
  age INTEGER
)";
$db->execute($sql);

// Insert data
$db->execute("INSERT INTO users (name, age) VALUES ('Diana Hooggan', 24)");

// Read data
$results = $db->query("SELECT * FROM users");

// Display data
foreach ($results['rows'] as $row) {
    echo "ID: " . $row['id'] . ", Name: " . $row['name'] . ", Age: " . $row['age'] . "\n";
}

// Close database
$db->close();

Thatโ€™s it! Itโ€™s feel like SQLite but it will more powerful ๐Ÿš€

Was this page helpful?