-
Notifications
You must be signed in to change notification settings - Fork 0
/
Database.php
66 lines (60 loc) · 1.99 KB
/
Database.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
class Database{
public $host = DB_HOST;
public $user = DB_USER;
public $pass = DB_PASS;
public $dbname = DB_NAME;
public $link;
public $error;
public function __construct(){
$this->connectDB();
}
private function connectDB(){
$this->link = new mysqli($this->host, $this->user, $this->pass, $this->dbname);
if(!$this->link){
$this->error = "Connection Fail".$this->link->connect_error;
return false;
}
}
// Select or Read Data
public function select($query){
$result = $this->link->query($query)or die($this->link->error.__LINE__);
if($result->num_rows > 0){
return $result;
}else{
return false;
}
}
// insert Data
public function insert($query){
$insert_row = $this->link->query($query)or die($this->link->error.__LINE__);
if($insert_row){
return $last_id = $this->link->insert_id;
// header("location:index.php?msg=".urlencode('Data Successfully Inserted.'));
// exit();
}else{
die("Error :".$this->link->errno.")".$this->link->error);
}
}
// update Data
public function update($query){
$update_row = $this->link->query($query)or die($this->link->error.__LINE__);
if($update_row){
header("location:index.php?msg=".urlencode('Data Updated Successfully .'));
exit();
}else{
die("Error: :".$this->link->errno.")".$this->link->error);
}
}
// delete Data
public function delete($query){
$delete_row = $this->link->query($query)or die($this->link->error.__LINE__);
if($delete_row){
header("location:index.php?msg=".urlencode('Data Deleted Successfully .'));
exit();
}else{
die("Error: :".$this->link->errno.")".$this->link->error);
}
}
}
?>