-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbase_layer.php
More file actions
88 lines (75 loc) · 2.12 KB
/
dbase_layer.php
File metadata and controls
88 lines (75 loc) · 2.12 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
define('SERVER', '127.0.0.1');
define('USERNAME', 'root');
define('PASSWORD', 'root');
define('DATABASE', 'metro');
define('TABLE', 'statn_graph');
define('JUNCTION_TABLE', 'junctions');
define('LATLONG_TABLE', 'location');
define('API_KEY', 'AIzaSyAHp1mwSB-jUQ7r_vfgB-QiygaFQnWhV7g');
// Function for select query.
function select_query($conn = NULL, $table = NULL, $cols = '*', $condition = NULL, $andor = 'AND') {
$query = 'SELECT ';
$base = '';
// Add columns to query.
if ($cols != '*') {
foreach ($cols as $colname) {
$base .= $colname . ', ';
}
$query .= rtrim($base, ', ') . ' FROM ' . $table . ' ';
}
else {
$query .= $cols . ' FROM ' . $table . ' ';
}
$base = '';
// Add conditions to query.
if ($condition != NULL) {
$query .= 'WHERE ';
foreach ($condition as $name => $value) {
$base .= $name . ' = "' . $value . '"';
// Check for more conditions.
if (count($condition) > 1) {
$base .= ' ' . $andor . ' ';
}
}
$base = rtrim($base, ' ' . $andor . ' ');
}
$query .= $base;
$result = mysqli_query($conn, $query);
return $result;
}
// Function for insert query.
function insert_query($conn = NULL, $table = NULL, $values = array()) {
$query = 'INSERT INTO ' . $table . ' VALUES(';
$base = '';
foreach ($values as $key => $val) {
$base .= '"' . $val . '", ';
}
$query .= rtrim($base, ', ') . ')';
mysqli_query($conn, $query);
return TRUE;
}
//Function for update query.
function update_query($conn, $table, $cols, $condition = array(), $andor = 'AND') {
$query = 'UPDATE ' . $table . ' SET ';
$base = '';
// Add columns to set to query.
foreach ($cols as $key => $value) {
$base .= $key . '="' . $value . '", ';
}
$query .= rtrim($base, ', ') . ' WHERE ';
$base = '';
// Add conditions to query.
foreach ($condition as $name => $value) {
$base .= $name . ' = "' . $value . '"';
// Check for more conditions.
if (count($condition) > 1) {
$base .= ' ' . $andor . ' ';
}
}
$base = rtrim($base, ' ' . $andor . ' ');
$query .= $base;
mysqli_query($conn, $query);
return TRUE;
}
?>