-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
009-execute.php
31 lines (22 loc) · 936 Bytes
/
009-execute.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
<?php
// Create a new LibSQL instance
$db = new LibSQL("libsql:dbname=database.db");
// SQL statement with positional parameters
$stmt = "INSERT INTO users (name, age) VALUES (?, ?)";
$parameters = ["John Doe", 30];
$rowsAffected = $db->execute($stmt, $parameters);
echo "Inserted $rowsAffected rows." . PHP_EOL;
$results = $db->query("SELECT * FROM users");
foreach ($results['rows'] as $row) {
echo "ID: " . $row['id'] . ", Name: " . $row['name'] . ", Age: " . $row['age'] . PHP_EOL;
}
// SQL statement with named parameters
$stmt = "UPDATE users SET name = :name WHERE id = :id";
$parameters = [":name" => "Jane Doe", ":id" => 6];
$rowsAffected = $db->execute($stmt, $parameters);
echo "Updated $rowsAffected rows." . PHP_EOL;
$results = $db->query("SELECT * FROM users");
foreach ($results['rows'] as $row) {
echo "ID: " . $row['id'] . ", Name: " . $row['name'] . ", Age: " . $row['age'] . PHP_EOL;
}
$db->close();