Prerequisites
Before you start, make sure you:
Download the latest build extension/driver binary you can see at Release page. It's available for:
Now, LibSQL
class is available in your PHP environment! You can use it everywhere in your PHP project 🎉
Configure database credentials
Get the database URL:
turso db show --url <database-name>
Get the database authentication token:
turso db tokens create <database-name>
Assign credentials to the environment variables inside .env
.
TURSO_DATABASE_URL=
TURSO_AUTH_TOKEN=
Save this later when you need to connect to Remote and Embedded Replica
Create PHP Project
Create new directory:
mkdir your-awesome-php-project
cd your-awesome-php-project
Install Turso Doctrine DBAL
composer require tursodatabase/turso-doctrine-dbal
Configure database connection
Setup the environment variable in your Laravel application, choose what the type connection you need.
$params = [
"url" => ":memory:",
'driverClass' => \Turso\Doctrine\DBAL\Driver::class,
];
Other environment variables (Embedded Replica Only)
Integer value representing synchronization interval in seconds (optional, default: 5
).
Boolean value indicating whether to read your writes (optional, default: true
).
String value for encryption purposes (optional, default: empty).
Project Structure Example
src/
├── helpers.php
└── Todo.php
vendor/
composer.json
composer.lock
todo # todo executable
Here you simple php todo cli + Doctrine BDAL
#!/usr/bin/env php
<?php
use Turso\Todo\CLI\Todo;
require_once __DIR__ . '/vendor/autoload.php';
$header = 'TODO CLI + TURSO';
echo $header . PHP_EOL;
function main()
{
echo str_repeat('-', WIDTH - 18) . " Todo CLI - " . VERSION . PHP_EOL;
while (true) {
echo "[L] List | [A] Add | [E] Edit | [D] Delete | [X] Exit" . PHP_EOL;
echo "command: ";
$choice = trim(fgets(STDIN));
$app = new Todo();
switch (strtolower($choice)) {
case 'l':
$app->listTodos();
break;
case 'a':
$app->addTodo();
clearScreen();
break;
case 'e':
$app->editTodo();
clearScreen();
break;
case 'd':
$app->deleteTodo();
clearScreen();
break;
case 'x':
exit("Goodbye!" . PHP_EOL);
default:
echo "Invalid choice." . PHP_EOL;
clearScreen();
}
}
echo PHP_EOL;
}
main();
Your PHP Application Ready!
Examples