forked from pfzim/ldap-phonebook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinc.db.php
155 lines (126 loc) · 2.34 KB
/
inc.db.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
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
154
155
<?php
require_once("inc.config.php");
class MySQLDB
{
private $link = NULL;
public $data = array();
private $error_msg = "";
function __construct()
{
$link = NULL;
$data = array();
$error_msg = "";
}
function connect($db_host = DB_HOST, $db_user = DB_USER, $db_passwd = DB_PASSWD, $db_name = DB_NAME, $db_cpage = DB_CPAGE)
{
$this->link = mysqli_connect($db_host, $db_user, $db_passwd, $db_name);
if(!$this->link)
{
$this->error(mysqli_connect_error());
return NULL;
}
if(!mysqli_set_charset($this->link, $db_cpage))
{
$this->error(mysqli_error($this->link));
mysqli_close($this->link);
$this->link = NULL;
return NULL;
}
return $this->link;
}
public function __destruct()
{
$this->data = array();
$this->disconnect();
}
public function select_db($db_name)
{
return mysqli_select_db($this->link, $db_name);
}
public function select($query)
{
$this->data = array();
if(!$this->link)
{
return FALSE;
}
$res = mysqli_query($this->link, $query);
if(!$res)
{
$this->error(mysqli_error($this->link));
return FALSE;
}
if(mysqli_num_rows($res) <= 0)
{
return FALSE;
}
while($row = mysqli_fetch_row($res))
{
$this->data[] = $row;
}
mysqli_free_result($res);
return TRUE;
}
public function select_assoc($query)
{
$this->data = array();
if(!$this->link)
{
return FALSE;
}
$res = mysqli_query($this->link, $query);
if(!$res)
{
$this->error(mysqli_error($this->link));
return FALSE;
}
if(mysqli_num_rows($res) <= 0)
{
return FALSE;
}
while($row = mysqli_fetch_assoc($res))
{
$this->data[] = $row;
}
mysqli_free_result($res);
return TRUE;
}
public function put($query)
{
if(!$this->link)
{
return FALSE;
}
$res = mysqli_query($this->link, $query);
if(!$res)
{
$this->error(mysqli_error($this->link));
return FALSE;
}
//return mysqli_affected_rows($this->link);
return TRUE;
}
public function last_id()
{
return mysqli_insert_id($this->link);
}
public function disconnect()
{
//$this->data = FALSE;
$this->error_msg = "";
if($this->link)
{
mysqli_close($this->link);
$this->link = NULL;
}
}
public function get_last_error()
{
return $this->error_msg;
}
private function error($str)
{
$this->error_msg = $str;
//throw new Exception(__CLASS__.": ".$str);
}
}