forked from clue/reactphp-sqlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery.php
More file actions
26 lines (21 loc) · 872 Bytes
/
query.php
File metadata and controls
26 lines (21 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
require __DIR__ . '/vendor/autoload.php';
} else {
require __DIR__ . '/../../vendor/autoload.php';
}
$factory = new Clue\React\SQLite\Factory();
$db = $factory->openLazy(':memory:', null, ['idle' => 0.001]);
$query = isset($argv[1]) ? $argv[1] : 'SELECT 42 AS value';
$args = array_slice(isset($argv) ? $argv : [], 2);
$db->query('SELECT ? AS answer', [42])->then(function (Clue\React\SQLite\Result $result) {
if ($result->columns !== ['answer'] || count($result->rows) !== 1 || $result->rows[0]['answer'] !== 42) {
var_dump($result);
throw new RuntimeException('Unexpected result');
}
$answer = $result->rows[0]['answer'];
echo 'Answer: ' . $answer . PHP_EOL;
})->then(null, function (Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
exit(1);
});