PHP code example of tursodatabase / turso-doctrine-dbal

1. Go to this page and download the library: Download tursodatabase/turso-doctrine-dbal 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/ */

    

tursodatabase / turso-doctrine-dbal example snippets


$params = [
    "url"               => ":memory:",
    'driverClass'       => \Turso\Doctrine\DBAL\Driver::class,
];

$params = [
    "url"               => "database.db",
    'driverClass'       => \Turso\Doctrine\DBAL\Driver::class,
];

$params = [
    "auth_token"        => "<your-database-auth-token-from-turso>",
    "sync_url"          => "<your-database-url-from-turso>",
    'driverClass'       => \Turso\Doctrine\DBAL\Driver::class,
];

$params = [
    "url"               => "database.db",
    "auth_token"        => "<your-database-auth-token-from-turso>",
    "sync_url"          => "<your-database-url-from-turso>",
    "sync_interval"     => 5,    // Optional, default is: 5 in seconds
    "read_your_writes"  => true, // Optional, default is: true
    "encryption_key"    => "",   // Optional, default is: empty
    'driverClass'       => \Turso\Doctrine\DBAL\Driver::class,
];

use Doctrine\DBAL\DriverManager;

    => ":memory:",
    'driverClass'       => \Turso\Doctrine\DBAL\Driver::class,
];

$db = DriverManager::getConnection($params);

$createTable = "CREATE TABLE IF NOT EXISTS users (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT,
    age INTEGER
)";
$db->executeStatement($createTable);

$insertUsers = <<<SQL
INSERT INTO users (name, age) VALUES ('Budi Dalton', 49);
INSERT INTO users (name, age) VALUES ('Sujiwo Tedjo', 50);
SQL;

$db->getNativeConnection()->executeBatch($insertUsers);

$result = $db->executeQuery("SELECT * FROM users")->fetchAllAssociative();
var_dump($result);
$db->close();