2
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
3
// +----------------------------------------------------------------------+
5
// +----------------------------------------------------------------------+
6
// | Copyright (c) 1997-2004 The PHP Group |
7
// +----------------------------------------------------------------------+
8
// | This source file is subject to version 2.02 of the PHP license, |
9
// | that is bundled with this package in the file LICENSE, and is |
10
// | available at through the world-wide-web at |
11
// | http://www.php.net/license/2_02.txt. |
12
// | If you did not receive a copy of the PHP license and are unable to |
13
// | obtain it through the world-wide-web, please send a note to |
14
// | license@php.net so we can mail you a copy immediately. |
15
// +----------------------------------------------------------------------+
16
// | Authors: Stig Bakken <ssb@php.net> |
17
// | Tomas V.V.Cox <cox@idecnet.com> |
18
// | Maintainer: Daniel Convissor <danielc@php.net> |
19
// +----------------------------------------------------------------------+
21
// $Id: DB.php 6184 2008-08-22 10:33:41Z vargenau $
23
// Database independent query interface.
26
require_once 'PEAR.php';
32
* The method mapErrorCode in each DB_dbtype implementation maps
33
* native error codes to one of these.
35
* If you add an error code here, make sure you also add a textual
36
* version of it in DB::errorMessage().
39
define('DB_ERROR', -1);
40
define('DB_ERROR_SYNTAX', -2);
41
define('DB_ERROR_CONSTRAINT', -3);
42
define('DB_ERROR_NOT_FOUND', -4);
43
define('DB_ERROR_ALREADY_EXISTS', -5);
44
define('DB_ERROR_UNSUPPORTED', -6);
45
define('DB_ERROR_MISMATCH', -7);
46
define('DB_ERROR_INVALID', -8);
47
define('DB_ERROR_NOT_CAPABLE', -9);
48
define('DB_ERROR_TRUNCATED', -10);
49
define('DB_ERROR_INVALID_NUMBER', -11);
50
define('DB_ERROR_INVALID_DATE', -12);
51
define('DB_ERROR_DIVZERO', -13);
52
define('DB_ERROR_NODBSELECTED', -14);
53
define('DB_ERROR_CANNOT_CREATE', -15);
54
define('DB_ERROR_CANNOT_DELETE', -16);
55
define('DB_ERROR_CANNOT_DROP', -17);
56
define('DB_ERROR_NOSUCHTABLE', -18);
57
define('DB_ERROR_NOSUCHFIELD', -19);
58
define('DB_ERROR_NEED_MORE_DATA', -20);
59
define('DB_ERROR_NOT_LOCKED', -21);
60
define('DB_ERROR_VALUE_COUNT_ON_ROW', -22);
61
define('DB_ERROR_INVALID_DSN', -23);
62
define('DB_ERROR_CONNECT_FAILED', -24);
63
define('DB_ERROR_EXTENSION_NOT_FOUND',-25);
64
define('DB_ERROR_ACCESS_VIOLATION', -26);
65
define('DB_ERROR_NOSUCHDB', -27);
66
define('DB_ERROR_CONSTRAINT_NOT_NULL',-29);
70
// {{{ prepared statement-related
74
* These constants are used when storing information about prepared
75
* statements (using the "prepare" method in DB_dbtype).
77
* The prepare/execute model in DB is mostly borrowed from the ODBC
78
* extension, in a query the "?" character means a scalar parameter.
79
* There are two extensions though, a "&" character means an opaque
80
* parameter. An opaque parameter is simply a file name, the real
81
* data are in that file (useful for putting uploaded files into your
82
* database and such). The "!" char means a parameter that must be
84
* They modify the quote behavoir:
85
* DB_PARAM_SCALAR (?) => 'original string quoted'
86
* DB_PARAM_OPAQUE (&) => 'string from file quoted'
87
* DB_PARAM_MISC (!) => original string
89
define('DB_PARAM_SCALAR', 1);
90
define('DB_PARAM_OPAQUE', 2);
91
define('DB_PARAM_MISC', 3);
95
// {{{ binary data-related
99
* These constants define different ways of returning binary data
100
* from queries. Again, this model has been borrowed from the ODBC
103
* DB_BINMODE_PASSTHRU sends the data directly through to the browser
104
* when data is fetched from the database.
105
* DB_BINMODE_RETURN lets you return data as usual.
106
* DB_BINMODE_CONVERT returns data as well, only it is converted to
107
* hex format, for example the string "123" would become "313233".
109
define('DB_BINMODE_PASSTHRU', 1);
110
define('DB_BINMODE_RETURN', 2);
111
define('DB_BINMODE_CONVERT', 3);
119
* This is a special constant that tells DB the user hasn't specified
120
* any particular get mode, so the default should be used.
122
define('DB_FETCHMODE_DEFAULT', 0);
125
* Column data indexed by numbers, ordered from 0 and up
127
define('DB_FETCHMODE_ORDERED', 1);
130
* Column data indexed by column names
132
define('DB_FETCHMODE_ASSOC', 2);
135
* Column data as object properties
137
define('DB_FETCHMODE_OBJECT', 3);
140
* For multi-dimensional results: normally the first level of arrays
141
* is the row number, and the second level indexed by column number or name.
142
* DB_FETCHMODE_FLIPPED switches this order, so the first level of arrays
143
* is the column name, and the second level the row number.
145
define('DB_FETCHMODE_FLIPPED', 4);
147
/* for compatibility */
148
define('DB_GETMODE_ORDERED', DB_FETCHMODE_ORDERED);
149
define('DB_GETMODE_ASSOC', DB_FETCHMODE_ASSOC);
150
define('DB_GETMODE_FLIPPED', DB_FETCHMODE_FLIPPED);
154
// {{{ tableInfo() && autoPrepare()-related
158
* these are constants for the tableInfo-function
159
* they are bitwised or'ed. so if there are more constants to be defined
160
* in the future, adjust DB_TABLEINFO_FULL accordingly
162
define('DB_TABLEINFO_ORDER', 1);
163
define('DB_TABLEINFO_ORDERTABLE', 2);
164
define('DB_TABLEINFO_FULL', 3);
167
* Used by autoPrepare()
169
define('DB_AUTOQUERY_INSERT', 1);
170
define('DB_AUTOQUERY_UPDATE', 2);
174
// {{{ portability modes
178
* Portability: turn off all portability features.
179
* @see DB_common::setOption()
181
define('DB_PORTABILITY_NONE', 0);
184
* Portability: convert names of tables and fields to lower case
185
* when using the get*(), fetch*() and tableInfo() methods.
186
* @see DB_common::setOption()
188
define('DB_PORTABILITY_LOWERCASE', 1);
191
* Portability: right trim the data output by get*() and fetch*().
192
* @see DB_common::setOption()
194
define('DB_PORTABILITY_RTRIM', 2);
197
* Portability: force reporting the number of rows deleted.
198
* @see DB_common::setOption()
200
define('DB_PORTABILITY_DELETE_COUNT', 4);
203
* Portability: enable hack that makes numRows() work in Oracle.
204
* @see DB_common::setOption()
206
define('DB_PORTABILITY_NUMROWS', 8);
209
* Portability: makes certain error messages in certain drivers compatible
210
* with those from other DBMS's.
212
* + mysql, mysqli: change unique/primary key constraints
213
* DB_ERROR_ALREADY_EXISTS -> DB_ERROR_CONSTRAINT
215
* + odbc(access): MS's ODBC driver reports 'no such field' as code
216
* 07001, which means 'too few parameters.' When this option is on
217
* that code gets mapped to DB_ERROR_NOSUCHFIELD.
219
* @see DB_common::setOption()
221
define('DB_PORTABILITY_ERRORS', 16);
224
* Portability: convert null values to empty strings in data output by
225
* get*() and fetch*().
226
* @see DB_common::setOption()
228
define('DB_PORTABILITY_NULL_TO_EMPTY', 32);
231
* Portability: turn on all portability features.
232
* @see DB_common::setOption()
234
define('DB_PORTABILITY_ALL', 63);
243
* The main "DB" class is simply a container class with some static
244
* methods for creating DB objects as well as some utility functions
245
* common to all parts of DB.
247
* The object model of DB is as follows (indentation means inheritance):
249
* DB The main DB class. This is simply a utility class
250
* with some "static" methods for creating DB objects as
251
* well as common utility functions for other DB classes.
253
* DB_common The base for each DB implementation. Provides default
254
* | implementations (in OO lingo virtual methods) for
255
* | the actual DB implementations as well as a bunch of
256
* | query utility functions.
258
* +-DB_mysql The DB implementation for MySQL. Inherits DB_common.
259
* When calling DB::factory or DB::connect for MySQL
260
* connections, the object returned is an instance of this
264
* @author Stig Bakken <ssb@php.net>
265
* @author Tomas V.V.Cox <cox@idecnet.com>
267
* @version $Id: DB.php 6184 2008-08-22 10:33:41Z vargenau $
275
* Create a new DB object for the specified database type.
277
* Allows creation of a DB_<driver> object from which the object's
278
* methods can be utilized without actually connecting to a database.
280
* @param string $type database type, for example "mysql"
281
* @param array $options associative array of option names and values
283
* @return object a new DB object. On error, an error object.
285
* @see DB_common::setOption()
288
function &factory($type, $options = false)
290
if (!is_array($options)) {
291
$options = array('persistent' => $options);
294
if (isset($options['debug']) && $options['debug'] >= 2) {
295
// expose php errors with sufficient debug level
296
include_once "DB/{$type}.php";
298
@include_once "DB/{$type}.php";
301
$classname = "DB_${type}";
303
if (!class_exists($classname)) {
304
$tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null,
305
"Unable to include the DB/{$type}.php file",
310
@$obj =& new $classname;
312
foreach ($options as $option => $value) {
313
$test = $obj->setOption($option, $value);
314
if (DB::isError($test)) {
326
* Create a new DB object and connect to the specified database.
330
* require_once 'DB.php';
332
* $dsn = 'mysql://user:password@host/database'
335
* 'portability' => DB_PORTABILITY_ALL,
338
* $dbh =& DB::connect($dsn, $options);
339
* if (DB::isError($dbh)) {
340
* die($dbh->getMessage());
344
* @param mixed $dsn string "data source name" or an array in the
345
* format returned by DB::parseDSN()
347
* @param array $options an associative array of option names and
350
* @return object a newly created DB connection object, or a DB
351
* error object on error
353
* @see DB::parseDSN(), DB_common::setOption(), DB::isError()
356
function &connect($dsn, $options = array())
358
$dsninfo = DB::parseDSN($dsn);
359
$type = $dsninfo['phptype'];
361
if (!is_array($options)) {
363
* For backwards compatibility. $options used to be boolean,
364
* indicating whether the connection should be persistent.
366
$options = array('persistent' => $options);
369
if (isset($options['debug']) && $options['debug'] >= 2) {
370
// expose php errors with sufficient debug level
371
include_once "DB/${type}.php";
373
@include_once "DB/${type}.php";
376
$classname = "DB_${type}";
377
if (!class_exists($classname)) {
378
$tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null,
379
"Unable to include the DB/{$type}.php file for `$dsn'",
384
@$obj =& new $classname;
386
foreach ($options as $option => $value) {
387
$test = $obj->setOption($option, $value);
388
if (DB::isError($test)) {
393
$err = $obj->connect($dsninfo, $obj->getOption('persistent'));
394
if (DB::isError($err)) {
395
$err->addUserInfo($dsn);
406
* Return the DB API version
408
* @return int the DB API version number
412
function apiVersion()
421
* Tell whether a result code from a DB method is an error
423
* @param int $value result code
425
* @return bool whether $value is an error
429
function isError($value)
431
return is_a($value, 'DB_Error');
435
// {{{ isConnection()
438
* Tell whether a value is a DB connection
440
* @param mixed $value value to test
442
* @return bool whether $value is a DB connection
446
function isConnection($value)
448
return (is_object($value) &&
449
is_subclass_of($value, 'db_common') &&
450
method_exists($value, 'simpleQuery'));
457
* Tell whether a query is a data manipulation query (insert,
458
* update or delete) or a data definition query (create, drop,
459
* alter, grant, revoke).
463
* @param string $query the query
465
* @return boolean whether $query is a data manipulation query
467
function isManip($query)
469
$manips = 'INSERT|UPDATE|DELETE|LOAD DATA|'.'REPLACE|CREATE|DROP|'.
470
'ALTER|GRANT|REVOKE|'.'LOCK|UNLOCK';
471
if (preg_match('/^\s*"?('.$manips.')\s+/i', $query)) {
478
// {{{ errorMessage()
481
* Return a textual error message for a DB error code
483
* @param integer $value error code
485
* @return string error message, or false if the error code was
488
function errorMessage($value)
490
static $errorMessages;
491
if (!isset($errorMessages)) {
492
$errorMessages = array(
493
DB_ERROR => 'unknown error',
494
DB_ERROR_ALREADY_EXISTS => 'already exists',
495
DB_ERROR_CANNOT_CREATE => 'can not create',
496
DB_ERROR_CANNOT_DELETE => 'can not delete',
497
DB_ERROR_CANNOT_DROP => 'can not drop',
498
DB_ERROR_CONSTRAINT => 'constraint violation',
499
DB_ERROR_CONSTRAINT_NOT_NULL=> 'null value violates not-null constraint',
500
DB_ERROR_DIVZERO => 'division by zero',
501
DB_ERROR_INVALID => 'invalid',
502
DB_ERROR_INVALID_DATE => 'invalid date or time',
503
DB_ERROR_INVALID_NUMBER => 'invalid number',
504
DB_ERROR_MISMATCH => 'mismatch',
505
DB_ERROR_NODBSELECTED => 'no database selected',
506
DB_ERROR_NOSUCHFIELD => 'no such field',
507
DB_ERROR_NOSUCHTABLE => 'no such table',
508
DB_ERROR_NOT_CAPABLE => 'DB backend not capable',
509
DB_ERROR_NOT_FOUND => 'not found',
510
DB_ERROR_NOT_LOCKED => 'not locked',
511
DB_ERROR_SYNTAX => 'syntax error',
512
DB_ERROR_UNSUPPORTED => 'not supported',
513
DB_ERROR_VALUE_COUNT_ON_ROW => 'value count on row',
514
DB_ERROR_INVALID_DSN => 'invalid DSN',
515
DB_ERROR_CONNECT_FAILED => 'connect failed',
517
DB_ERROR_NEED_MORE_DATA => 'insufficient data supplied',
518
DB_ERROR_EXTENSION_NOT_FOUND=> 'extension not found',
519
DB_ERROR_NOSUCHDB => 'no such database',
520
DB_ERROR_ACCESS_VIOLATION => 'insufficient permissions',
521
DB_ERROR_TRUNCATED => 'truncated'
525
if (DB::isError($value)) {
526
$value = $value->getCode();
529
return isset($errorMessages[$value]) ? $errorMessages[$value] : $errorMessages[DB_ERROR];
536
* Parse a data source name.
538
* Additional keys can be added by appending a URI query string to the
541
* The format of the supplied DSN is in its fullest form:
543
* phptype(dbsyntax)://username:password@protocol+hostspec/database?option=8&another=true
546
* Most variations are allowed:
548
* phptype://username:password@protocol+hostspec:110//usr/db_file.db?mode=0644
549
* phptype://username:password@hostspec/database_name
550
* phptype://username:password@hostspec
551
* phptype://username@hostspec
552
* phptype://hostspec/database
558
* @param string $dsn Data Source Name to be parsed
560
* @return array an associative array with the following keys:
561
* + phptype: Database backend used in PHP (mysql, odbc etc.)
562
* + dbsyntax: Database used with regards to SQL syntax etc.
563
* + protocol: Communication protocol to use (tcp, unix etc.)
564
* + hostspec: Host specification (hostname[:port])
565
* + database: Database to use on the DBMS server
566
* + username: User name for login
567
* + password: Password for login
569
* @author Tomas V.V.Cox <cox@idecnet.com>
571
function parseDSN($dsn)
585
if (is_array($dsn)) {
586
$dsn = array_merge($parsed, $dsn);
587
if (!$dsn['dbsyntax']) {
588
$dsn['dbsyntax'] = $dsn['phptype'];
593
// Find phptype and dbsyntax
594
if (($pos = strpos($dsn, '://')) !== false) {
595
$str = substr($dsn, 0, $pos);
596
$dsn = substr($dsn, $pos + 3);
602
// Get phptype and dbsyntax
603
// $str => phptype(dbsyntax)
604
if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) {
605
$parsed['phptype'] = $arr[1];
606
$parsed['dbsyntax'] = !$arr[2] ? $arr[1] : $arr[2];
608
$parsed['phptype'] = $str;
609
$parsed['dbsyntax'] = $str;
616
// Get (if found): username and password
617
// $dsn => username:password@protocol+hostspec/database
618
if (($at = strrpos($dsn,'@')) !== false) {
619
$str = substr($dsn, 0, $at);
620
$dsn = substr($dsn, $at + 1);
621
if (($pos = strpos($str, ':')) !== false) {
622
$parsed['username'] = rawurldecode(substr($str, 0, $pos));
623
$parsed['password'] = rawurldecode(substr($str, $pos + 1));
625
$parsed['username'] = rawurldecode($str);
629
// Find protocol and hostspec
631
// $dsn => proto(proto_opts)/database
632
if (preg_match('|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match)) {
634
$proto_opts = $match[2] ? $match[2] : false;
637
// $dsn => protocol+hostspec/database (old format)
639
if (strpos($dsn, '+') !== false) {
640
list($proto, $dsn) = explode('+', $dsn, 2);
642
if (strpos($dsn, '/') !== false) {
643
list($proto_opts, $dsn) = explode('/', $dsn, 2);
650
// process the different protocol options
651
$parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp';
652
$proto_opts = rawurldecode($proto_opts);
653
if ($parsed['protocol'] == 'tcp') {
654
if (strpos($proto_opts, ':') !== false) {
655
list($parsed['hostspec'], $parsed['port']) = explode(':', $proto_opts);
657
$parsed['hostspec'] = $proto_opts;
659
} elseif ($parsed['protocol'] == 'unix') {
660
$parsed['socket'] = $proto_opts;
667
if (($pos = strpos($dsn, '?')) === false) {
668
$parsed['database'] = $dsn;
669
// /database?param1=value1¶m2=value2
671
$parsed['database'] = substr($dsn, 0, $pos);
672
$dsn = substr($dsn, $pos + 1);
673
if (strpos($dsn, '&') !== false) {
674
$opts = explode('&', $dsn);
675
} else { // database?param1=value1
678
foreach ($opts as $opt) {
679
list($key, $value) = explode('=', $opt);
680
if (!isset($parsed[$key])) {
681
// don't allow params overwrite
682
$parsed[$key] = rawurldecode($value);
692
// {{{ assertExtension()
695
* Load a PHP database extension if it is not loaded already.
699
* @param string $name the base name of the extension (without the .so or
702
* @return boolean true if the extension was already or successfully
703
* loaded, false if it could not be loaded
705
function assertExtension($name)
707
if (!extension_loaded($name)) {
708
$dlext = OS_WINDOWS ? '.dll' : '.so';
709
$dlprefix = OS_WINDOWS ? 'php_' : '';
710
@dl($dlprefix . $name . $dlext);
711
return extension_loaded($name);
719
// {{{ class DB_Error
722
* DB_Error implements a class for reporting portable database error
726
* @author Stig Bakken <ssb@php.net>
728
class DB_Error extends PEAR_Error
733
* DB_Error constructor.
735
* @param mixed $code DB error code, or string with error message.
736
* @param integer $mode what "error mode" to operate in
737
* @param integer $level what error level to use for $mode & PEAR_ERROR_TRIGGER
738
* @param mixed $debuginfo additional debug info, such as the last query
744
function DB_Error($code = DB_ERROR, $mode = PEAR_ERROR_RETURN,
745
$level = E_USER_NOTICE, $debuginfo = null)
748
$this->PEAR_Error('DB Error: ' . DB::errorMessage($code), $code, $mode, $level, $debuginfo);
750
$this->PEAR_Error("DB Error: $code", DB_ERROR, $mode, $level, $debuginfo);
757
// {{{ class DB_result
760
* This class implements a wrapper for a DB result set.
761
* A new instance of this class will be returned by the DB implementation
762
* after processing a query that returns data.
765
* @author Stig Bakken <ssb@php.net>
773
var $row_counter = null;
776
* for limit queries, the row to start fetching
779
var $limit_from = null;
782
* for limit queries, the number of rows to fetch
785
var $limit_count = null;
791
* DB_result constructor.
792
* @param resource &$dbh DB object reference
793
* @param resource $result result resource id
794
* @param array $options assoc array with optional result options
796
function DB_result(&$dbh, $result, $options = array())
799
$this->result = $result;
800
foreach ($options as $key => $value) {
801
$this->setOption($key, $value);
803
$this->limit_type = $dbh->features['limit'];
804
$this->autofree = $dbh->options['autofree'];
805
$this->fetchmode = $dbh->fetchmode;
806
$this->fetchmode_object_class = $dbh->fetchmode_object_class;
809
function setOption($key, $value = null)
813
$this->limit_from = $value; break;
815
$this->limit_count = $value; break;
823
* Fetch a row of data and return it by reference into an array.
825
* The type of array returned can be controlled either by setting this
826
* method's <var>$fetchmode</var> parameter or by changing the default
827
* fetch mode setFetchMode() before calling this method.
829
* There are two options for standardizing the information returned
830
* from databases, ensuring their values are consistent when changing
831
* DBMS's. These portability options can be turned on when creating a
832
* new DB object or by using setOption().
834
* + <samp>DB_PORTABILITY_LOWERCASE</samp>
835
* convert names of fields to lower case
837
* + <samp>DB_PORTABILITY_RTRIM</samp>
838
* right trim the data
840
* @param int $fetchmode how the resulting array should be indexed
841
* @param int $rownum the row number to fetch
843
* @return array a row of data, null on no more rows or PEAR_Error
846
* @see DB_common::setOption(), DB_common::setFetchMode()
849
function &fetchRow($fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null)
851
if ($fetchmode === DB_FETCHMODE_DEFAULT) {
852
$fetchmode = $this->fetchmode;
854
if ($fetchmode === DB_FETCHMODE_OBJECT) {
855
$fetchmode = DB_FETCHMODE_ASSOC;
856
$object_class = $this->fetchmode_object_class;
858
if ($this->limit_from !== null) {
859
if ($this->row_counter === null) {
860
$this->row_counter = $this->limit_from;
862
if ($this->limit_type == false) {
864
while ($i++ < $this->limit_from) {
865
$this->dbh->fetchInto($this->result, $arr, $fetchmode);
869
if ($this->row_counter >= (
870
$this->limit_from + $this->limit_count))
872
if ($this->autofree) {
878
if ($this->limit_type == 'emulate') {
879
$rownum = $this->row_counter;
881
$this->row_counter++;
883
$res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum);
884
if ($res === DB_OK) {
885
if (isset($object_class)) {
886
// default mode specified in DB_common::fetchmode_object_class property
887
if ($object_class == 'stdClass') {
888
$arr = (object) $arr;
890
$arr = &new $object_class($arr);
895
if ($res == null && $this->autofree) {
905
* Fetch a row of data into an array which is passed by reference.
907
* The type of array returned can be controlled either by setting this
908
* method's <var>$fetchmode</var> parameter or by changing the default
909
* fetch mode setFetchMode() before calling this method.
911
* There are two options for standardizing the information returned
912
* from databases, ensuring their values are consistent when changing
913
* DBMS's. These portability options can be turned on when creating a
914
* new DB object or by using setOption().
916
* + <samp>DB_PORTABILITY_LOWERCASE</samp>
917
* convert names of fields to lower case
919
* + <samp>DB_PORTABILITY_RTRIM</samp>
920
* right trim the data
922
* @param array &$arr (reference) array where data from the row
924
* @param int $fetchmode how the resulting array should be indexed
925
* @param int $rownum the row number to fetch
927
* @return mixed DB_OK on success, null on no more rows or
928
* a DB_Error object on error
930
* @see DB_common::setOption(), DB_common::setFetchMode()
933
function fetchInto(&$arr, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null)
935
if ($fetchmode === DB_FETCHMODE_DEFAULT) {
936
$fetchmode = $this->fetchmode;
938
if ($fetchmode === DB_FETCHMODE_OBJECT) {
939
$fetchmode = DB_FETCHMODE_ASSOC;
940
$object_class = $this->fetchmode_object_class;
942
if ($this->limit_from !== null) {
943
if ($this->row_counter === null) {
944
$this->row_counter = $this->limit_from;
946
if ($this->limit_type == false) {
948
while ($i++ < $this->limit_from) {
949
$this->dbh->fetchInto($this->result, $arr, $fetchmode);
953
if ($this->row_counter >= (
954
$this->limit_from + $this->limit_count))
956
if ($this->autofree) {
961
if ($this->limit_type == 'emulate') {
962
$rownum = $this->row_counter;
965
$this->row_counter++;
967
$res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum);
968
if ($res === DB_OK) {
969
if (isset($object_class)) {
970
// default mode specified in DB_common::fetchmode_object_class property
971
if ($object_class == 'stdClass') {
972
$arr = (object) $arr;
974
$arr = new $object_class($arr);
979
if ($res == null && $this->autofree) {
989
* Get the the number of columns in a result set.
991
* @return int the number of columns, or a DB error
997
return $this->dbh->numCols($this->result);
1004
* Get the number of rows in a result set.
1006
* @return int the number of rows, or a DB error
1012
return $this->dbh->numRows($this->result);
1019
* Get the next result if a batch of queries was executed.
1021
* @return bool true if a new result is available or false if not.
1025
function nextResult()
1027
return $this->dbh->nextResult($this->result);
1034
* Frees the resources allocated for this result set.
1035
* @return int error code
1041
$err = $this->dbh->freeResult($this->result);
1042
if (DB::isError($err)) {
1045
$this->result = false;
1055
* @see DB_common::tableInfo()
1057
function tableInfo($mode = null)
1059
if (is_string($mode)) {
1060
return $this->dbh->raiseError(DB_ERROR_NEED_MORE_DATA);
1062
return $this->dbh->tableInfo($this, $mode);
1066
// {{{ getRowCounter()
1069
* returns the actual row number
1072
function getRowCounter()
1074
return $this->row_counter;
1083
* Pear DB Row Object
1084
* @see DB_common::setFetchMode()
1093
* @param resource row data as array
1095
function DB_row(&$arr)
1097
foreach ($arr as $key => $value) {
1098
$this->$key = &$arr[$key];