Local Connection
A local connection is the simplest way to use Turso Client PHP. It stores data in a local SQLite/libSQL file on disk.
Example
<?php
// Connect to a local database file
$libsql = new LibSQL("file:database.db");
// Create a table
$libsql->execute("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)");
// Insert data
$libsql->execute("INSERT INTO users (name) VALUES (?)", ["Alice"]);
// Query
$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
- Prototyping or small projects
- Local development with SQLite semantics
- Applications that donβt need replication or remote access
Next Steps
- π Memory Connection β Connect libSQL in-memory
- π 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)