commit | author | age
|
d13c36
|
1 |
<?php |
S |
2 |
// +----------------------------------------------------------------------+ |
|
3 |
// | PHP versions 4 and 5 | |
|
4 |
// +----------------------------------------------------------------------+ |
|
5 |
// | Copyright (c) 1998-2004 Manuel Lemos, Tomas V.V.Cox, | |
|
6 |
// | Stig. S. Bakken, Lukas Smith | |
|
7 |
// | All rights reserved. | |
|
8 |
// +----------------------------------------------------------------------+ |
|
9 |
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB | |
|
10 |
// | API as well as database abstraction for PHP applications. | |
|
11 |
// | This LICENSE is in the BSD license style. | |
|
12 |
// | | |
|
13 |
// | Redistribution and use in source and binary forms, with or without | |
|
14 |
// | modification, are permitted provided that the following conditions | |
|
15 |
// | are met: | |
|
16 |
// | | |
|
17 |
// | Redistributions of source code must retain the above copyright | |
|
18 |
// | notice, this list of conditions and the following disclaimer. | |
|
19 |
// | | |
|
20 |
// | Redistributions in binary form must reproduce the above copyright | |
|
21 |
// | notice, this list of conditions and the following disclaimer in the | |
|
22 |
// | documentation and/or other materials provided with the distribution. | |
|
23 |
// | | |
|
24 |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, | |
|
25 |
// | Lukas Smith nor the names of his contributors may be used to endorse | |
|
26 |
// | or promote products derived from this software without specific prior| |
|
27 |
// | written permission. | |
|
28 |
// | | |
|
29 |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
|
30 |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
|
31 |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
|
32 |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
|
33 |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
|
34 |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
|
35 |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS| |
|
36 |
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | |
|
37 |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
|
38 |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY| |
|
39 |
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
|
40 |
// | POSSIBILITY OF SUCH DAMAGE. | |
|
41 |
// +----------------------------------------------------------------------+ |
|
42 |
// | Author: Lukas Smith <smith@pooteeweet.org> | |
|
43 |
// +----------------------------------------------------------------------+ |
|
44 |
// |
|
45 |
// $Id$ |
|
46 |
// |
|
47 |
|
|
48 |
/** |
|
49 |
* Wrapper that makes MDB2 behave like PEAR DB |
|
50 |
* WARNING: this wrapper is broken and unmaintained |
|
51 |
* |
|
52 |
* @package MDB2 |
|
53 |
* @category Database |
|
54 |
* @author Lukas Smith <smith@pooteeweet.org> |
|
55 |
*/ |
|
56 |
|
|
57 |
require_once 'MDB2.php'; |
|
58 |
|
|
59 |
/* |
|
60 |
* The method mapErrorCode in each MDB2_dbtype implementation maps |
|
61 |
* native error codes to one of these. |
|
62 |
* |
|
63 |
* If you add an error code here, make sure you also add a textual |
|
64 |
* version of it in DB::errorMessage(). |
|
65 |
*/ |
|
66 |
|
|
67 |
define('DB_OK', MDB2_OK); |
|
68 |
define('DB_ERROR', MDB2_ERROR); |
|
69 |
define('DB_ERROR_SYNTAX', MDB2_ERROR_SYNTAX); |
|
70 |
define('DB_ERROR_CONSTRAINT', MDB2_ERROR_CONSTRAINT); |
|
71 |
define('DB_ERROR_NOT_FOUND', MDB2_ERROR_NOT_FOUND); |
|
72 |
define('DB_ERROR_ALREADY_EXISTS', MDB2_ERROR_ALREADY_EXISTS); |
|
73 |
define('DB_ERROR_UNSUPPORTED', MDB2_ERROR_UNSUPPORTED); |
|
74 |
define('DB_ERROR_MISMATCH', MDB2_ERROR_MISMATCH); |
|
75 |
define('DB_ERROR_INVALID', MDB2_ERROR_INVALID); |
|
76 |
define('DB_ERROR_NOT_CAPABLE', MDB2_ERROR_NOT_CAPABLE); |
|
77 |
define('DB_ERROR_TRUNCATED', MDB2_ERROR_TRUNCATED); |
|
78 |
define('DB_ERROR_INVALID_NUMBER', MDB2_ERROR_INVALID_NUMBER); |
|
79 |
define('DB_ERROR_INVALID_DATE', MDB2_ERROR_INVALID_DATE); |
|
80 |
define('DB_ERROR_DIVZERO', MDB2_ERROR_DIVZERO); |
|
81 |
define('DB_ERROR_NODBSELECTED', MDB2_ERROR_NODBSELECTED); |
|
82 |
define('DB_ERROR_CANNOT_CREATE', MDB2_ERROR_CANNOT_CREATE); |
|
83 |
define('DB_ERROR_CANNOT_DROP', MDB2_ERROR_CANNOT_DROP); |
|
84 |
define('DB_ERROR_NOSUCHTABLE', MDB2_ERROR_NOSUCHTABLE); |
|
85 |
define('DB_ERROR_NOSUCHFIELD', MDB2_ERROR_NOSUCHFIELD); |
|
86 |
define('DB_ERROR_NEED_MORE_DATA', MDB2_ERROR_NEED_MORE_DATA); |
|
87 |
define('DB_ERROR_NOT_LOCKED', MDB2_ERROR_NOT_LOCKED); |
|
88 |
define('DB_ERROR_VALUE_COUNT_ON_ROW', MDB2_ERROR_VALUE_COUNT_ON_ROW); |
|
89 |
define('DB_ERROR_INVALID_DSN', MDB2_ERROR_INVALID_DSN); |
|
90 |
define('DB_ERROR_CONNECT_FAILED', MDB2_ERROR_CONNECT_FAILED); |
|
91 |
define('DB_ERROR_EXTENSION_NOT_FOUND', MDB2_ERROR_EXTENSION_NOT_FOUND); |
|
92 |
define('DB_ERROR_ACCESS_VIOLATION', MDB2_ERROR_ACCESS_VIOLATION); |
|
93 |
define('DB_ERROR_NOSUCHDB', MDB2_ERROR_NOSUCHDB); |
|
94 |
|
|
95 |
define('DB_WARNING', -1000); |
|
96 |
define('DB_WARNING_READ_ONLY', -1001); |
|
97 |
|
|
98 |
define('DB_PARAM_SCALAR', 1); |
|
99 |
define('DB_PARAM_OPAQUE', 2); |
|
100 |
define('DB_PARAM_MISC', 3); |
|
101 |
|
|
102 |
define('DB_BINMODE_PASSTHRU', 1); |
|
103 |
define('DB_BINMODE_RETURN', 2); |
|
104 |
define('DB_BINMODE_CONVERT', 3); |
|
105 |
|
|
106 |
define('DB_FETCHMODE_DEFAULT', MDB2_FETCHMODE_DEFAULT); |
|
107 |
define('DB_FETCHMODE_ORDERED', MDB2_FETCHMODE_ORDERED); |
|
108 |
define('DB_FETCHMODE_ASSOC', MDB2_FETCHMODE_ASSOC); |
|
109 |
define('DB_FETCHMODE_OBJECT', MDB2_FETCHMODE_OBJECT); |
|
110 |
define('DB_FETCHMODE_FLIPPED', MDB2_FETCHMODE_FLIPPED); |
|
111 |
|
|
112 |
define('DB_GETMODE_ORDERED', DB_FETCHMODE_ORDERED); |
|
113 |
define('DB_GETMODE_ASSOC', DB_FETCHMODE_ASSOC); |
|
114 |
define('DB_GETMODE_FLIPPED', DB_FETCHMODE_FLIPPED); |
|
115 |
|
|
116 |
require_once 'MDB2/Extended.php'; |
|
117 |
define('DB_AUTOQUERY_INSERT', MDB2_AUTOQUERY_INSERT); |
|
118 |
define('DB_AUTOQUERY_UPDATE', MDB2_AUTOQUERY_UPDATE); |
|
119 |
|
|
120 |
require_once 'MDB2/Driver/Reverse/Common.php'; |
|
121 |
define('DB_TABLEINFO_ORDER', MDB2_TABLEINFO_ORDER); |
|
122 |
define('DB_TABLEINFO_ORDERTABLE', MDB2_TABLEINFO_ORDERTABLE); |
|
123 |
define('DB_TABLEINFO_FULL', MDB2_TABLEINFO_FULL); |
|
124 |
|
|
125 |
define('DB_PORTABILITY_NONE', MDB2_PORTABILITY_NONE); |
|
126 |
define('DB_PORTABILITY_LOWERCASE', MDB2_PORTABILITY_FIX_CASE); |
|
127 |
define('DB_PORTABILITY_RTRIM', MDB2_PORTABILITY_RTRIM); |
|
128 |
define('DB_PORTABILITY_DELETE_COUNT', MDB2_PORTABILITY_DELETE_COUNT); |
|
129 |
define('DB_PORTABILITY_NUMROWS', MDB2_PORTABILITY_NUMROWS); |
|
130 |
define('DB_PORTABILITY_ERRORS', MDB2_PORTABILITY_ERRORS); |
|
131 |
define('DB_PORTABILITY_NULL_TO_EMPTY', MDB2_PORTABILITY_EMPTY_TO_NULL); |
|
132 |
define('DB_PORTABILITY_ALL', MDB2_PORTABILITY_ALL); |
|
133 |
|
|
134 |
/** |
|
135 |
* Wrapper that makes MDB2 behave like PEAR DB |
|
136 |
* |
|
137 |
* @package MDB2 |
|
138 |
* @category Database |
|
139 |
* @author Lukas Smith <smith@pooteeweet.org> |
|
140 |
*/ |
|
141 |
class DB |
|
142 |
{ |
|
143 |
function &factory($type) |
|
144 |
{ |
|
145 |
$db =& MDB2::factory($type); |
|
146 |
if (PEAR::isError($db)) { |
|
147 |
return $db; |
|
148 |
} |
|
149 |
$obj =& new MDB2_PEARProxy($db); |
|
150 |
return $obj; |
|
151 |
} |
|
152 |
|
|
153 |
function &connect($dsn, $options = false) |
|
154 |
{ |
|
155 |
if (!is_array($options) && $options) { |
|
156 |
$options = array('persistent' => true); |
|
157 |
} |
|
158 |
$db =& MDB2::connect($dsn, $options); |
|
159 |
if (PEAR::isError($db)) { |
|
160 |
return $db; |
|
161 |
} |
|
162 |
$obj =& new MDB2_PEARProxy($db); |
|
163 |
return $obj; |
|
164 |
} |
|
165 |
|
|
166 |
function apiVersion() |
|
167 |
{ |
|
168 |
return 2; |
|
169 |
} |
|
170 |
|
|
171 |
function isError($value) |
|
172 |
{ |
|
173 |
return PEAR::isError($value); |
|
174 |
} |
|
175 |
|
|
176 |
function isManip($query) |
|
177 |
{ |
|
178 |
return MDB2::isManip($query); |
|
179 |
} |
|
180 |
|
|
181 |
function errorMessage($value) |
|
182 |
{ |
|
183 |
return MDB2::errorMessage($value); |
|
184 |
} |
|
185 |
|
|
186 |
function parseDSN($dsn) |
|
187 |
{ |
|
188 |
return MDB2::parseDSN($dsn); |
|
189 |
} |
|
190 |
|
|
191 |
function assertExtension($name) |
|
192 |
{ |
|
193 |
if (!extension_loaded($name)) { |
|
194 |
$dlext = OS_WINDOWS ? '.dll' : '.so'; |
|
195 |
@dl($name . $dlext); |
|
196 |
} |
|
197 |
return extension_loaded($name); |
|
198 |
} |
|
199 |
} |
|
200 |
|
|
201 |
/** |
|
202 |
* MDB2_Error implements a class for reporting portable database error |
|
203 |
* messages. |
|
204 |
* |
|
205 |
* @package MDB2 |
|
206 |
* @category Database |
|
207 |
* @author Stig Bakken <ssb@fast.no> |
|
208 |
*/ |
|
209 |
class DB_Error extends PEAR_Error |
|
210 |
{ |
|
211 |
function DB_Error($code = DB_ERROR, $mode = PEAR_ERROR_RETURN, |
|
212 |
$level = E_USER_NOTICE, $debuginfo = null) |
|
213 |
{ |
|
214 |
if (is_int($code)) { |
|
215 |
$this->PEAR_Error('DB Error: ' . DB::errorMessage($code), $code, $mode, $level, $debuginfo); |
|
216 |
} else { |
|
217 |
$this->PEAR_Error("DB Error: $code", DB_ERROR, $mode, $level, $debuginfo); |
|
218 |
} |
|
219 |
} |
|
220 |
} |
|
221 |
|
|
222 |
/** |
|
223 |
* Wrapper that makes MDB2 behave like PEAR DB |
|
224 |
* |
|
225 |
* @package MDB2 |
|
226 |
* @category Database |
|
227 |
* @author Lukas Smith <smith@pooteeweet.org> |
|
228 |
*/ |
|
229 |
class DB_result extends MDB2_Result_Common |
|
230 |
{ |
|
231 |
var $result; |
|
232 |
var $row_counter = null; |
|
233 |
|
|
234 |
var $limit_from = null; |
|
235 |
|
|
236 |
var $limit_count = null; |
|
237 |
|
|
238 |
function DB_result($result) |
|
239 |
{ |
|
240 |
$this->result = $result; |
|
241 |
} |
|
242 |
|
|
243 |
function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null) |
|
244 |
{ |
|
245 |
$arr = $this->result->fetchRow($fetchmode, $rownum); |
|
246 |
if ($this->result->mdb->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) { |
|
247 |
$this->_convertNullArrayValuesToEmpty($arr); |
|
248 |
} |
|
249 |
return $arr; |
|
250 |
} |
|
251 |
|
|
252 |
function fetchInto(&$arr, $fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null) |
|
253 |
{ |
|
254 |
$arr = $this->fetchRow($fetchmode, $rownum); |
|
255 |
if ($this->result->mdb->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) { |
|
256 |
$this->_convertNullArrayValuesToEmpty($arr); |
|
257 |
} |
|
258 |
return DB_OK; |
|
259 |
} |
|
260 |
|
|
261 |
function _convertNullArrayValuesToEmpty(&$array) |
|
262 |
{ |
|
263 |
if (is_array($array)) { |
|
264 |
foreach ($array as $key => $value) { |
|
265 |
if (is_null($value)) { |
|
266 |
$array[$key] = ''; |
|
267 |
} |
|
268 |
} |
|
269 |
} |
|
270 |
} |
|
271 |
|
|
272 |
function numCols() |
|
273 |
{ |
|
274 |
return $this->result->numCols(); |
|
275 |
} |
|
276 |
|
|
277 |
function numRows() |
|
278 |
{ |
|
279 |
return $this->result->numRows(); |
|
280 |
} |
|
281 |
|
|
282 |
function nextResult() |
|
283 |
{ |
|
284 |
return $this->result->nextResult(); |
|
285 |
} |
|
286 |
|
|
287 |
function free() |
|
288 |
{ |
|
289 |
$err = $this->result->free(); |
|
290 |
if (PEAR::isError($err)) { |
|
291 |
return $err; |
|
292 |
} |
|
293 |
$this->result = false; |
|
294 |
return true; |
|
295 |
} |
|
296 |
|
|
297 |
function tableInfo($mode = null) |
|
298 |
{ |
|
299 |
$this->result->db->loadModule('Reverse'); |
|
300 |
return $this->result->db->reverse->tableInfo($this->result, $mode); |
|
301 |
} |
|
302 |
|
|
303 |
function getRowCounter() |
|
304 |
{ |
|
305 |
return $this->result->rowCount()+1+$this->result->offset; |
|
306 |
} |
|
307 |
} |
|
308 |
|
|
309 |
class DB_row |
|
310 |
{ |
|
311 |
function DB_row(&$arr) |
|
312 |
{ |
|
313 |
for (reset($arr); $key = key($arr); next($arr)) { |
|
314 |
$this->$key = &$arr[$key]; |
|
315 |
} |
|
316 |
} |
|
317 |
} |
|
318 |
|
|
319 |
class MDB2_PEARProxy extends PEAR |
|
320 |
{ |
|
321 |
var $db_object; |
|
322 |
var $phptype; |
|
323 |
var $connection; |
|
324 |
var $dsn; |
|
325 |
|
|
326 |
function MDB2_PEARProxy(&$db_object) |
|
327 |
{ |
|
328 |
$this->db_object =& $db_object; |
|
329 |
$this->PEAR('DB_Error'); |
|
330 |
$this->db_object->setOption('seqcol_name', 'id'); |
|
331 |
$this->db_object->setOption('result_wrap_class', 'DB_result'); |
|
332 |
$this->phptype = $this->db_object->phptype; |
|
333 |
$this->connection = $this->db_object->connection; |
|
334 |
$this->dsn = $this->db_object->getDSN(); |
|
335 |
} |
|
336 |
|
|
337 |
function connect($dsninfo, $persistent = false) |
|
338 |
{ |
|
339 |
$this->options['persistent'] = $presistent; |
|
340 |
return $this->db_object->connect(); |
|
341 |
} |
|
342 |
|
|
343 |
function disconnect() |
|
344 |
{ |
|
345 |
return $this->db_object->disconnect(); |
|
346 |
} |
|
347 |
|
|
348 |
function toString() |
|
349 |
{ |
|
350 |
return $this->db_object->__toString(); |
|
351 |
} |
|
352 |
|
|
353 |
function quoteString($string) |
|
354 |
{ |
|
355 |
$string = $this->quote($string); |
|
356 |
if ($string{0} == "'") { |
|
357 |
return substr($string, 1, -1); |
|
358 |
} |
|
359 |
return $string; |
|
360 |
} |
|
361 |
|
|
362 |
function quote($string) |
|
363 |
{ |
|
364 |
if (is_null($string)) { |
|
365 |
return 'NULL'; |
|
366 |
} |
|
367 |
return $this->db_object->quote($string); |
|
368 |
} |
|
369 |
|
|
370 |
function escapeSimple($str) |
|
371 |
{ |
|
372 |
return $this->db_object->escape($str); |
|
373 |
} |
|
374 |
|
|
375 |
function quoteSmart($in) |
|
376 |
{ |
|
377 |
if (is_int($in) || is_double($in)) { |
|
378 |
return $in; |
|
379 |
} elseif (is_bool($in)) { |
|
380 |
return $in ? 1 : 0; |
|
381 |
} elseif (is_null($in)) { |
|
382 |
return 'NULL'; |
|
383 |
} else { |
|
384 |
return "'" . $this->escapeSimple($in) . "'"; |
|
385 |
} |
|
386 |
} |
|
387 |
|
|
388 |
function quoteIdentifier($string) |
|
389 |
{ |
|
390 |
return $this->db_object->quoteIdentifier($string); |
|
391 |
} |
|
392 |
|
|
393 |
// map? |
|
394 |
function provides($feature) |
|
395 |
{ |
|
396 |
return $this->db_object->support($feature); |
|
397 |
} |
|
398 |
|
|
399 |
// remove? |
|
400 |
function errorCode($nativecode) |
|
401 |
{ |
|
402 |
return $this->db_object->errorCode($nativecode); |
|
403 |
} |
|
404 |
|
|
405 |
// remove? |
|
406 |
function errorMessage($dbcode) |
|
407 |
{ |
|
408 |
return $this->db_object->errorMessage($dbcode); |
|
409 |
} |
|
410 |
|
|
411 |
// remove? |
|
412 |
function &raiseError($code = MDB2_ERROR, $mode = null, $options = null, |
|
413 |
$userinfo = null, $nativecode = null) |
|
414 |
{ |
|
415 |
return $this->db_object->raiseError($code, $mode, $options, $userinfo, $nativecode); |
|
416 |
} |
|
417 |
|
|
418 |
function setFetchMode($fetchmode, $object_class = 'stdClass') |
|
419 |
{ |
|
420 |
return $this->db_object->setFetchMode($fetchmode, $object_class); |
|
421 |
} |
|
422 |
|
|
423 |
function setOption($option, $value) |
|
424 |
{ |
|
425 |
return $this->db_object->setOption($option, $value); |
|
426 |
} |
|
427 |
|
|
428 |
function getOption($option) |
|
429 |
{ |
|
430 |
return $this->db_object->getOption($option); |
|
431 |
} |
|
432 |
|
|
433 |
function prepare($query) |
|
434 |
{ |
|
435 |
// parse for ! and & |
|
436 |
// set types |
|
437 |
return $this->db_object->prepare($query); |
|
438 |
} |
|
439 |
|
|
440 |
function autoPrepare($table, $table_fields, $mode = MDB2_AUTOQUERY_INSERT, $where = false) |
|
441 |
{ |
|
442 |
$this->db_object->loadModule('Extended'); |
|
443 |
// types |
|
444 |
return $this->db_object->extended->autoPrepare($table, $table_fields, $mode, $where); |
|
445 |
} |
|
446 |
|
|
447 |
function &autoExecute($table, $fields_values, $mode, $where) |
|
448 |
{ |
|
449 |
$this->db_object->loadModule('Extended'); |
|
450 |
// types |
|
451 |
return $this->db_object->extended->autoExecute($table, $fields_values, $mode, $where); |
|
452 |
} |
|
453 |
|
|
454 |
function buildManipSQL($table, $table_fields, $mode, $where = false) |
|
455 |
{ |
|
456 |
$this->db_object->loadModule('Extended'); |
|
457 |
return $this->db_object->extended->buildManipSQL($table, $table_fields, $mode, $where); |
|
458 |
} |
|
459 |
|
|
460 |
function &execute($stmt, $data = false) |
|
461 |
{ |
|
462 |
$stmt->bindParamArray($data); |
|
463 |
return $stmt->execute(); |
|
464 |
} |
|
465 |
|
|
466 |
function executeMultiple($stmt, $data) |
|
467 |
{ |
|
468 |
$this->db_object->loadModule('Extended'); |
|
469 |
return $this->db_object->extended->executeMultiple($stmt, null, $data); |
|
470 |
} |
|
471 |
|
|
472 |
function &query($query, $params = array()) { |
|
473 |
if (sizeof($params) > 0) { |
|
474 |
$sth = $this->db_object->prepare($query); |
|
475 |
if (PEAR::isError($sth)) { |
|
476 |
return $sth; |
|
477 |
} |
|
478 |
if (!is_array($params)) { |
|
479 |
$params = array($params); |
|
480 |
} |
|
481 |
$stmt->bindParamArray($params); |
|
482 |
return $stmt->execute(); |
|
483 |
} |
|
484 |
return $this->db_object->query($query); |
|
485 |
} |
|
486 |
|
|
487 |
function simpleQuery($query) { |
|
488 |
$result = $this->db_object->query($query); |
|
489 |
if (PEAR::isError($result) || $result === MDB2_OK) { |
|
490 |
return $result; |
|
491 |
} else { |
|
492 |
return $result->result->getResource(); |
|
493 |
} |
|
494 |
} |
|
495 |
|
|
496 |
function limitQuery($query, $from, $count, $params = array()) |
|
497 |
{ |
|
498 |
$result = $this->db_object->setLimit($count, $from); |
|
499 |
if (PEAR::isError($result)) { |
|
500 |
return $result; |
|
501 |
} |
|
502 |
$result =& $this->query($query, $params); |
|
503 |
return $result; |
|
504 |
} |
|
505 |
|
|
506 |
function _convertNullArrayValuesToEmpty(&$array) |
|
507 |
{ |
|
508 |
if (is_array($array)) { |
|
509 |
foreach ($array as $key => $value) { |
|
510 |
if (is_null($value)) { |
|
511 |
$array[$key] = ''; |
|
512 |
} |
|
513 |
} |
|
514 |
} |
|
515 |
} |
|
516 |
|
|
517 |
function &getOne($query, $params = array()) |
|
518 |
{ |
|
519 |
$result = $this->query($query, $params); |
|
520 |
$one = $result->result->fetchOne(); |
|
521 |
if (is_null($one)) { |
|
522 |
$one = ''; |
|
523 |
} |
|
524 |
return $one; |
|
525 |
} |
|
526 |
|
|
527 |
function &getRow($query, |
|
528 |
$params = array(), |
|
529 |
$fetchmode = MDB2_FETCHMODE_DEFAULT) |
|
530 |
{ |
|
531 |
if (!is_array($params)) { |
|
532 |
if (is_array($fetchmode)) { |
|
533 |
if (is_null($params)) { |
|
534 |
$tmp = DB_FETCHMODE_DEFAULT; |
|
535 |
} else { |
|
536 |
$tmp = $params; |
|
537 |
} |
|
538 |
$params = $fetchmode; |
|
539 |
$fetchmode = $tmp; |
|
540 |
} elseif (!is_null($params)) { |
|
541 |
$fetchmode = $params; |
|
542 |
$params = array(); |
|
543 |
} |
|
544 |
} |
|
545 |
$result =& $this->query($query, $params); |
|
546 |
return $result->result->fetchRow($fetchmode); |
|
547 |
} |
|
548 |
|
|
549 |
function &getCol($query, $col = 0, $params = array()) |
|
550 |
{ |
|
551 |
$result =& $this->query($query, $params); |
|
552 |
$col = $result->result->fetchCol($col); |
|
553 |
$this->_convertNullArrayValuesToEmpty($col); |
|
554 |
return $col; |
|
555 |
} |
|
556 |
|
|
557 |
function &getAssoc($query, $force_array = false, $params = array(), |
|
558 |
$fetchmode = MDB2_FETCHMODE_ORDERED, $group = false) |
|
559 |
{ |
|
560 |
$result =& $this->query($query, $params); |
|
561 |
$all = $result->result->fetchAll($fetchmode, true, $force_array, $group); |
|
562 |
$first = reset($all); |
|
563 |
if (isset($first) && $this->db_object->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) { |
|
564 |
if (is_array($first)) { |
|
565 |
foreach ($all as $key => $arr) { |
|
566 |
$this->_convertNullArrayValuesToEmpty($all[$key]); |
|
567 |
} |
|
568 |
} elseif (is_object($first)) { |
|
569 |
foreach ($all as $key => $arr) { |
|
570 |
$tmp = get_object_vars($all[$key]); |
|
571 |
if (is_array($tmp)) { |
|
572 |
$this->_convertNullArrayValuesToEmpty($tmp); |
|
573 |
foreach ($tmp as $key2 => $column) { |
|
574 |
$all[$key]->{$key2} = $column; |
|
575 |
} |
|
576 |
} |
|
577 |
} |
|
578 |
} |
|
579 |
} |
|
580 |
return $all; |
|
581 |
} |
|
582 |
|
|
583 |
function &getAll($query, |
|
584 |
$params = null, |
|
585 |
$fetchmode = MDB2_FETCHMODE_DEFAULT) |
|
586 |
{ |
|
587 |
if (!is_array($params)) { |
|
588 |
if (is_array($fetchmode)) { |
|
589 |
if (is_null($params)) { |
|
590 |
$tmp = DB_FETCHMODE_DEFAULT; |
|
591 |
} else { |
|
592 |
$tmp = $params; |
|
593 |
} |
|
594 |
$params = $fetchmode; |
|
595 |
$fetchmode = $tmp; |
|
596 |
} elseif (!is_null($params)) { |
|
597 |
$fetchmode = $params; |
|
598 |
$params = array(); |
|
599 |
} |
|
600 |
} |
|
601 |
$result =& $this->query($query, $params); |
|
602 |
$all = $result->result->fetchAll($fetchmode); |
|
603 |
$first = reset($all); |
|
604 |
if (isset($first) && $this->db_object->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) { |
|
605 |
if (is_array($first)) { |
|
606 |
foreach ($all as $key => $arr) { |
|
607 |
$this->_convertNullArrayValuesToEmpty($all[$key]); |
|
608 |
} |
|
609 |
} elseif (is_object($first)) { |
|
610 |
foreach ($all as $key => $arr) { |
|
611 |
$tmp = get_object_vars($all[$key]); |
|
612 |
if (is_array($tmp)) { |
|
613 |
$this->_convertNullArrayValuesToEmpty($tmp); |
|
614 |
foreach ($tmp as $key2 => $column) { |
|
615 |
$all[$key]->{$key2} = $column; |
|
616 |
} |
|
617 |
} |
|
618 |
} |
|
619 |
} |
|
620 |
} |
|
621 |
return $all; |
|
622 |
} |
|
623 |
|
|
624 |
function autoCommit($onoff = false) |
|
625 |
{ |
|
626 |
return $this->db_object->autoCommit($onoff); |
|
627 |
} |
|
628 |
|
|
629 |
function commit() |
|
630 |
{ |
|
631 |
return $this->db_object->commit(); |
|
632 |
} |
|
633 |
|
|
634 |
function rollback() |
|
635 |
{ |
|
636 |
return $this->db_object->rollback(); |
|
637 |
} |
|
638 |
|
|
639 |
function affectedRows() |
|
640 |
{ |
|
641 |
return $this->db_object->affectedRows(); |
|
642 |
} |
|
643 |
|
|
644 |
// remove? |
|
645 |
function errorNative() |
|
646 |
{ |
|
647 |
return $this->db_object->errorNative(); |
|
648 |
} |
|
649 |
|
|
650 |
function nextId($seq_name, $ondemand = true) |
|
651 |
{ |
|
652 |
return $this->db_object->nextID($seq_name, $ondemand); |
|
653 |
} |
|
654 |
|
|
655 |
function createSequence($seq_name) |
|
656 |
{ |
|
657 |
$this->db_object->loadModule('Manager'); |
|
658 |
return $this->db_object->manager->createSequence($seq_name, 1); |
|
659 |
} |
|
660 |
|
|
661 |
function dropSequence($seq_name) |
|
662 |
{ |
|
663 |
$this->db_object->loadModule('Manager'); |
|
664 |
return $this->db_object->manager->dropSequence($seq_name); |
|
665 |
} |
|
666 |
|
|
667 |
function &_wrapResource($result) |
|
668 |
{ |
|
669 |
if (is_resource($result)) { |
|
670 |
$result_class = $this->db_object->getOption('result_buffering') |
|
671 |
? $this->db_object->getOption('buffered_result_class') : $$this->db_object->getOption('result_class'); |
|
672 |
$class_name = sprintf($result_class, $this->db_object->phptype); |
|
673 |
$result =& new $class_name($this->db_object, $result); |
|
674 |
} |
|
675 |
return $result; |
|
676 |
} |
|
677 |
|
|
678 |
function fetchInto($result, &$arr, $fetchmode, $rownum = null) |
|
679 |
{ |
|
680 |
$result = $this->_wrapResource($result); |
|
681 |
if (!is_null($rownum)) { |
|
682 |
$result->result->seek($rownum); |
|
683 |
} |
|
684 |
$arr = $result->fetchRow($fetchmode); |
|
685 |
} |
|
686 |
|
|
687 |
function freePrepared($prepared) |
|
688 |
{ |
|
689 |
return $this->db_object->freePrepared($prepared); |
|
690 |
} |
|
691 |
|
|
692 |
function freeResult($result) |
|
693 |
{ |
|
694 |
$result = $this->_wrapResource($result); |
|
695 |
return $result->free(); |
|
696 |
} |
|
697 |
|
|
698 |
function numCols($result) |
|
699 |
{ |
|
700 |
$result = $this->_wrapResource($result); |
|
701 |
return $result->numCols(); |
|
702 |
} |
|
703 |
|
|
704 |
function numRows($result) |
|
705 |
{ |
|
706 |
$result = $this->_wrapResource($result); |
|
707 |
return $result->numRows(); |
|
708 |
} |
|
709 |
|
|
710 |
function nextResult($result) |
|
711 |
{ |
|
712 |
$result = $this->_wrapResource($result); |
|
713 |
return $result->nextResult(); |
|
714 |
} |
|
715 |
|
|
716 |
function tableInfo($result, $mode = null) |
|
717 |
{ |
|
718 |
$result = $this->_wrapResource($result); |
|
719 |
if (is_string($result) || MDB2::isResultCommon($result)) { |
|
720 |
$this->db_object->loadModule('Reverse'); |
|
721 |
return $this->db_object->reverse->tableInfo($result, $mode); |
|
722 |
} |
|
723 |
return $result->tableInfo($mode); |
|
724 |
} |
|
725 |
|
|
726 |
function getTables() |
|
727 |
{ |
|
728 |
return $this->getListOf('tables'); |
|
729 |
} |
|
730 |
|
|
731 |
function getListOf($type) |
|
732 |
{ |
|
733 |
$this->db_object->loadModule('Manager'); |
|
734 |
switch ($type) { |
|
735 |
case 'tables': |
|
736 |
return $this->db_object->manager->listTables(); |
|
737 |
case 'views': |
|
738 |
return $this->db_object->manager->listViews(); |
|
739 |
case 'users': |
|
740 |
return $this->db_object->manager->listUsers(); |
|
741 |
case 'functions': |
|
742 |
return $this->db_object->manager->listFunctions(); |
|
743 |
case 'databases': |
|
744 |
return $this->db_object->manager->listDatabases(); |
|
745 |
default: |
|
746 |
return $this->db_object->raiseError(MDB2_ERROR_UNSUPPORTED); |
|
747 |
} |
|
748 |
} |
|
749 |
} |
|
750 |
?> |