-
Notifications
You must be signed in to change notification settings - Fork 0
/
Database.php
68 lines (52 loc) · 1.51 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
67
68
<?php
require_once 'APIWrapper.class.php';
class Database
{
public $mysqli;
private $return_data = array();
public function __construct($host, $user, $password, $database)
{
$this->mysqli = new mysqli($host, $user, $password, $database);
}
public function query($query)
{
return $this->mysqli->query($query);
}
public function fetch_all($query)
{
$results = $this->query($query);
$return_data = array();
while($row = $results->fetch_assoc())
{
$return_data[] = $row;
}
return $return_data;
}
public function fetch($query)
{
return $this->query($query)->fetch_assoc();
}
public function insert_array($data = [], $table = "")
{
$fields_construct = "(";
$values_construct = "(";
foreach ($data as $key => $val) {
$values_construct .= "'".$val."',";
$fields_construct .= "`".$key."`,";
}
$values_construct = rtrim($values_construct, ",") . ")";
$fields_construct = rtrim($fields_construct, ",") . ")";
$final_query = "INSERT INTO `{$table}` " . $fields_construct . " VALUES " . $values_construct . ";";
if($this->query($final_query))
return TRUE;
return FALSE;
}
public function escape_string($string)
{
return mysqli_real_escape_string($this->mysqli, $string);
}
public function insert_id()
{
return $this->mysqli->insert_id;
}
}