-
Notifications
You must be signed in to change notification settings - Fork 0
/
MysqlRequest.php
104 lines (63 loc) · 2.18 KB
/
MysqlRequest.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
require 'configuration.php';
date_default_timezone_set('Asia/Kolkata');
Class MysqlRequest{
function select($array){
$con = $this->connect();
$queryExtras = "";
if(array_key_exists('what', $array))
$queryExtras = $queryExtras.' '.$array['what'];
if(array_key_exists('table', $array))
$queryExtras = $queryExtras.' '.$array['table'];
if(array_key_exists('where', $array))
$queryExtras = $queryExtras.' '.$array['where'];
if(array_key_exists('group_by', $array))
$queryExtras = $queryExtras.' '.$array['group_by'];
if(array_key_exists('limit', $array))
$queryExtras = $queryExtras.' '.$array['limit'];
if(array_key_exists('offset', $array))
$queryExtras = $queryExtras.' '.$array['offset'];
$query = "Select".$queryExtras;
// echo $query;
$mysqli = new mysqli(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$result = $mysqli->query($query);
if(!$result) echo mysqli_error($con).'<br>';
// print_r($result);
return $result;
}
function insert($array){
$con = $this->connect();
$queryExtras = "";
if(array_key_exists('into', $array))
$queryExtras = $queryExtras.' '.$array['into'];
if(array_key_exists('set', $array))
$queryExtras = $queryExtras.' '.$array['set'];
$query = "Insert".$queryExtras;
// echo $query;
$result = mysqli_query($con, $query);
if(!$result) echo mysqli_error($con).'<br>';
return $result;
}
function update($array){
$con = $this->connect();
$queryExtras = "";
if(array_key_exists('table', $array))
$queryExtras = $queryExtras.' '.$array['table'];
if(array_key_exists('set', $array))
$queryExtras = $queryExtras.' '.$array['set'];
if(array_key_exists('where', $array))
$queryExtras = $queryExtras.' '.$array['where'];
$query = "update".$queryExtras;
$result = mysqli_query($con, $query);
if(!$result) echo mysqli_error($con).'<br>';
return $result;
}
function connect(){
$con = mysqli_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
return $con;
}
}