An in-memory connection creates a temporary database stored entirely in memory. This database disappears when the script ends.
<?php
// Connect to an in-memory database
$libsql = new LibSQL("file::memory:");
// Create schema
$libsql->execute("CREATE TABLE sessions (id INTEGER PRIMARY KEY, token TEXT)");
// Insert data
$libsql->execute("INSERT INTO sessions (token) VALUES (?)", ["abc123"]);
// 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;
}- Unit testing
- Temporary datasets
- Caching scenarios where persistence isn’t needed
- 👉 Remote Connection — Connect libSQL remotely
- 👉 Embedded Replica Connection — Connect libSQL with Embedded Replica
- 👉 Offline Writes (Turso) Connection — Connect libSQL with Offline Writes abillity from (with Turso)
- 👉 Offline Writes (libSQL Server/sqld) Connection — Connect libSQL with Offline Writes abillity from (with libSQL Server - self-host)