This repository has been archived by the owner on Jun 12, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
104 lines (76 loc) · 3.22 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
use Darkterminal\LibSQLPHPExtension\LibSQLPHP;
use Darkterminal\LibSQLPHPExtension\Utils\TransactionBehavior;
require_once 'vendor/autoload.php';
$db = new LibSQLPHP(path: "file:database.db", url: getenv('TURSO_DATABASE_URL'), token: getenv('TURSO_DATABASE_TOKEN'));
if ($db->is_connected()) {
echo $db->version() . PHP_EOL;
// $db->exec("CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)");
// $db->exec("INSERT INTO users (name) VALUES ('Handoko')");
// $db->exec("INSERT INTO users (name) VALUES ('Karlina')");
// $db->exec("INSERT INTO users (name) VALUES (?)", ["Marlo"]);
// var_dump($db->last_insert_rowid());
// $result = $db->query('SELECT * FROM users');
// echo "Return as raw:" . PHP_EOL;
// var_dump($result->fetchRaw());
// echo json_encode(["name" => "Merlin"]) . PHP_EOL;
// echo "Return as default (LIBSQLPHP_NUM):" . PHP_EOL;
// $users = $result->fetchArray(LIBSQLPHP_NUM);
// var_dump($users);
// foreach ($users as $user) {
// echo $user['name'] . PHP_EOL;
// }
// echo "Return the column count:" . PHP_EOL;
// var_dump($result->numColumns());
// echo "Return the column names:" . PHP_EOL;
// var_dump($result->columName());
// echo "Return the column types:" . PHP_EOL;
// var_dump($result->columnType());
// $stmt = $db->prepare("INSERT INTO persons (name, age) VALUES (:name, @age)");
// // Bind parameters
// $stmt->bindParam(':name', $baz, LIBSQLPHP_TEXT);
// $stmt->bindParam('@age', $foo, LIBSQLPHP_INTEGER);
// $baz = "Sarah";
// $foo = 22;
// $stmt->execute();
// $stmt = $db->prepare("INSERT INTO foo VALUES (?, ?)");
// // Bind parameters
// $stmt->bindValue(1, "baz", LIBSQLPHP_TEXT);
// $stmt->bindValue(2, 5, LIBSQLPHP_INTEGER);
// echo $stmt->paramCount() . PHP_EOL;
// $db->exec("DELETE FROM users WHERE id = 3");
// $changes = $db->changes();
// echo "The DELETE statement removed $changes rows";
// $stmt = $db->prepare('INSERT INTO foo VALUES (?)');
// $age = 18;
// $stmt->bindValue(1, $age, LIBSQLPHP_INTEGER);
// // Check if the statement is read-only
// if ($stmt->readOnly()) {
// echo "The statement is read-only.\n";
// } else {
// echo "The statement is not read-only.\n";
// }
// $result = $db->querySingle("SELECT name FROM users WHERE id = 1");
// $result2 = $db->querySingle("SELECT name FROM users WHERE id = 2", true);
// var_dump($result);
// var_dump($result2);
// $operations_successful = false;
// $tx = $db->transaction(TransactionBehavior::Deferred);
// $tx->exec("INSERT INTO users (name) VALUES (?)", ["Emanuel"]);
// $tx->exec("INSERT INTO users (name) VALUES (?)", ["Darren"]);
// if ($operations_successful) {
// $tx->commit();
// echo "Commit the changes" . PHP_EOL;
// } else {
// $tx->rollback();
// echo "Rollback the changes" . PHP_EOL;
// }
// $db->execute_batch("
// BEGIN;
// CREATE TABLE foo(x INTEGER);
// CREATE TABLE bar(y TEXT);
// COMMIT;
// ");
// $db->exec("INSERT INTO users (name, email) VALUES ('Cintia Messa', 'cintia@duck.com')");
}
$db->close();