-
Notifications
You must be signed in to change notification settings - Fork 3
/
SearchClass.php
43 lines (36 loc) · 1.04 KB
/
SearchClass.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
<?php
$dsn = "mysql:host=localhost;dbname=library_v8";
$user = "root";
$pass = "";
$opt = [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION];
$pdo = new PDO($dsn, $user, $pass, $opt);
class Search {
private $conn;
public function __construct(PDO $pdo) {
$this->conn = $pdo;
}
public function search($pdo, $bookname) {
try {
$stmt = $pdo->prepare("Select * from book where title = ?");
$stmt ->execute([$bookname]);
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
$result = $stmt->fetchAll();
if ($result == null) {
// echo '<pre>'; print_r($result); echo '</pre>';
echo '<div class="row justify-content-center align-items-center">';
echo "No results for $bookname.";
echo '</div>';
} else {
echo '<div class="row justify-content-center align-items-center">';
echo '<pre>'; print_r($result); echo '</pre>';
echo '</div>';
}
} catch (PDOException $e)
{
$e->getMessage();
die("Search Error");
}
}
}
//$search = new Search($pdo);
//$search->search($pdo, "ABC");