-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.php
More file actions
77 lines (62 loc) · 1.9 KB
/
class.php
File metadata and controls
77 lines (62 loc) · 1.9 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
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
<?php
class Mahasiswa{
private $db;
public $npm;
public $nama;
public $semester;
public $umur;
public function __construct($db) {
$this->db = $db;
}
public function select() {
$query = "select * from mahasiswa order by npm asc";
$stmt = $this->db->query($query);
return $stmt;
}
public function insert() {
$query = "INSERT INTO mahasiswa (npm, nama, semester, umur) VALUES(?,?,?,?)";
$stmt = $this->db->prepare($query);
$par = array($this->npm, $this->nama, $this->semester, $this->umur);
$ret = $stmt->execute($par);
if($ret) {
return true;
} else {
$errors = $stmt->errorInfo();
echo($errors[2]);
return false;
}
}
public function update() {
$query = "update mahasiswa set nama =?, semester=?, umur=? where npm = ?";
$stmt = $this->db->prepare($query);
$par = array($this->nama, $this->semester, $this->umur,$this->npm);
$ret = $stmt->execute($par);
if($ret) {
return true;
} else {
$errors = $stmt->errorInfo();
echo($errors[2]);
return false;
}
}
public function delete() {
$query = "delete from mahasiswa where npm =?";
$stmt = $this->db->prepare($query);
$par = array($this->npm);
$ret = $stmt->execute($par);
if($stmt) {
return true;
} else {
$errors = $stmt->errorInfo();
echo($errors[2]);
return false;
}
}
public function getDataMahasiswa() {
$query = "select * from mahasiswa where npm = ?";
$stmt = $this->db->prepare($query);
$par = array($this->npm);
$stmt->execute($par);
return $stmt->fetchObject();
}
}