PHP code example of venndev / vosaka-libsql

1. Go to this page and download the library: Download venndev/vosaka-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/ */

    

venndev / vosaka-libsql example snippets




osaka\libsql\AsyncMysqlPool;
use vosaka\foroutines\AsyncMain;
use vosaka\foroutines\Launch;
use vosaka\foroutines\Thread;
use vosaka\foroutines\RunBlocking;

#[AsyncMain]
function main(): void
{
    // Initialize the MySQL pool
    $pool = new AsyncMysqlPool(
        host: '127.0.0.1',
        port: 3306,
        user: 'root',
        password: 'password',
        database: 'test_db',
        maxConnections: 20
    );

    // Run concurrent queries
    RunBlocking::new(function () use ($pool) {
        for ($i = 0; $i < 50; $i++) {
            Launch::new(function () use ($pool, $i) {
                // Non-blocking query execution
                $result = $pool->query('SELECT * FROM users WHERE id = ?', [$i % 10 + 1])->await();
                
                // For INSERT/UPDATE/DELETE
                $pool->execute('INSERT INTO logs (message) VALUES (?)', ["Log entry $i"])->await();
            });
        }

        // Clean up
        $pool->closeAll()->await();
    });
}



osaka\libsql\AsyncPgsqlPool;
use vosaka\foroutines\AsyncMain;
use vosaka\foroutines\Launch;
use vosaka\foroutines\Thread;
use vosaka\foroutines\RunBlocking;

#[AsyncMain]
function main(): void
{
    // Initialize the PostgreSQL pool
    $pool = new AsyncPgsqlPool(
        host: '127.0.0.1',
        port: 5432,
        user: 'postgres',
        password: 'password',
        database: 'test_db',
        maxConnections: 20
    );

    RunBlocking::new(function () use ($pool) {
        Launch::new(function () use ($pool) {
            $result = $pool->query('SELECT * FROM users LIMIT 10')->await();
        });
        $pool->closeAll()->await();
    });
}