-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabase.class.php
More file actions
62 lines (54 loc) · 1.37 KB
/
Copy pathDatabase.class.php
File metadata and controls
62 lines (54 loc) · 1.37 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
<?php
class Database {
// Public Variable
public $result;
public $error = false;
public $errorMsg = '';
// Private Variables
private $mysqli;
function __construct(){
// Connect to Server
$this->mysqli = new mysqli('host', 'username', 'password', 'dbname');
if($this->mysqli->connect_error){
die('Connect Error (' . $this->mysqli->connect_errno . ') ' . $this->mysqli->connect_error);
}
}
public function query($query){
if(isset($this->mysqli)){
// What type of query are we doing?
$returnResult = array('SELECT', 'SHOW', 'DESCRIBE', 'EXPLAIN');
$substring = substr($query, 0, 20);
$exploded = explode(' ', $substring);
if(in_array($exploded[0], $returnResult)){
// Query With Result
if($this->result = $this->mysqli->query($query)){
// Successful Query
}else{
// Query Error
$this->error = true;
}
}else{
// True False Query
if($this->mysqli->query($query) === true){
// Successful Query
}else{
// Query Error
$this->error = true;
}
}
}
}
public function escape($string){
$escaped = $this->mysqli->real_escape_string($string);
return $escaped;
}
public function resultArray(){
$array = $this->result->fetch_array(MYSQLI_ASSOC);
return $array;
}
public function singleResult($key){
$array = $this->result->fetch_array(MYSQLI_ASSOC);
return $array[$key];
}
}
?>