| Line 1... |
Line 1... |
| 1 |
<?php |
1 |
<?php |
| 2 |
/*************************************************************************** |
2 |
/*************************************************************************** |
| 3 |
* mysql4.php |
3 |
* mysql4.php |
| 4 |
* ------------------- |
4 |
* ------------------- |
| 5 |
* begin : Saturday, Feb 13, 2001 |
5 |
* begin : Saturday, Feb 13, 2001 |
| 6 |
* copyright : (C) 2001 The phpBB Group |
6 |
* copyright : (C) 2001 The phpBB Group |
| 7 |
* email : supportphpbb.com |
7 |
* email : supportphpbb.com |
| 8 |
* |
8 |
* |
| 9 |
* $Id: mysql4.php,v 1.5.2.1 2005/09/18 16:17:20 acydburn Exp $ |
9 |
* $Id: mysql4.php,v 1.5.2.1 2005/09/18 16:17:20 acydburn Exp $ |
| 10 |
* |
10 |
* |
| 11 |
***************************************************************************/ |
11 |
***************************************************************************/ |
| 12 |
|
12 |
|
| 13 |
/*************************************************************************** |
13 |
/*************************************************************************** |
| 14 |
* |
14 |
* |
| 15 |
* This program is free software; you can redistribute it and/or modify |
15 |
* This program is free software; you can redistribute it and/or modify |
| 16 |
* it under the terms of the GNU General Public License as published by |
16 |
* it under the terms of the GNU General Public License as published by |
| 17 |
* the Free Software Foundation; either version 2 of the License, or |
17 |
* the Free Software Foundation; either version 2 of the License, or |
| 18 |
* (at your option) any later version. |
18 |
* (at your option) any later version. |
| 19 |
* |
19 |
* |
| 20 |
***************************************************************************/ |
20 |
***************************************************************************/ |
| 21 |
|
21 |
|
| 22 |
if(!defined("SQL_LAYER")) |
22 |
if(!defined("SQL_LAYER")) |
| 23 |
{ |
23 |
{ |
| 24 |
|
24 |
|
| 25 |
define("SQL_LAYER","mysql4"); |
25 |
define("SQL_LAYER","mysql4"); |
| 26 |
|
26 |
|
| 27 |
class sql_db |
27 |
class sql_db |
| 28 |
{ |
28 |
{ |
| 29 |
|
29 |
|
| 30 |
var $db_connect_id; |
30 |
var $db_connect_id; |
| 31 |
var $query_result; |
31 |
var $query_result; |
| 32 |
var $row = array(); |
32 |
var $row = array(); |
| 33 |
var $rowset = array(); |
33 |
var $rowset = array(); |
| 34 |
var $num_queries = 0; |
34 |
var $num_queries = 0; |
| 35 |
var $in_transaction = 0; |
35 |
var $in_transaction = 0; |
| 36 |
|
36 |
|
| 37 |
// |
37 |
// |
| 38 |
// Constructor |
38 |
// Constructor |
| 39 |
// |
39 |
// |
| 40 |
function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true) |
40 |
function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true) |
| 41 |
{ |
41 |
{ |
| 42 |
$this->persistency = $persistency; |
42 |
$this->persistency = $persistency; |
| 43 |
$this->user = $sqluser; |
43 |
$this->user = $sqluser; |
| 44 |
$this->password = $sqlpassword; |
44 |
$this->password = $sqlpassword; |
| 45 |
$this->server = $sqlserver; |
45 |
$this->server = $sqlserver; |
| 46 |
$this->dbname = $database; |
46 |
$this->dbname = $database; |
| 47 |
mysql_query("SET NAMES 'utf8'"); |
47 |
|
| 48 |
|
48 |
$this->db_connect_id = ($this->persistency) ? mysql_pconnect($this->server, $this->user, $this->password) : mysql_connect($this->server, $this->user, $this->password); |
| 49 |
$this->db_connect_id = ($this->persistency) ? mysql_pconnect($this->server, $this->user, $this->password) : mysql_connect($this->server, $this->user, $this->password); |
49 |
|
| 50 |
|
50 |
if( $this->db_connect_id ) |
| 51 |
if( $this->db_connect_id ) |
51 |
{ |
| 52 |
{ |
52 |
if( $database != "" ) |
| 53 |
if( $database != "" ) |
53 |
{ |
| 54 |
{ |
54 |
$this->dbname = $database; |
| 55 |
$this->dbname = $database; |
55 |
$dbselect = mysql_select_db($this->dbname); |
| 56 |
$dbselect = mysql_select_db($this->dbname); |
56 |
|
| 57 |
|
57 |
if( !$dbselect ) |
| 58 |
if( !$dbselect ) |
58 |
{ |
| 59 |
{ |
59 |
mysql_close($this->db_connect_id); |
| 60 |
mysql_close($this->db_connect_id); |
60 |
$this->db_connect_id = $dbselect; |
| 61 |
$this->db_connect_id = $dbselect; |
61 |
} |
| 62 |
} |
62 |
} |
| 63 |
} |
63 |
|
| 64 |
|
64 |
return $this->db_connect_id; |
| 65 |
return $this->db_connect_id; |
65 |
} |
| 66 |
} |
66 |
else |
| 67 |
else |
67 |
{ |
| 68 |
{ |
68 |
return false; |
| 69 |
return false; |
69 |
} |
| 70 |
} |
70 |
} |
| 71 |
} |
71 |
|
| 72 |
|
72 |
// |
| 73 |
// |
73 |
// Other base methods |
| 74 |
// Other base methods |
74 |
// |
| 75 |
// |
75 |
function sql_close() |
| 76 |
function sql_close() |
76 |
{ |
| 77 |
{ |
77 |
if( $this->db_connect_id ) |
| 78 |
if( $this->db_connect_id ) |
78 |
{ |
| 79 |
{ |
79 |
// |
| 80 |
// |
80 |
// Commit any remaining transactions |
| 81 |
// Commit any remaining transactions |
81 |
// |
| 82 |
// |
82 |
if( $this->in_transaction ) |
| 83 |
if( $this->in_transaction ) |
83 |
{ |
| 84 |
{ |
84 |
mysql_query("COMMIT", $this->db_connect_id); |
| 85 |
mysql_query("COMMIT", $this->db_connect_id); |
85 |
} |
| 86 |
} |
86 |
|
| 87 |
|
87 |
return mysql_close($this->db_connect_id); |
| 88 |
return mysql_close($this->db_connect_id); |
88 |
} |
| 89 |
} |
89 |
else |
| 90 |
else |
90 |
{ |
| 91 |
{ |
91 |
return false; |
| 92 |
return false; |
92 |
} |
| 93 |
} |
93 |
} |
| 94 |
} |
94 |
|
| 95 |
|
95 |
// |
| 96 |
// |
96 |
// Base query method |
| 97 |
// Base query method |
97 |
// |
| 98 |
// |
98 |
function sql_query($query = "", $transaction = FALSE) |
| 99 |
function sql_query($query = "", $transaction = FALSE) |
99 |
{ |
| 100 |
{ |
100 |
// |
| 101 |
// |
101 |
// Remove any pre-existing queries |
| 102 |
// Remove any pre-existing queries |
102 |
// |
| 103 |
// |
103 |
unset($this->query_result); |
| 104 |
unset($this->query_result); |
104 |
|
| 105 |
|
105 |
if( $query != "" ) |
| 106 |
if( $query != "" ) |
106 |
{ |
| 107 |
{ |
107 |
$this->num_queries++; |
| 108 |
$this->num_queries++; |
108 |
if( $transaction == BEGIN_TRANSACTION && !$this->in_transaction ) |
| 109 |
if( $transaction == BEGIN_TRANSACTION && !$this->in_transaction ) |
109 |
{ |
| 110 |
{ |
110 |
$result = mysql_query("BEGIN", $this->db_connect_id); |
| 111 |
$result = mysql_query("BEGIN", $this->db_connect_id); |
111 |
if(!$result) |
| 112 |
if(!$result) |
112 |
{ |
| 113 |
{ |
113 |
return false; |
| 114 |
return false; |
114 |
} |
| 115 |
} |
115 |
$this->in_transaction = TRUE; |
| 116 |
$this->in_transaction = TRUE; |
116 |
} |
| 117 |
} |
117 |
|
| 118 |
|
118 |
$this->query_result = mysql_query($query, $this->db_connect_id); |
| 119 |
$this->query_result = mysql_query($query, $this->db_connect_id); |
119 |
} |
| 120 |
} |
120 |
else |
| 121 |
else |
121 |
{ |
| 122 |
{ |
122 |
if( $transaction == END_TRANSACTION && $this->in_transaction ) |
| 123 |
if( $transaction == END_TRANSACTION && $this->in_transaction ) |
123 |
{ |
| 124 |
{ |
124 |
$result = mysql_query("COMMIT", $this->db_connect_id); |
| 125 |
$result = mysql_query("COMMIT", $this->db_connect_id); |
125 |
} |
| 126 |
} |
126 |
} |
| 127 |
} |
127 |
|
| 128 |
|
128 |
if( $this->query_result ) |
| 129 |
if( $this->query_result ) |
129 |
{ |
| 130 |
{ |
130 |
unset($this->row[$this->query_result]); |
| 131 |
unset($this->row[$this->query_result]); |
131 |
unset($this->rowset[$this->query_result]); |
| 132 |
unset($this->rowset[$this->query_result]); |
132 |
|
| 133 |
|
133 |
if( $transaction == END_TRANSACTION && $this->in_transaction ) |
| 134 |
if( $transaction == END_TRANSACTION && $this->in_transaction ) |
134 |
{ |
| 135 |
{ |
135 |
$this->in_transaction = FALSE; |
| 136 |
$this->in_transaction = FALSE; |
136 |
|
| 137 |
|
137 |
if ( !mysql_query("COMMIT", $this->db_connect_id) ) |
| 138 |
if ( !mysql_query("COMMIT", $this->db_connect_id) ) |
138 |
{ |
| 139 |
{ |
139 |
mysql_query("ROLLBACK", $this->db_connect_id); |
| 140 |
mysql_query("ROLLBACK", $this->db_connect_id); |
140 |
return false; |
| 141 |
return false; |
141 |
} |
| 142 |
} |
142 |
} |
| 143 |
} |
143 |
|
| 144 |
|
144 |
return $this->query_result; |
| 145 |
return $this->query_result; |
145 |
} |
| 146 |
} |
146 |
else |
| 147 |
else |
147 |
{ |
| 148 |
{ |
148 |
if( $this->in_transaction ) |
| 149 |
if( $this->in_transaction ) |
149 |
{ |
| 150 |
{ |
150 |
mysql_query("ROLLBACK", $this->db_connect_id); |
| 151 |
mysql_query("ROLLBACK", $this->db_connect_id); |
151 |
$this->in_transaction = FALSE; |
| 152 |
$this->in_transaction = FALSE; |
152 |
} |
| 153 |
} |
153 |
return false; |
| 154 |
return false; |
154 |
} |
| 155 |
} |
155 |
} |
| 156 |
} |
156 |
|
| 157 |
|
157 |
// |
| 158 |
// |
158 |
// Other query methods |
| 159 |
// Other query methods |
159 |
// |
| 160 |
// |
160 |
function sql_numrows($query_id = 0) |
| 161 |
function sql_numrows($query_id = 0) |
161 |
{ |
| 162 |
{ |
162 |
if( !$query_id ) |
| 163 |
if( !$query_id ) |
163 |
{ |
| 164 |
{ |
164 |
$query_id = $this->query_result; |
| 165 |
$query_id = $this->query_result; |
165 |
} |
| 166 |
} |
166 |
|
| 167 |
|
167 |
return ( $query_id ) ? mysql_num_rows($query_id) : false; |
| 168 |
return ( $query_id ) ? mysql_num_rows($query_id) : false; |
168 |
} |
| 169 |
} |
169 |
|
| 170 |
|
170 |
function sql_affectedrows() |
| 171 |
function sql_affectedrows() |
171 |
{ |
| 172 |
{ |
172 |
return ( $this->db_connect_id ) ? mysql_affected_rows($this->db_connect_id) : false; |
| 173 |
return ( $this->db_connect_id ) ? mysql_affected_rows($this->db_connect_id) : false; |
173 |
} |
| 174 |
} |
174 |
|
| 175 |
|
175 |
function sql_numfields($query_id = 0) |
| 176 |
function sql_numfields($query_id = 0) |
176 |
{ |
| 177 |
{ |
177 |
if( !$query_id ) |
| 178 |
if( !$query_id ) |
178 |
{ |
| 179 |
{ |
179 |
$query_id = $this->query_result; |
| 180 |
$query_id = $this->query_result; |
180 |
} |
| 181 |
} |
181 |
|
| 182 |
|
182 |
return ( $query_id ) ? mysql_num_fields($query_id) : false; |
| 183 |
return ( $query_id ) ? mysql_num_fields($query_id) : false; |
183 |
} |
| 184 |
} |
184 |
|
| 185 |
|
185 |
function sql_fieldname($offset, $query_id = 0) |
| 186 |
function sql_fieldname($offset, $query_id = 0) |
186 |
{ |
| 187 |
{ |
187 |
if( !$query_id ) |
| 188 |
if( !$query_id ) |
188 |
{ |
| 189 |
{ |
189 |
$query_id = $this->query_result; |
| 190 |
$query_id = $this->query_result; |
190 |
} |
| 191 |
} |
191 |
|
| 192 |
|
192 |
return ( $query_id ) ? mysql_field_name($query_id, $offset) : false; |
| 193 |
return ( $query_id ) ? mysql_field_name($query_id, $offset) : false; |
193 |
} |
| 194 |
} |
194 |
|
| 195 |
|
195 |
function sql_fieldtype($offset, $query_id = 0) |
| 196 |
function sql_fieldtype($offset, $query_id = 0) |
196 |
{ |
| 197 |
{ |
197 |
if( !$query_id ) |
| 198 |
if( !$query_id ) |
198 |
{ |
| 199 |
{ |
199 |
$query_id = $this->query_result; |
| 200 |
$query_id = $this->query_result; |
200 |
} |
| 201 |
} |
201 |
|
| 202 |
|
202 |
return ( $query_id ) ? mysql_field_type($query_id, $offset) : false; |
| 203 |
return ( $query_id ) ? mysql_field_type($query_id, $offset) : false; |
203 |
} |
| 204 |
} |
204 |
|
| 205 |
|
205 |
function sql_fetchrow($query_id = 0) |
| 206 |
function sql_fetchrow($query_id = 0) |
206 |
{ |
| 207 |
{ |
207 |
if( !$query_id ) |
| 208 |
if( !$query_id ) |
208 |
{ |
| 209 |
{ |
209 |
$query_id = $this->query_result; |
| 210 |
$query_id = $this->query_result; |
210 |
} |
| 211 |
} |
211 |
|
| 212 |
|
212 |
if( $query_id ) |
| 213 |
if( $query_id ) |
213 |
{ |
| 214 |
{ |
214 |
$this->row[$query_id] = mysql_fetch_array($query_id, MYSQL_ASSOC); |
| 215 |
$this->row[$query_id] = mysql_fetch_array($query_id, MYSQL_ASSOC); |
215 |
return $this->row[$query_id]; |
| 216 |
return $this->row[$query_id]; |
216 |
} |
| 217 |
} |
217 |
else |
| 218 |
else |
218 |
{ |
| 219 |
{ |
219 |
return false; |
| 220 |
return false; |
220 |
} |
| 221 |
} |
221 |
} |
| 222 |
} |
222 |
|
| 223 |
|
223 |
function sql_fetchrowset($query_id = 0) |
| 224 |
function sql_fetchrowset($query_id = 0) |
224 |
{ |
| 225 |
{ |
225 |
if( !$query_id ) |
| 226 |
if( !$query_id ) |
226 |
{ |
| 227 |
{ |
227 |
$query_id = $this->query_result; |
| 228 |
$query_id = $this->query_result; |
228 |
} |
| 229 |
} |
229 |
|
| 230 |
|
230 |
if( $query_id ) |
| 231 |
if( $query_id ) |
231 |
{ |
| 232 |
{ |
232 |
unset($this->rowset[$query_id]); |
| 233 |
unset($this->rowset[$query_id]); |
233 |
unset($this->row[$query_id]); |
| 234 |
unset($this->row[$query_id]); |
234 |
|
| 235 |
|
235 |
while($this->rowset[$query_id] = mysql_fetch_array($query_id, MYSQL_ASSOC)) |
| 236 |
while($this->rowset[$query_id] = mysql_fetch_array($query_id, MYSQL_ASSOC)) |
236 |
{ |
| 237 |
{ |
237 |
$result[] = $this->rowset[$query_id]; |
| 238 |
$result[] = $this->rowset[$query_id]; |
238 |
} |
| 239 |
} |
239 |
|
| 240 |
|
240 |
return $result; |
| 241 |
return $result; |
241 |
} |
| 242 |
} |
242 |
else |
| 243 |
else |
243 |
{ |
| 244 |
{ |
244 |
return false; |
| 245 |
return false; |
245 |
} |
| 246 |
} |
246 |
} |
| 247 |
} |
247 |
|
| 248 |
|
248 |
function sql_fetchfield($field, $rownum = -1, $query_id = 0) |
| 249 |
function sql_fetchfield($field, $rownum = -1, $query_id = 0) |
249 |
{ |
| 250 |
{ |
250 |
if( !$query_id ) |
| 251 |
if( !$query_id ) |
251 |
{ |
| 252 |
{ |
252 |
$query_id = $this->query_result; |
| 253 |
$query_id = $this->query_result; |
253 |
} |
| 254 |
} |
254 |
|
| 255 |
|
255 |
if( $query_id ) |
| 256 |
if( $query_id ) |
256 |
{ |
| 257 |
{ |
257 |
if( $rownum > -1 ) |
| 258 |
if( $rownum > -1 ) |
258 |
{ |
| 259 |
{ |
259 |
$result = mysql_result($query_id, $rownum, $field); |
| 260 |
$result = mysql_result($query_id, $rownum, $field); |
260 |
} |
| 261 |
} |
261 |
else |
| 262 |
else |
262 |
{ |
| 263 |
{ |
263 |
if( empty($this->row[$query_id]) && empty($this->rowset[$query_id]) ) |
| 264 |
if( empty($this->row[$query_id]) && empty($this->rowset[$query_id]) ) |
264 |
{ |
| 265 |
{ |
265 |
if( $this->sql_fetchrow() ) |
| 266 |
if( $this->sql_fetchrow() ) |
266 |
{ |
| 267 |
{ |
267 |
$result = $this->row[$query_id][$field]; |
| 268 |
$result = $this->row[$query_id][$field]; |
268 |
} |
| 269 |
} |
269 |
} |
| 270 |
} |
270 |
else |
| 271 |
else |
271 |
{ |
| 272 |
{ |
272 |
if( $this->rowset[$query_id] ) |
| 273 |
if( $this->rowset[$query_id] ) |
273 |
{ |
| 274 |
{ |
274 |
$result = $this->rowset[$query_id][0][$field]; |
| 275 |
$result = $this->rowset[$query_id][0][$field]; |
275 |
} |
| 276 |
} |
276 |
else if( $this->row[$query_id] ) |
| 277 |
else if( $this->row[$query_id] ) |
277 |
{ |
| 278 |
{ |
278 |
$result = $this->row[$query_id][$field]; |
| 279 |
$result = $this->row[$query_id][$field]; |
279 |
} |
| 280 |
} |
280 |
} |
| 281 |
} |
281 |
} |
| 282 |
} |
282 |
|
| 283 |
|
283 |
return $result; |
| 284 |
return $result; |
284 |
} |
| 285 |
} |
285 |
else |
| 286 |
else |
286 |
{ |
| 287 |
{ |
287 |
return false; |
| 288 |
return false; |
288 |
} |
| 289 |
} |
289 |
} |
| 290 |
} |
290 |
|
| 291 |
|
291 |
function sql_rowseek($rownum, $query_id = 0) |
| 292 |
function sql_rowseek($rownum, $query_id = 0) |
292 |
{ |
| 293 |
{ |
293 |
if( !$query_id ) |
| 294 |
if( !$query_id ) |
294 |
{ |
| 295 |
{ |
295 |
$query_id = $this->query_result; |
| 296 |
$query_id = $this->query_result; |
296 |
} |
| 297 |
} |
297 |
|
| 298 |
|
298 |
return ( $query_id ) ? mysql_data_seek($query_id, $rownum) : false; |
| 299 |
return ( $query_id ) ? mysql_data_seek($query_id, $rownum) : false; |
299 |
} |
| 300 |
} |
300 |
|
| 301 |
|
301 |
function sql_nextid() |
| 302 |
function sql_nextid() |
302 |
{ |
| 303 |
{ |
303 |
return ( $this->db_connect_id ) ? mysql_insert_id($this->db_connect_id) : false; |
| 304 |
return ( $this->db_connect_id ) ? mysql_insert_id($this->db_connect_id) : false; |
304 |
} |
| 305 |
} |
305 |
|
| 306 |
|
306 |
function sql_freeresult($query_id = 0) |
| 307 |
function sql_freeresult($query_id = 0) |
307 |
{ |
| 308 |
{ |
308 |
if( !$query_id ) |
| 309 |
if( !$query_id ) |
309 |
{ |
| 310 |
{ |
310 |
$query_id = $this->query_result; |
| 311 |
$query_id = $this->query_result; |
311 |
} |
| 312 |
} |
312 |
|
| 313 |
|
313 |
if ( $query_id ) |
| 314 |
if ( $query_id ) |
314 |
{ |
| 315 |
{ |
315 |
unset($this->row[$query_id]); |
| 316 |
unset($this->row[$query_id]); |
316 |
unset($this->rowset[$query_id]); |
| 317 |
unset($this->rowset[$query_id]); |
317 |
|
| 318 |
|
318 |
mysql_free_result($query_id); |
| 319 |
mysql_free_result($query_id); |
319 |
|
| 320 |
|
320 |
return true; |
| 321 |
return true; |
321 |
} |
| 322 |
} |
322 |
else |
| 323 |
else |
323 |
{ |
| 324 |
{ |
324 |
return false; |
| 325 |
return false; |
325 |
} |
| 326 |
} |
326 |
} |
| 327 |
} |
327 |
|
| 328 |
|
328 |
function sql_error() |
| 329 |
function sql_error() |
329 |
{ |
| 330 |
{ |
330 |
$result['message'] = mysql_error($this->db_connect_id); |
| 331 |
$result['message'] = mysql_error($this->db_connect_id); |
331 |
$result['code'] = mysql_errno($this->db_connect_id); |
| 332 |
$result['code'] = mysql_errno($this->db_connect_id); |
332 |
|
| 333 |
|
333 |
return $result; |
| 334 |
return $result; |
334 |
} |
| 335 |
} |
335 |
|
| 336 |
|
336 |
} // class sql_db |
| 337 |
} // class sql_db |
337 |
|
| 338 |
|
338 |
} // if ... define |
| 339 |
} // if ... define |
339 |
|
| 340 |
|
340 |
?> |
| 341 |
?> |
- |
|