LibSQL has 4 types of connections to interact with the database: In-Memory Connection, Local Connection, Remote Connection, and Remote Replica Connection (Embedded Replica).

In-Memory Connection

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

Local Connection

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

If you want to create Remote Connection or Remote Replica (Embedded Replica) Connection, you will need an existing database to continue. If you donโ€™t have one, create one.

Get the database URL:

turso db show --url <database-name>

Get the database authentication token:

turso db tokens create <database-name>

If you use .env file, assign credentials to the environment variables inside .env.

TURSO_DATABASE_URL=
TURSO_AUTH_TOKEN=

Remote Connection

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

Remote Replica (Embedded Replica) Connection

$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'       => \Darkterminal\LibSQL\DBAL\Driver::class,
];