PHP code example of vajexal / amp-sqlite

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

    

vajexal / amp-sqlite example snippets




declare(strict_types=1);

use Amp\Loop;
use Vajexal\AmpSQLite\SQLiteCommandResult;
use Vajexal\AmpSQLite\SQLiteConnection;
use Vajexal\AmpSQLite\SQLiteResultSet;
use Vajexal\AmpSQLite\SQLiteStatement;
use function Vajexal\AmpSQLite\connect;

primary key, name text not null)');
    yield $connection->execute('insert into users (name) values (:name)', [
        ':name' => 'Bob',
    ]);

    /** @var SQLiteResultSet $results */
    $results = yield $connection->query('select * from users');
    while (yield $results->advance()) {
        $row = $results->getCurrent();
        echo "Hello {$row['name']}\n";
    }

    /** @var SQLiteStatement $statement */
    $statement = yield $connection->prepare('update users set name = :name where id = 1');
    /** @var SQLiteCommandResult $result */
    $result = yield $statement->execute([
        ':name' => 'John',
    ]);
    echo "Updated {$result->getAffectedRowCount()} rows\n";
});



declare(strict_types=1);

use Amp\Loop;
use Vajexal\AmpSQLite\SQLiteConnection;
use Vajexal\AmpSQLite\SQLiteTransaction;
use function Vajexal\AmpSQLite\connect;

 exists users');
    yield $connection->execute('create table users (id integer primary key, name text not null)');

    /** @var SQLiteTransaction $transaction */
    $transaction = yield $connection->beginTransaction();
    yield $transaction->execute('insert into users (name) values (:name)', [
        ':name' => 'Bob',
    ]);

    yield $transaction->createSavepoint('change_name');
    yield $transaction->execute('update users set name = :name where id = 1', [
        ':name' => 'John',
    ]);
    yield $transaction->releaseSavepoint('change_name');

    yield $transaction->commit();
});