-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlite-test.php
More file actions
45 lines (41 loc) · 1.18 KB
/
sqlite-test.php
File metadata and controls
45 lines (41 loc) · 1.18 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>SQLite Test</title>
</head>
<body>
<h1>Testing...</h1>
<!-- Connect to the database -->
<?php
$pdo = new PDO('sqlite:books.db');
$statement = $pdo->query("SELECT * FROM books WHERE LOWER(title) LIKE lower('%HARRY POTTER%')");
while($row = $statement->fetch(\PDO::FETCH_ASSOC))
{
echo "<p>" . htmlspecialchars($row['title']) . " | " .
htmlspecialchars($row['author']) . " | " .
htmlspecialchars($row['genre']) . " | " .
htmlspecialchars($row['age']) . " </p>";
}
?>
<!-- Reading Data from the Table
<?php
$sql='SELECT * FROM table1 WHERE genre IS "fantasy"';
$result = $db->query($sql) or die("Query failed");
echo "<p>associative array: array uses named field</p>";
while ($row = $result->fetchArray())
{
echo "<p>" . htmlspecialchars($row['title']) . " | " .
htmlspecialchars($row['author']) . " | " .
htmlspecialchars($row['genre']) . " | " .
htmlspecialchars($row['age']) . " </p>";
}
?>
<?php
$statement = $pdo->query("SELECT * FROM books WHERE genre IS 'fantasy'");
$rows = $statement->fetchAll(PDO::FETCH_ASSOC);
echo "<pre>";
print_r($rows);
echo "</pre>";
?> -->
</body>
</html>