Skip to content

Latest commit

 

History

History
48 lines (32 loc) · 1.38 KB

File metadata and controls

48 lines (32 loc) · 1.38 KB

Remote Connection

A remote connection allows PHP applications to connect to a Turso or libSQL server running remotely. This is how you scale beyond local SQLite.


Example

<?php

// Replace with your Turso/libSQL server URL and auth token
$dbUrl = "libsql://my-database.turso.io";
$authToken = "your_auth_token";

// Connect to remote database
$libsql = new LibSQL("libsql:dbname=$dbUrl;authToken=$authToken");

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

// Insert and query
$libsql->execute("INSERT INTO products (name) VALUES (?)", ["Laptop"]);

$result = $libsql->query("SELECT * FROM products");
$rows = $result->fetchArray(LibSQL::LIBSQL_ASSOC);

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

When to Use

  • Production environments
  • Multi-region deployments with Turso
  • Applications needing centralized storage

Next Steps