-
Notifications
You must be signed in to change notification settings - Fork 0
/
library.php
executable file
·48 lines (39 loc) · 1.25 KB
/
library.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
<?php
class Library {
public function __construct() {
$this->db = new PDO('mysql:host=localhost;dbname=phpdatabase', 'root', 'root');
}
public function addBook($kb, $jb, $pengbu, $penerbu) {
$sql = "INSERT INTO buku (kodebuku, judulubuku, pengarang, penerbit) VALUES('$kb', '$jb', '$pengbu', '$penerbu')";
$query = $this->db->query($sql);
if (!$query) {
return "Gagal";
} else {
return "Berhasil";
}
}
public function editBook($kb) {
$sql = "SELECT * FROM buku WHERE kodebuku='$kb'";
$query = $this->db->query($sql);
return $query;
}
public function updateBook($kb, $jb, $pengbu, $penerbu) {
$sql = "UPDATE buku SET judulubuku='$jb', pengarang='$pengbu', penerbit='$penerbu' WHERE kodebuku='$kb'";
$query = $this->db->query($sql);
if (!$query) {
return "Gagal";
} else {
return "Berhasil";
}
}
public function showBooks() {
$sql = "SELECT * FROM buku";
$query = $this->db->query($sql);
return $query;
}
public function deleteBook($kb) {
$sql = "DELETE FROM buku WHERE kodebuku='$kb'";
$query = $this->db->query($sql);
}
}
?>