-
Notifications
You must be signed in to change notification settings - Fork 0
/
include.php
44 lines (38 loc) · 1.04 KB
/
include.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
<?php
include ('init.php');
function dbquery($query) {
$query = str_replace('\'NULL\'','NULL',$query); //allows NULL entry
$result = mysqli_query($GLOBALS['link'], $query) or die("<b>Error with MySQL Query:</b>.\n<br />Query: " . $query . "<br />\nError: (" . mysqli_errno() . ") " . mysqli_error());
return $result;
}
function dbqueryl($query) {
$query = str_replace('\'NULL\'','NULL',$query); //allows NULL entry
$result = mysqli_query($GLOBALS['link'], $query);
return $result;
}
function queryAssoc($query) {
$queryResult = dbquery($query);
$array = array();
while($row = mysqli_fetch_assoc($queryResult)) {
$array[] = $row;
}
return $array;
}
function mysqlQueryToJsonArray($query) {
$result = dbquery($query);
$columns = array();
$rows = array();
while ($row = mysqli_fetch_assoc($result)) {
$columns = array();
$dataRow = array();
foreach ($row as $key => $value) {
$columns[] = $key;
$dataRow[] = $value;
}
$rows[] = $dataRow;
}
$data['rows'] = $rows;
$data['columns'] = $columns;
return json_encode($data);
}
?>