-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest.php
60 lines (37 loc) · 1.24 KB
/
test.php
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
$db = new LibSQL(":memory:");
if (!$db) {
throw new Exception("Database Not Connected!");
}
$createUsers = <<<STMT
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
age INTEGER
);
INSERT INTO users (name, age) VALUES ('Bilal Ali Maftullah', 21);
INSERT INTO users (name, age) VALUES ('Lisa Nur Amelia', 22);
STMT;
$db->executeBatch($createUsers);
echo $db->totalChanges() . PHP_EOL;
echo $db->lastInsertedId() . PHP_EOL;
$users = $db->query("SELECT * FROM users")->fetchArray(LibSQL::LIBSQL_LAZY);
do {
$user = $users->current();
echo "Age: {$user['age']}, Name: {$user['name']}\n";
$users->next();
} while ($users->valid());
$stmt = $db->prepare("SELECT * FROM users WHERE age = ?1");
$stmt->bindPositional([21]);
var_dump($stmt->query()->fetchArray(LibSQL::LIBSQL_ASSOC));
$stmt = $db->prepare("DELETE FROM users WHERE age = :age");
$stmt->bindNamed([':age' => 22]);
var_dump($stmt->execute());
$stmt = $db->prepare("SELECT * FROM users");
$users =$stmt->query()->fetchArray(LibSQL::LIBSQL_LAZY);
do {
$user = $users->current();
echo "Age: {$user['age']}, Name: {$user['name']}\n";
$users->next();
} while ($users->valid());
$db->close();