-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathinsert.php
More file actions
23 lines (18 loc) · 684 Bytes
/
insert.php
File metadata and controls
23 lines (18 loc) · 684 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
require __DIR__ . '/../vendor/autoload.php';
$factory = 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)'
)->then(null, function (Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
});
$n = isset($argv[1]) ? $argv[1] : 1;
for ($i = 0; $i < $n; ++$i) {
$db->exec("INSERT INTO user (name) VALUES ('Alice')")->then(function (Clue\React\SQLite\Result $result) {
echo 'New row ' . $result->insertId . PHP_EOL;
}, function (Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
});
}
$db->quit();