-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabaseProcess.php
More file actions
68 lines (57 loc) · 2.05 KB
/
DatabaseProcess.php
File metadata and controls
68 lines (57 loc) · 2.05 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
<?php
class DatabaseProcess {
private $servername;
private $username;
private $password;
private $dbname;
private $conn;
private $isAlreadyInitialized;
public function __construct() {
$this->servername = "localhost";
$this->username = "revw4882_Rinda";
$this->password = "d4xCtsNmjLZ65PG";
$this->dbname = "revw4882_Rinda_Introduction-to-Data-and-Information-Management";
$this->isAlreadyInitialized = false;
}
public function initializeDatabaseForApplication() {
if(!$this->isAlreadyInitialized) {
$this->createConnectionIfNeeded();
$this->isAlreadyInitialized = true;
}
}
function createConnectionIfNeeded() {
if(!$this->conn) {
$this->conn = new mysqli($this->servername, $this->username, $this->password, $this->dbname);
// Check connection
if ($this->conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
echo "Connection DB Error, " . $conn->connect_error;
echo "<BR><BR>";
} else {
echo "Connection DB successfully";
echo "<BR><BR>";
}
}
}
public function fetchBarang() {
$resultQuery = mysqli_query($this->conn, "SELECT * FROM Barang");
$resultTable = "";
while ($resultData = mysqli_fetch_array($resultQuery, MYSQLI_ASSOC)) {
$resultTable .= "<TR><TD>".$resultData['IdBarang']."</TD><TD>".$resultData['NamaBarang']."</TD><TD>".$resultData['Keterangan']."</TD><TD>".$resultData['Satuan']."</TD><TD>".$resultData['IdPengguna']."</TD><TD><button type=\"button\">EDIT</button> <button type=\"button\">HAPUS</button></TD></TR>";
}
print($resultTable);
return $resultTable;
}
public function insertBarang($id, $name, $keterangan, $satuan) {
$resultQuery = mysqli_query($this->conn, "INSERT INTO Barang VALUES ($id, $name, $keterangan, $satuan, 1)");
if ($this->conn->query($resultQuery) === TRUE) {
header("Refresh:0");
} else {
//echo "Error: " . $sql . "<br>" . $conn->error;
}
}
public function closeConnection() {
$this->conn->close();
}
}
?>