Skip to content

Latest commit

 

History

History
46 lines (31 loc) · 1.26 KB

File metadata and controls

46 lines (31 loc) · 1.26 KB

In-Memory Connection

An in-memory connection creates a temporary database stored entirely in memory. This database disappears when the script ends.


Example

<?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;
}

When to Use

  • Unit testing
  • Temporary datasets
  • Caching scenarios where persistence isn’t needed

Next Steps