-
Notifications
You must be signed in to change notification settings - Fork 0
/
database_class.php
executable file
·126 lines (97 loc) · 2.51 KB
/
database_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
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
<?php
include 'table.php';
include 'user_table.php';
include 'article_table.php';
class DataBase extends output{
var $conf;
var $conn;
var $log;
var $table;
function __construct($conf_file, &$ret)
{
//$this->errno = DB_ERRNO_NO_ERROR;
//$this->data = "";
//$this->msg = get_error_msg(DB_ERRNO_NO_ERROR);
//$this->interval = 60;
$this->conf = new conf($conf_file);
$ret = $this->conf->DB_parse_conf();
if (!$ret) {
//$this->errno = DB_ERRNO_CONF_PARSE_ERROR;
//$this->msg = get_error_msg(DB_ERRNO_CONF_PARSE_ERROR);
$ret = FALSE;
goto error;
}
$this->log = new log($this->conf->log);
$ret = $this->DB_connect_mysql();
if (!$ret) {
$this->log->log_write("connect mysql error", 'LOG_LEVEL_ERROR', $this->conf->debug);
$ret = FALSE;
goto error;
}
$this->log->log_write("connect mysql ok", 'LOG_LEVEL_INFO', $this->conf->debug);
$ret = $this->DB_select_db();
if (!$ret) {
$this->log->log_write("select db error", 'LOG_LEVEL_ERROR', $this->conf->debug);
$ret = FALSE;
goto error;
}
$this->log->log_write("select db ok", 'LOG_LEVEL_INFO', $this->conf->debug);
$ret = TRUE;
return;
error:
$this->print_result();
}
function __destruct()
{
if ($this->conn) {
$ret = mysql_close($this->conn);
}
}
function DB_connect_mysql()
{
if ($this->conn) {
return TRUE;
}
$connection = mysql_connect($this->conf->server . ":" . $this->conf->port, $this->conf->user, $this->conf->password);
if (!$connection) {
return FALSE;
}
$this->conn = $connection;
return TRUE;
}
function DB_close_mysql()
{
if (!$this->conn) {
return;
}
mysql_close($this->conn);
$this->conn = "";
}
function DB_select_db()
{
if (!$this->conf->data_base) {
return FALSE;
}
$link = mysql_select_db($this->conf->data_base, $this->conn);
if (!$link) {
return FALSE;
}
return TRUE;
}
function DB_request_handler($array)
{
if ($array["user"] && $array["password"]) {
$this->table = new user_table($this->log, $this->conf);
return $this->table->run($array);
}
if ($array["insert"] && $array["article"]) {
$this->table = new article_table($this->log, $this->conf);
return $this->table->run($array);
}
if ($array["select"] && $array["article"]) {
$this->table = new article_table($this->log, $this->conf);
return $this->table->run($array);
}
}
}
?>