1. Go to this page and download the library: Download clue/reactphp-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/ */
clue / reactphp-sqlite example snippets
ory = new Clue\React\SQLite\Factory();
$db = $factory->openLazy(__DIR__ . '/users.db');
$db->exec('CREATE TABLE IF NOT EXISTS user (id INTEGER PRIMARY KEY AUTOINCREMENT, name STRING)');
$name = 'Alice';
$db->query('INSERT INTO user (name) VALUES (?)', [$name])->then(
function (Clue\React\SQLite\Result $result) use ($name) {
echo 'New ID for ' . $name . ': ' . $result->insertId . PHP_EOL;
},
function (Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
}
);
$db->quit();
$factory = new Clue\React\SQLite\Factory();
// advanced usage: pass custom PHP binary to use when spawning child process
$factory = new Clue\React\SQLite\Factory(null, '/usr/bin/php6.0');
// advanced usage: empty binary path runs blocking SQLite in same process
$factory = new Clue\React\SQLite\Factory(null, '');
$db->exec('CREATE TABLE test ...');
$db->exec('INSERT INTO test (id) VALUES (1)');
$db->exec($query)->then(function (Result $result) {
// this is an OK message in response to an UPDATE etc.
if ($result->insertId !== 0) {
var_dump('last insert ID', $result->insertId);
}
echo 'Query OK, ' . $result->changed . ' row(s) changed' . PHP_EOL;
}, function (Exception $error) {
// the query was not executed successfully
echo 'Error: ' . $error->getMessage() . PHP_EOL;
});
$db->query('CREATE TABLE test ...');
$db->query('INSERT INTO test (id) VALUES (1)');
$db->query($query)->then(function (Result $result) {
if (isset($result->rows)) {
// this is a response to a SELECT etc. with some rows (0+)
print_r($result->columns);
print_r($result->rows);
echo count($result->rows) . ' row(s) in set' . PHP_EOL;
} else {
// this is an OK message in response to an UPDATE etc.
if ($result->insertId !== 0) {
var_dump('last insert ID', $result->insertId);
}
echo 'Query OK, ' . $result->changed . ' row(s) changed' . PHP_EOL;
}
}, function (Exception $error) {
// the query was not executed successfully
echo 'Error: ' . $error->getMessage() . PHP_EOL;
});
$db->query('SELECT * FROM user WHERE id > ?', [$id]);
$db->query('SELECT * FROM user WHERE id > :id', ['id' => $id]);