-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdatabase.php
91 lines (74 loc) · 1.73 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
$db_host = "localhost";
$db_user = "username";
$db_pass = "password";
$db_name = "database_name";
$db = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db($db_name);
function q($q, $debug = 0){
$r = mysql_query($q);
if(mysql_error()){
echo mysql_error();
echo "$q<br>";
}
if($debug == 1)
echo "<br>$q<br>";
if(stristr(substr($q,0,8),"delete") || stristr(substr($q,0,8),"insert") || stristr(substr($q,0,8),"update")){
if(mysql_affected_rows() > 0)
return true;
else
return false;
}
if(mysql_num_rows($r) > 1){
while($row = mysql_fetch_array($r, MYSQL_ASSOC)){
$results[] = $row;
}
}
else if(mysql_num_rows($r) == 1){
$results = array();
$results[] = mysql_fetch_array($r, MYSQL_ASSOC);
}
else
$results = array();
return $results;
}
function q1($q, $debug = 0){
$r = mysql_query($q);
if(mysql_error()){
echo mysql_error();
echo "<br>$q<br>";
}
if($debug == 1)
echo "<br>$q<br>";
$row = @mysql_fetch_array($r);
if(count($row) == 2)
return $row[0];
else
return $row;
}
function qr($q, $debug = 0){
$r = mysql_query($q);
if(mysql_error()){
return false;
//echo mysql_error();
//echo "<br>$q<br>";
}
if($debug == 1)
echo "<br>$q<br>";
if(stristr(substr($q,0,8),"delete") || stristr(substr($q,0,8),"insert") || stristr(substr($q,0,8),"update")){
if(mysql_affected_rows() > 0){
return true;
}
else{
if(stristr(substr($q,0,8),"update")){
//return true; //return true even if the update did not update anything (per kayla on 2/1/15 @ 4:10pm)
}
return false;
}
}
$results = array();
$results[] = mysql_fetch_array($r, MYSQL_ASSOC);
$results = $results[0];
return $results;
}
?>