PHP code example of darkterminal / libsql-driver-laravel
1. Go to this page and download the library: Download darkterminal/libsql-driver-laravel 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/ */
darkterminal / libsql-driver-laravel example snippets
'libsql' => [
'driver' => 'libsql',
'url' => 'file:' . env('DB_DATABASE', database_path('database.sqlite')),
'authToken' => env('DB_AUTH_TOKEN', ''),
'syncUrl' => env('DB_SYNC_URL', ''),
'syncInterval' => env('DB_SYNC_INTERVAL', 5),
'read_your_writes' => env('DB_READ_YOUR_WRITES', true),
'encryptionKey' => env('DB_ENCRYPTION_KEY', ''),
'remoteOnly' => env('DB_REMOTE_ONLY', false),
'database' => null,
'prefix' => '',
],
use Illuminate\Support\Facades\DB;
// Create
DB::connection('libsql')->table('users')->craete([
'name' => 'Budi Dalton',
'email' => '[email protected] '
]);
// Read
DB::connection('libsql')->table('users')->get();
DB::connection('libsql')->table('users')->where('id', 2)->first();
DB::connection('libsql')->table('users')->orderBy('id', 'DESC')->limit(2)->get();
// Update
DB::connection('libsql')->table('users')->where('id', 2)->update(['name' => 'Doni Mandala']);
// Delete
DB::connection('libsql')->table('users')->where('id', 2)->delete();
// Transaction
try {
DB::beginTransaction();
$updated = DB::connection('libsql')->table('users')->where('id', 9)->update(['name' => 'Doni Kumala']);
if ($updated) {
echo "It's updated";
DB::commit();
} else {
echo "Not updated";
DB::rollBack();
}
$data = DB::connection('libsql')->table('users')->orderBy('id', 'DESC')->limit(2)->get();
dump($data);
} catch (\Exception $e) {
DB::rollBack();
echo "An error occurred: " . $e->getMessage();
}
// Sync
DB::connection('libsql')->sync();
bash
php artisan vendor:publish --tag=libsql-driver-laravel