-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabaseManager.php
More file actions
153 lines (124 loc) · 2.63 KB
/
DatabaseManager.php
File metadata and controls
153 lines (124 loc) · 2.63 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?
class DatabaseManager{
//set up the object
private $host;
private $db;
private $dbuser;
private $dbpassword;
private $dbopenstatus;
private $dbconnection;
function getHost() {
return $this->dbhost;
}
function setHost($req_host) {
$this->dbhost = $req_host;
}
function getDatabase() {
return $this->db;
}
function setDatabase($req_db) {
$this->db = $req_db;
}
function getUser() {
return $this->dbuser;
}
function setUser($req_user) {
$this->dbuser = $req_user;
}
function setConnection($req_dbconnection) {
$this->dbconnection = $req_connection;
}
function getConnection() {
return $this->dbconnection;
}
function __construct($HOST, $DB, $USER, $PASSWORD) {
$this->sethost($HOST);
$this->setDatabase($DB);
$this->setUser($USER);
$this->dbpassword = $PASSWORD;
$this->setConnection(false);
}
function opendbconnection() {
$this->dbconnection = mysql_connect($this->dbhost, $this->dbuser, $this->dbpassword);
if ($this->dbconnection == true) {
$this->db = mysql_select_db($this->db);
$this->setConnection(true);
} else {
$this->setConnection(false);
return false;
}
return true;
}
function closedbconnection() {
if ($this->dbconnection = true) {
mysql_close($this->dbconnection);
}
}
/*
* Returns SQl results
*
* Null if no results exists
*/
function selectquery($select, $from, $where) {
if ($this->dbconnection == false) {
$this->opendbconnection();
}
if($where == null){
$where = "";
}else{
$where = "WHERE ".$where;
}
$sql = "SELECT ".$select." FROM ".$from." ".$where;
$qry = mysql_query($sql);
if (!$qry) {
return false;
} else {
$numberrows = mysql_num_rows($qry);
if ($numberrows >= 0) {
return $qry;
} else {
return null;
}
}
}
/*
* Insert entry into the database
*/
function insertquery($table, $values) {
if ($this->dbconnection == false) {
$this->opendbconnection();
}
$sql = "INSERT INTO ".$table." VALUES (".$values.")";
$qry = mysql_query($sql);
if (!$qry) {
return false;
} else {
return true;
}
}
function updatequery($table, $colVal, $where) {
if ($this->dbconnection == false) {
$this->opendbconnection();
}
$sql = "UPDATE ".$table." SET ".$colVal." WHERE ".$where;
$qry = mysql_query($sql);
if (!$qry) {
return false;
} else {
return true;
}
}
function deletequery($table, $where) {
if ($this->dbconnection == false) {
$this->opendbconnection();
}
$sql = "DELETE FROM ".$table." WHERE ".$where;
$qry = mysql_query($sql);
if (!$qry) {
return false;
} else {
return true;
}
}
}
?>