-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_helper.php
More file actions
executable file
·73 lines (61 loc) · 1.58 KB
/
db_helper.php
File metadata and controls
executable file
·73 lines (61 loc) · 1.58 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
<?php
include 'db_credentials.php';
$connection = mysql_connect(
$db_host,
$db_username,
$db_password
);
if(!$connection){
die("Error connecting to the database.<br/><br/>" .
mysql_error());
}
$db_select = mysql_select_db($db_database);
if(!$db_select){die("Error with db select.<br/><br/>".mysql_error());}
function getDBResultsArray($dbQuery){
$dbResults=mysql_query($dbQuery);
if(!$dbResults){
$GLOBALS["_PLATFORM"]->sandboxHeader("HTTP/1.1 500 Internal Server Error");
die();
}
$resultsArray = array();
if(mysql_num_rows($dbResults) > 0){
while($row = mysql_fetch_assoc($dbResults)){
$resultsArray[] = $row;
}
}else{
$GLOBALS["_PLATFORM"]->sandboxHeader('HTTP/1.1 404 Not Found');
die();
}
return $resultsArray;
}
function getDBResultRecord($dbQuery){
$dbResults=mysql_query($dbQuery);
if(!$dbResults){
$GLOBALS["_PLATFORM"]->sandboxHeader("HTTP/1.1 500 Internal Server Error");
die();
}
if(mysql_num_rows($dbResults) != 1){
$GLOBALS["_PLATFORM"]->sandboxHeader('HTTP/1.1 404 Not Found');
die();
}
return mysql_fetch_assoc($dbResults);
}
function getDBResultAffected($dbQuery){
$dbResults=mysql_query($dbQuery);
if($dbResults){
return array('rowsAffected'=>mysql_affected_rows());
}else{
$GLOBALS["_PLATFORM"]->sandboxHeader('HTTP/1.1 500 Internal Server Error');
die(mysql_error());
}
}
function getDBResultInserted($dbQuery,$id){
$dbResults=mysql_query($dbQuery);
if($dbResults){
return array($id=>mysql_insert_id());
}else{
$GLOBALS["_PLATFORM"]->sandboxHeader('HTTP/1.1 500 Internal Server Error');
die(mysql_error());
}
}
?>