PHP code example of turso / libsql

1. Go to this page and download the library: Download turso/libsql library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

turso / libsql example snippets




use Libsql\Database;

$db = new Database(
    path: 'local.db',
    url: getenv('TURSO_DATABASE_URL'),
    authToken: getenv('TURSO_AUTH_TOKEN'),
    syncInterval: 1000
);

$conn = $db->connect();

$createUsers = "
  CREATE TABLE IF NOT EXISTS users (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      name TEXT
  );
  INSERT INTO users (name) VALUES ('Iku');
";

$conn->executeBatch($createUsers);

$conn->query("SELECT * FROM users WHERE id = ?", [1])->fetchArray();