-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.class.php
68 lines (50 loc) · 1.29 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
<?php
class db {
private $result;
public function __construct($server, $user, $password, $db) {
mysql_connect($server, $user, $password) or $this->debug('Error.');
mysql_select_db($db) or $this->debug('Error.');
mysql_query("SET NAMES 'utf8'");
}
public function query($query) {
$this->result = mysql_query($query) or $this->debug();
return $this->result;
}
public function execute($query) {
mysql_query($query) or $this->debug();
}
public function fetchObject($query = '') {
if (empty($query)) {
return mysql_fetch_object($this->result);
} else {
return mysql_fetch_object($query);
}
}
public function fetchArray($query = '') {
if (empty($query)) {
return mysql_fetch_array($this->result);
} else {
return mysql_fetch_array($query);
}
}
public function numRows($query = '') {
if (empty($query)) {
return mysql_num_rows($this->result);
} else {
return mysql_num_rows($query);
}
}
public function debug($error = '') {
if (defined('DEBUG')) {
if (empty($error)) { $error = mysql_error(); }
die('<div><p><strong>Error</strong><span>' . $error . '</span></p></div>');
}
}
public function free_result($query = '') {
if (!empty($query)) {
mysql_free_result($query);
$this->result = '';
}
}
}
?>