This repository has been archived by the owner on May 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
db.class.php
70 lines (53 loc) · 1.62 KB
/
db.class.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
<?php
class db {
var $con;
var $debug = false;
function db($mysql_host, $mysql_user, $mysql_password, $mysql_database, $debug = false) {
$this->con = mysql_connect($mysql_host, $mysql_user, $mysql_password);
if ($this->con == false) {
die("Could not connect to database engine. Please try later.");
}
mysql_select_db($mysql_database, $this->con);
$this->debug = $debug;
}
function __destruct() {
mysql_close($this->con);
}
function select($columns, $table, $where) {
if ($this->debug) {
echo("<p>sql = " . "SELECT $columns FROM $table WHERE $where</p>");
}
$result = mysql_query("SELECT $columns FROM $table WHERE $where");
if ($result == false) {
if ($this->debug) {
echo("<p>sqlerror = " . mysql_error());
}
return false;
}
return ($result);
}
function insert($table, $values, $columns = "") {
if ($columns != "") {
$query = "INSERT INTO $table($columns) VALUES($values)";
} else {
$query = "INSERT INTO $table VALUES($values)";
}
if ($this->debug) {
echo($query);
}
return mysql_query($query);
}
function delete($table, $where) {
if ($where == "") {
/* Never allow a delete all */
return false;
} else {
$query = "DELETE FROM $table WHERE $where";
}
if ($this->debug) {
echo($query);
}
return mysql_query($query);
}
}
?>