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 // +----------------------------------------------------------------------+
23 // Database independent query interface.
25 require_once 'PEAR.php';
31 * The method mapErrorCode in each DB_dbtype implementation maps
32 * native error codes to one of these.
34 * If you add an error code here, make sure you also add a textual
35 * version of it in DB::errorMessage().
38 define('DB_ERROR', -1);
39 define('DB_ERROR_SYNTAX', -2);
40 define('DB_ERROR_CONSTRAINT', -3);
41 define('DB_ERROR_NOT_FOUND', -4);
42 define('DB_ERROR_ALREADY_EXISTS', -5);
43 define('DB_ERROR_UNSUPPORTED', -6);
44 define('DB_ERROR_MISMATCH', -7);
45 define('DB_ERROR_INVALID', -8);
46 define('DB_ERROR_NOT_CAPABLE', -9);
47 define('DB_ERROR_TRUNCATED', -10);
48 define('DB_ERROR_INVALID_NUMBER', -11);
49 define('DB_ERROR_INVALID_DATE', -12);
50 define('DB_ERROR_DIVZERO', -13);
51 define('DB_ERROR_NODBSELECTED', -14);
52 define('DB_ERROR_CANNOT_CREATE', -15);
53 define('DB_ERROR_CANNOT_DELETE', -16);
54 define('DB_ERROR_CANNOT_DROP', -17);
55 define('DB_ERROR_NOSUCHTABLE', -18);
56 define('DB_ERROR_NOSUCHFIELD', -19);
57 define('DB_ERROR_NEED_MORE_DATA', -20);
58 define('DB_ERROR_NOT_LOCKED', -21);
59 define('DB_ERROR_VALUE_COUNT_ON_ROW', -22);
60 define('DB_ERROR_INVALID_DSN', -23);
61 define('DB_ERROR_CONNECT_FAILED', -24);
62 define('DB_ERROR_EXTENSION_NOT_FOUND',-25);
63 define('DB_ERROR_ACCESS_VIOLATION', -26);
64 define('DB_ERROR_NOSUCHDB', -27);
65 define('DB_ERROR_CONSTRAINT_NOT_NULL',-29);
68 // {{{ prepared statement-related
71 * These constants are used when storing information about prepared
72 * statements (using the "prepare" method in DB_dbtype).
74 * The prepare/execute model in DB is mostly borrowed from the ODBC
75 * extension, in a query the "?" character means a scalar parameter.
76 * There are two extensions though, a "&" character means an opaque
77 * parameter. An opaque parameter is simply a file name, the real
78 * data are in that file (useful for putting uploaded files into your
79 * database and such). The "!" char means a parameter that must be
81 * They modify the quote behavoir:
82 * DB_PARAM_SCALAR (?) => 'original string quoted'
83 * DB_PARAM_OPAQUE (&) => 'string from file quoted'
84 * DB_PARAM_MISC (!) => original string
86 define('DB_PARAM_SCALAR', 1);
87 define('DB_PARAM_OPAQUE', 2);
88 define('DB_PARAM_MISC', 3);
91 // {{{ binary data-related
94 * These constants define different ways of returning binary data
95 * from queries. Again, this model has been borrowed from the ODBC
98 * DB_BINMODE_PASSTHRU sends the data directly through to the browser
99 * when data is fetched from the database.
100 * DB_BINMODE_RETURN lets you return data as usual.
101 * DB_BINMODE_CONVERT returns data as well, only it is converted to
102 * hex format, for example the string "123" would become "313233".
104 define('DB_BINMODE_PASSTHRU', 1);
105 define('DB_BINMODE_RETURN', 2);
106 define('DB_BINMODE_CONVERT', 3);
112 * This is a special constant that tells DB the user hasn't specified
113 * any particular get mode, so the default should be used.
115 define('DB_FETCHMODE_DEFAULT', 0);
118 * Column data indexed by numbers, ordered from 0 and up
120 define('DB_FETCHMODE_ORDERED', 1);
123 * Column data indexed by column names
125 define('DB_FETCHMODE_ASSOC', 2);
128 * Column data as object properties
130 define('DB_FETCHMODE_OBJECT', 3);
133 * For multi-dimensional results: normally the first level of arrays
134 * is the row number, and the second level indexed by column number or name.
135 * DB_FETCHMODE_FLIPPED switches this order, so the first level of arrays
136 * is the column name, and the second level the row number.
138 define('DB_FETCHMODE_FLIPPED', 4);
140 /* for compatibility */
141 define('DB_GETMODE_ORDERED', DB_FETCHMODE_ORDERED);
142 define('DB_GETMODE_ASSOC', DB_FETCHMODE_ASSOC);
143 define('DB_GETMODE_FLIPPED', DB_FETCHMODE_FLIPPED);
147 // {{{ tableInfo() && autoPrepare()-related
151 * these are constants for the tableInfo-function
152 * they are bitwised or'ed. so if there are more constants to be defined
153 * in the future, adjust DB_TABLEINFO_FULL accordingly
155 define('DB_TABLEINFO_ORDER', 1);
156 define('DB_TABLEINFO_ORDERTABLE', 2);
157 define('DB_TABLEINFO_FULL', 3);
160 * Used by autoPrepare()
162 define('DB_AUTOQUERY_INSERT', 1);
163 define('DB_AUTOQUERY_UPDATE', 2);
166 // {{{ portability modes
169 * Portability: turn off all portability features.
170 * @see DB_common::setOption()
172 define('DB_PORTABILITY_NONE', 0);
175 * Portability: convert names of tables and fields to lower case
176 * when using the get*(), fetch*() and tableInfo() methods.
177 * @see DB_common::setOption()
179 define('DB_PORTABILITY_LOWERCASE', 1);
182 * Portability: right trim the data output by get*() and fetch*().
183 * @see DB_common::setOption()
185 define('DB_PORTABILITY_RTRIM', 2);
188 * Portability: force reporting the number of rows deleted.
189 * @see DB_common::setOption()
191 define('DB_PORTABILITY_DELETE_COUNT', 4);
194 * Portability: enable hack that makes numRows() work in Oracle.
195 * @see DB_common::setOption()
197 define('DB_PORTABILITY_NUMROWS', 8);
200 * Portability: makes certain error messages in certain drivers compatible
201 * with those from other DBMS's.
203 * + mysql, mysqli: change unique/primary key constraints
204 * DB_ERROR_ALREADY_EXISTS -> DB_ERROR_CONSTRAINT
206 * + odbc(access): MS's ODBC driver reports 'no such field' as code
207 * 07001, which means 'too few parameters.' When this option is on
208 * that code gets mapped to DB_ERROR_NOSUCHFIELD.
210 * @see DB_common::setOption()
212 define('DB_PORTABILITY_ERRORS', 16);
215 * Portability: convert null values to empty strings in data output by
216 * get*() and fetch*().
217 * @see DB_common::setOption()
219 define('DB_PORTABILITY_NULL_TO_EMPTY', 32);
222 * Portability: turn on all portability features.
223 * @see DB_common::setOption()
225 define('DB_PORTABILITY_ALL', 63);
233 * The main "DB" class is simply a container class with some static
234 * methods for creating DB objects as well as some utility functions
235 * common to all parts of DB.
237 * The object model of DB is as follows (indentation means inheritance):
239 * DB The main DB class. This is simply a utility class
240 * with some "static" methods for creating DB objects as
241 * well as common utility functions for other DB classes.
243 * DB_common The base for each DB implementation. Provides default
244 * | implementations (in OO lingo virtual methods) for
245 * | the actual DB implementations as well as a bunch of
246 * | query utility functions.
248 * +-DB_mysql The DB implementation for MySQL. Inherits DB_common.
249 * When calling DB::factory or DB::connect for MySQL
250 * connections, the object returned is an instance of this
254 * @author Stig Bakken <ssb@php.net>
255 * @author Tomas V.V.Cox <cox@idecnet.com>
265 * Create a new DB object for the specified database type.
267 * Allows creation of a DB_<driver> object from which the object's
268 * methods can be utilized without actually connecting to a database.
270 * @param string $type database type, for example "mysql"
271 * @param array $options associative array of option names and values
273 * @return object a new DB object. On error, an error object.
275 * @see DB_common::setOption()
278 function &factory($type, $options = false)
280 if (!is_array($options)) {
281 $options = array('persistent' => $options);
284 if (isset($options['debug']) && $options['debug'] >= 2) {
285 // expose php errors with sufficient debug level
286 include_once "DB/{$type}.php";
288 @include_once "DB/{$type}.php";
291 $classname = "DB_${type}";
293 if (!class_exists($classname)) {
294 $tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null,
295 "Unable to include the DB/{$type}.php file",
300 @$obj = new $classname;
302 foreach ($options as $option => $value) {
303 $test = $obj->setOption($option, $value);
304 if (DB::isError($test)) {
316 * Create a new DB object and connect to the specified database.
320 * require_once 'DB.php';
322 * $dsn = 'mysql://user:password@host/database'
325 * 'portability' => DB_PORTABILITY_ALL,
328 * $dbh =& DB::connect($dsn, $options);
329 * if (DB::isError($dbh)) {
330 * die($dbh->getMessage());
334 * @param mixed $dsn string "data source name" or an array in the
335 * format returned by DB::parseDSN()
337 * @param array $options an associative array of option names and
340 * @return object a newly created DB connection object, or a DB
341 * error object on error
343 * @see DB::parseDSN(), DB_common::setOption(), DB::isError()
346 function &connect($dsn, $options = array())
348 $dsninfo = DB::parseDSN($dsn);
349 $type = $dsninfo['phptype'];
351 if (!is_array($options)) {
353 * For backwards compatibility. $options used to be boolean,
354 * indicating whether the connection should be persistent.
356 $options = array('persistent' => $options);
359 if (isset($options['debug']) && $options['debug'] >= 2) {
360 // expose php errors with sufficient debug level
361 include_once "DB/${type}.php";
363 @include_once "DB/${type}.php";
366 $classname = "DB_${type}";
367 if (!class_exists($classname)) {
368 $tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null,
369 "Unable to include the DB/{$type}.php file for `$dsn'",
374 @$obj = new $classname;
376 foreach ($options as $option => $value) {
377 $test = $obj->setOption($option, $value);
378 if (DB::isError($test)) {
383 $err = $obj->connect($dsninfo, $obj->getOption('persistent'));
384 if (DB::isError($err)) {
385 $err->addUserInfo($dsn);
396 * Return the DB API version
398 * @return int the DB API version number
402 function apiVersion()
411 * Tell whether a result code from a DB method is an error
413 * @param int $value result code
415 * @return bool whether $value is an error
419 function isError($value)
421 return is_a($value, 'DB_Error');
425 // {{{ isConnection()
428 * Tell whether a value is a DB connection
430 * @param mixed $value value to test
432 * @return bool whether $value is a DB connection
436 function isConnection($value)
438 return (is_object($value) &&
439 is_subclass_of($value, 'db_common') &&
440 method_exists($value, 'simpleQuery'));
447 * Tell whether a query is a data manipulation query (insert,
448 * update or delete) or a data definition query (create, drop,
449 * alter, grant, revoke).
453 * @param string $query the query
455 * @return boolean whether $query is a data manipulation query
457 function isManip($query)
459 $manips = 'INSERT|UPDATE|DELETE|LOAD DATA|'.'REPLACE|CREATE|DROP|'.
460 'ALTER|GRANT|REVOKE|'.'LOCK|UNLOCK';
461 if (preg_match('/^\s*"?('.$manips.')\s+/i', $query)) {
468 // {{{ errorMessage()
471 * Return a textual error message for a DB error code
473 * @param integer $value error code
475 * @return string error message, or false if the error code was
478 function errorMessage($value)
480 static $errorMessages;
481 if (!isset($errorMessages)) {
482 $errorMessages = array(
483 DB_ERROR => 'unknown error',
484 DB_ERROR_ALREADY_EXISTS => 'already exists',
485 DB_ERROR_CANNOT_CREATE => 'can not create',
486 DB_ERROR_CANNOT_DELETE => 'can not delete',
487 DB_ERROR_CANNOT_DROP => 'can not drop',
488 DB_ERROR_CONSTRAINT => 'constraint violation',
489 DB_ERROR_CONSTRAINT_NOT_NULL=> 'null value violates not-null constraint',
490 DB_ERROR_DIVZERO => 'division by zero',
491 DB_ERROR_INVALID => 'invalid',
492 DB_ERROR_INVALID_DATE => 'invalid date or time',
493 DB_ERROR_INVALID_NUMBER => 'invalid number',
494 DB_ERROR_MISMATCH => 'mismatch',
495 DB_ERROR_NODBSELECTED => 'no database selected',
496 DB_ERROR_NOSUCHFIELD => 'no such field',
497 DB_ERROR_NOSUCHTABLE => 'no such table',
498 DB_ERROR_NOT_CAPABLE => 'DB backend not capable',
499 DB_ERROR_NOT_FOUND => 'not found',
500 DB_ERROR_NOT_LOCKED => 'not locked',
501 DB_ERROR_SYNTAX => 'syntax error',
502 DB_ERROR_UNSUPPORTED => 'not supported',
503 DB_ERROR_VALUE_COUNT_ON_ROW => 'value count on row',
504 DB_ERROR_INVALID_DSN => 'invalid DSN',
505 DB_ERROR_CONNECT_FAILED => 'connect failed',
507 DB_ERROR_NEED_MORE_DATA => 'insufficient data supplied',
508 DB_ERROR_EXTENSION_NOT_FOUND=> 'extension not found',
509 DB_ERROR_NOSUCHDB => 'no such database',
510 DB_ERROR_ACCESS_VIOLATION => 'insufficient permissions',
511 DB_ERROR_TRUNCATED => 'truncated'
515 if (DB::isError($value)) {
516 $value = $value->getCode();
519 return isset($errorMessages[$value]) ? $errorMessages[$value] : $errorMessages[DB_ERROR];
526 * Parse a data source name.
528 * Additional keys can be added by appending a URI query string to the
531 * The format of the supplied DSN is in its fullest form:
533 * phptype(dbsyntax)://username:password@protocol+hostspec/database?option=8&another=true
536 * Most variations are allowed:
538 * phptype://username:password@protocol+hostspec:110//usr/db_file.db?mode=0644
539 * phptype://username:password@hostspec/database_name
540 * phptype://username:password@hostspec
541 * phptype://username@hostspec
542 * phptype://hostspec/database
548 * @param string $dsn Data Source Name to be parsed
550 * @return array an associative array with the following keys:
551 * + phptype: Database backend used in PHP (mysql, odbc etc.)
552 * + dbsyntax: Database used with regards to SQL syntax etc.
553 * + protocol: Communication protocol to use (tcp, unix etc.)
554 * + hostspec: Host specification (hostname[:port])
555 * + database: Database to use on the DBMS server
556 * + username: User name for login
557 * + password: Password for login
559 * @author Tomas V.V.Cox <cox@idecnet.com>
561 function parseDSN($dsn)
575 if (is_array($dsn)) {
576 $dsn = array_merge($parsed, $dsn);
577 if (!$dsn['dbsyntax']) {
578 $dsn['dbsyntax'] = $dsn['phptype'];
583 // Find phptype and dbsyntax
584 if (($pos = strpos($dsn, '://')) !== false) {
585 $str = substr($dsn, 0, $pos);
586 $dsn = substr($dsn, $pos + 3);
592 // Get phptype and dbsyntax
593 // $str => phptype(dbsyntax)
594 if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) {
595 $parsed['phptype'] = $arr[1];
596 $parsed['dbsyntax'] = !$arr[2] ? $arr[1] : $arr[2];
598 $parsed['phptype'] = $str;
599 $parsed['dbsyntax'] = $str;
606 // Get (if found): username and password
607 // $dsn => username:password@protocol+hostspec/database
608 if (($at = strrpos($dsn,'@')) !== false) {
609 $str = substr($dsn, 0, $at);
610 $dsn = substr($dsn, $at + 1);
611 if (($pos = strpos($str, ':')) !== false) {
612 $parsed['username'] = rawurldecode(substr($str, 0, $pos));
613 $parsed['password'] = rawurldecode(substr($str, $pos + 1));
615 $parsed['username'] = rawurldecode($str);
619 // Find protocol and hostspec
621 // $dsn => proto(proto_opts)/database
622 if (preg_match('|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match)) {
624 $proto_opts = $match[2] ? $match[2] : false;
627 // $dsn => protocol+hostspec/database (old format)
629 if (strpos($dsn, '+') !== false) {
630 list($proto, $dsn) = explode('+', $dsn, 2);
632 if (strpos($dsn, '/') !== false) {
633 list($proto_opts, $dsn) = explode('/', $dsn, 2);
640 // process the different protocol options
641 $parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp';
642 $proto_opts = rawurldecode($proto_opts);
643 if ($parsed['protocol'] == 'tcp') {
644 if (strpos($proto_opts, ':') !== false) {
645 list($parsed['hostspec'], $parsed['port']) = explode(':', $proto_opts);
647 $parsed['hostspec'] = $proto_opts;
649 } elseif ($parsed['protocol'] == 'unix') {
650 $parsed['socket'] = $proto_opts;
657 if (($pos = strpos($dsn, '?')) === false) {
658 $parsed['database'] = $dsn;
659 // /database?param1=value1¶m2=value2
661 $parsed['database'] = substr($dsn, 0, $pos);
662 $dsn = substr($dsn, $pos + 1);
663 if (strpos($dsn, '&') !== false) {
664 $opts = explode('&', $dsn);
665 } else { // database?param1=value1
668 foreach ($opts as $opt) {
669 list($key, $value) = explode('=', $opt);
670 if (!isset($parsed[$key])) {
671 // don't allow params overwrite
672 $parsed[$key] = rawurldecode($value);
682 // {{{ assertExtension()
685 * Load a PHP database extension if it is not loaded already.
689 * @param string $name the base name of the extension (without the .so or
692 * @return boolean true if the extension was already or successfully
693 * loaded, false if it could not be loaded
695 function assertExtension($name)
697 if (!extension_loaded($name)) {
698 $dlext = OS_WINDOWS ? '.dll' : '.so';
699 $dlprefix = OS_WINDOWS ? 'php_' : '';
700 @dl($dlprefix . $name . $dlext);
701 return extension_loaded($name);
709 // {{{ class DB_Error
712 * DB_Error implements a class for reporting portable database error
716 * @author Stig Bakken <ssb@php.net>
718 class DB_Error extends PEAR_Error
723 * DB_Error constructor.
725 * @param mixed $code DB error code, or string with error message.
726 * @param integer $mode what "error mode" to operate in
727 * @param integer $level what error level to use for $mode & PEAR_ERROR_TRIGGER
728 * @param mixed $debuginfo additional debug info, such as the last query
734 function DB_Error($code = DB_ERROR, $mode = PEAR_ERROR_RETURN,
735 $level = E_USER_NOTICE, $debuginfo = null)
738 $this->PEAR_Error('DB Error: ' . DB::errorMessage($code), $code, $mode, $level, $debuginfo);
740 $this->PEAR_Error("DB Error: $code", DB_ERROR, $mode, $level, $debuginfo);
747 // {{{ class DB_result
750 * This class implements a wrapper for a DB result set.
751 * A new instance of this class will be returned by the DB implementation
752 * after processing a query that returns data.
755 * @author Stig Bakken <ssb@php.net>
763 var $row_counter = null;
766 * for limit queries, the row to start fetching
769 var $limit_from = null;
772 * for limit queries, the number of rows to fetch
775 var $limit_count = null;
781 * DB_result constructor.
782 * @param resource &$dbh DB object reference
783 * @param resource $result result resource id
784 * @param array $options assoc array with optional result options
786 function DB_result(&$dbh, $result, $options = array())
789 $this->result = $result;
790 foreach ($options as $key => $value) {
791 $this->setOption($key, $value);
793 $this->limit_type = $dbh->features['limit'];
794 $this->autofree = $dbh->options['autofree'];
795 $this->fetchmode = $dbh->fetchmode;
796 $this->fetchmode_object_class = $dbh->fetchmode_object_class;
799 function setOption($key, $value = null)
803 $this->limit_from = $value; break;
805 $this->limit_count = $value; break;
813 * Fetch a row of data and return it by reference into an array.
815 * The type of array returned can be controlled either by setting this
816 * method's <var>$fetchmode</var> parameter or by changing the default
817 * fetch mode setFetchMode() before calling this method.
819 * There are two options for standardizing the information returned
820 * from databases, ensuring their values are consistent when changing
821 * DBMS's. These portability options can be turned on when creating a
822 * new DB object or by using setOption().
824 * + <samp>DB_PORTABILITY_LOWERCASE</samp>
825 * convert names of fields to lower case
827 * + <samp>DB_PORTABILITY_RTRIM</samp>
828 * right trim the data
830 * @param int $fetchmode how the resulting array should be indexed
831 * @param int $rownum the row number to fetch
833 * @return array a row of data, null on no more rows or PEAR_Error
836 * @see DB_common::setOption(), DB_common::setFetchMode()
839 function &fetchRow($fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null)
841 if ($fetchmode === DB_FETCHMODE_DEFAULT) {
842 $fetchmode = $this->fetchmode;
844 if ($fetchmode === DB_FETCHMODE_OBJECT) {
845 $fetchmode = DB_FETCHMODE_ASSOC;
846 $object_class = $this->fetchmode_object_class;
848 if ($this->limit_from !== null) {
849 if ($this->row_counter === null) {
850 $this->row_counter = $this->limit_from;
852 if ($this->limit_type == false) {
854 while ($i++ < $this->limit_from) {
855 $this->dbh->fetchInto($this->result, $arr, $fetchmode);
859 if ($this->row_counter >= (
860 $this->limit_from + $this->limit_count))
862 if ($this->autofree) {
868 if ($this->limit_type == 'emulate') {
869 $rownum = $this->row_counter;
871 $this->row_counter++;
873 $res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum);
874 if ($res === DB_OK) {
875 if (isset($object_class)) {
876 // default mode specified in DB_common::fetchmode_object_class property
877 if ($object_class == 'stdClass') {
878 $arr = (object) $arr;
880 $arr = new $object_class($arr);
885 if ($res == null && $this->autofree) {
895 * Fetch a row of data into an array which is passed by reference.
897 * The type of array returned can be controlled either by setting this
898 * method's <var>$fetchmode</var> parameter or by changing the default
899 * fetch mode setFetchMode() before calling this method.
901 * There are two options for standardizing the information returned
902 * from databases, ensuring their values are consistent when changing
903 * DBMS's. These portability options can be turned on when creating a
904 * new DB object or by using setOption().
906 * + <samp>DB_PORTABILITY_LOWERCASE</samp>
907 * convert names of fields to lower case
909 * + <samp>DB_PORTABILITY_RTRIM</samp>
910 * right trim the data
912 * @param array &$arr (reference) array where data from the row
914 * @param int $fetchmode how the resulting array should be indexed
915 * @param int $rownum the row number to fetch
917 * @return mixed DB_OK on success, null on no more rows or
918 * a DB_Error object on error
920 * @see DB_common::setOption(), DB_common::setFetchMode()
923 function fetchInto(&$arr, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null)
925 if ($fetchmode === DB_FETCHMODE_DEFAULT) {
926 $fetchmode = $this->fetchmode;
928 if ($fetchmode === DB_FETCHMODE_OBJECT) {
929 $fetchmode = DB_FETCHMODE_ASSOC;
930 $object_class = $this->fetchmode_object_class;
932 if ($this->limit_from !== null) {
933 if ($this->row_counter === null) {
934 $this->row_counter = $this->limit_from;
936 if ($this->limit_type == false) {
938 while ($i++ < $this->limit_from) {
939 $this->dbh->fetchInto($this->result, $arr, $fetchmode);
943 if ($this->row_counter >= (
944 $this->limit_from + $this->limit_count))
946 if ($this->autofree) {
951 if ($this->limit_type == 'emulate') {
952 $rownum = $this->row_counter;
955 $this->row_counter++;
957 $res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum);
958 if ($res === DB_OK) {
959 if (isset($object_class)) {
960 // default mode specified in DB_common::fetchmode_object_class property
961 if ($object_class == 'stdClass') {
962 $arr = (object) $arr;
964 $arr = new $object_class($arr);
969 if ($res == null && $this->autofree) {
979 * Get the the number of columns in a result set.
981 * @return int the number of columns, or a DB error
987 return $this->dbh->numCols($this->result);
994 * Get the number of rows in a result set.
996 * @return int the number of rows, or a DB error
1002 return $this->dbh->numRows($this->result);
1009 * Get the next result if a batch of queries was executed.
1011 * @return bool true if a new result is available or false if not.
1015 function nextResult()
1017 return $this->dbh->nextResult($this->result);
1024 * Frees the resources allocated for this result set.
1025 * @return int error code
1031 $err = $this->dbh->freeResult($this->result);
1032 if (DB::isError($err)) {
1035 $this->result = false;
1045 * @see DB_common::tableInfo()
1047 function tableInfo($mode = null)
1049 if (is_string($mode)) {
1050 return $this->dbh->raiseError(DB_ERROR_NEED_MORE_DATA);
1052 return $this->dbh->tableInfo($this, $mode);
1056 // {{{ getRowCounter()
1059 * returns the actual row number
1062 function getRowCounter()
1064 return $this->row_counter;
1073 * Pear DB Row Object
1074 * @see DB_common::setFetchMode()
1083 * @param resource row data as array
1085 function DB_row(&$arr)
1087 foreach ($arr as $key => $value) {
1088 $this->$key = &$arr[$key];