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 // Database independent query interface.
23 require_once 'PEAR.php';
29 * The method mapErrorCode in each DB_dbtype implementation maps
30 * native error codes to one of these.
32 * If you add an error code here, make sure you also add a textual
33 * version of it in DB::errorMessage().
36 define('DB_ERROR', -1);
37 define('DB_ERROR_SYNTAX', -2);
38 define('DB_ERROR_CONSTRAINT', -3);
39 define('DB_ERROR_NOT_FOUND', -4);
40 define('DB_ERROR_ALREADY_EXISTS', -5);
41 define('DB_ERROR_UNSUPPORTED', -6);
42 define('DB_ERROR_MISMATCH', -7);
43 define('DB_ERROR_INVALID', -8);
44 define('DB_ERROR_NOT_CAPABLE', -9);
45 define('DB_ERROR_TRUNCATED', -10);
46 define('DB_ERROR_INVALID_NUMBER', -11);
47 define('DB_ERROR_INVALID_DATE', -12);
48 define('DB_ERROR_DIVZERO', -13);
49 define('DB_ERROR_NODBSELECTED', -14);
50 define('DB_ERROR_CANNOT_CREATE', -15);
51 define('DB_ERROR_CANNOT_DELETE', -16);
52 define('DB_ERROR_CANNOT_DROP', -17);
53 define('DB_ERROR_NOSUCHTABLE', -18);
54 define('DB_ERROR_NOSUCHFIELD', -19);
55 define('DB_ERROR_NEED_MORE_DATA', -20);
56 define('DB_ERROR_NOT_LOCKED', -21);
57 define('DB_ERROR_VALUE_COUNT_ON_ROW', -22);
58 define('DB_ERROR_INVALID_DSN', -23);
59 define('DB_ERROR_CONNECT_FAILED', -24);
60 define('DB_ERROR_EXTENSION_NOT_FOUND',-25);
61 define('DB_ERROR_ACCESS_VIOLATION', -26);
62 define('DB_ERROR_NOSUCHDB', -27);
63 define('DB_ERROR_CONSTRAINT_NOT_NULL',-29);
66 // {{{ prepared statement-related
69 * These constants are used when storing information about prepared
70 * statements (using the "prepare" method in DB_dbtype).
72 * The prepare/execute model in DB is mostly borrowed from the ODBC
73 * extension, in a query the "?" character means a scalar parameter.
74 * There are two extensions though, a "&" character means an opaque
75 * parameter. An opaque parameter is simply a file name, the real
76 * data are in that file (useful for putting uploaded files into your
77 * database and such). The "!" char means a parameter that must be
79 * They modify the quote behavoir:
80 * DB_PARAM_SCALAR (?) => 'original string quoted'
81 * DB_PARAM_OPAQUE (&) => 'string from file quoted'
82 * DB_PARAM_MISC (!) => original string
84 define('DB_PARAM_SCALAR', 1);
85 define('DB_PARAM_OPAQUE', 2);
86 define('DB_PARAM_MISC', 3);
89 // {{{ binary data-related
92 * These constants define different ways of returning binary data
93 * from queries. Again, this model has been borrowed from the ODBC
96 * DB_BINMODE_PASSTHRU sends the data directly through to the browser
97 * when data is fetched from the database.
98 * DB_BINMODE_RETURN lets you return data as usual.
99 * DB_BINMODE_CONVERT returns data as well, only it is converted to
100 * hex format, for example the string "123" would become "313233".
102 define('DB_BINMODE_PASSTHRU', 1);
103 define('DB_BINMODE_RETURN', 2);
104 define('DB_BINMODE_CONVERT', 3);
110 * This is a special constant that tells DB the user hasn't specified
111 * any particular get mode, so the default should be used.
113 define('DB_FETCHMODE_DEFAULT', 0);
116 * Column data indexed by numbers, ordered from 0 and up
118 define('DB_FETCHMODE_ORDERED', 1);
121 * Column data indexed by column names
123 define('DB_FETCHMODE_ASSOC', 2);
126 * Column data as object properties
128 define('DB_FETCHMODE_OBJECT', 3);
131 * For multi-dimensional results: normally the first level of arrays
132 * is the row number, and the second level indexed by column number or name.
133 * DB_FETCHMODE_FLIPPED switches this order, so the first level of arrays
134 * is the column name, and the second level the row number.
136 define('DB_FETCHMODE_FLIPPED', 4);
138 /* for compatibility */
139 define('DB_GETMODE_ORDERED', DB_FETCHMODE_ORDERED);
140 define('DB_GETMODE_ASSOC', DB_FETCHMODE_ASSOC);
141 define('DB_GETMODE_FLIPPED', DB_FETCHMODE_FLIPPED);
145 // {{{ tableInfo() && autoPrepare()-related
149 * these are constants for the tableInfo-function
150 * they are bitwised or'ed. so if there are more constants to be defined
151 * in the future, adjust DB_TABLEINFO_FULL accordingly
153 define('DB_TABLEINFO_ORDER', 1);
154 define('DB_TABLEINFO_ORDERTABLE', 2);
155 define('DB_TABLEINFO_FULL', 3);
158 * Used by autoPrepare()
160 define('DB_AUTOQUERY_INSERT', 1);
161 define('DB_AUTOQUERY_UPDATE', 2);
164 // {{{ portability modes
167 * Portability: turn off all portability features.
168 * @see DB_common::setOption()
170 define('DB_PORTABILITY_NONE', 0);
173 * Portability: convert names of tables and fields to lower case
174 * when using the get*(), fetch*() and tableInfo() methods.
175 * @see DB_common::setOption()
177 define('DB_PORTABILITY_LOWERCASE', 1);
180 * Portability: right trim the data output by get*() and fetch*().
181 * @see DB_common::setOption()
183 define('DB_PORTABILITY_RTRIM', 2);
186 * Portability: force reporting the number of rows deleted.
187 * @see DB_common::setOption()
189 define('DB_PORTABILITY_DELETE_COUNT', 4);
192 * Portability: enable hack that makes numRows() work in Oracle.
193 * @see DB_common::setOption()
195 define('DB_PORTABILITY_NUMROWS', 8);
198 * Portability: makes certain error messages in certain drivers compatible
199 * with those from other DBMS's.
201 * + mysql, mysqli: change unique/primary key constraints
202 * DB_ERROR_ALREADY_EXISTS -> DB_ERROR_CONSTRAINT
204 * + odbc(access): MS's ODBC driver reports 'no such field' as code
205 * 07001, which means 'too few parameters.' When this option is on
206 * that code gets mapped to DB_ERROR_NOSUCHFIELD.
208 * @see DB_common::setOption()
210 define('DB_PORTABILITY_ERRORS', 16);
213 * Portability: convert null values to empty strings in data output by
214 * get*() and fetch*().
215 * @see DB_common::setOption()
217 define('DB_PORTABILITY_NULL_TO_EMPTY', 32);
220 * Portability: turn on all portability features.
221 * @see DB_common::setOption()
223 define('DB_PORTABILITY_ALL', 63);
231 * The main "DB" class is simply a container class with some static
232 * methods for creating DB objects as well as some utility functions
233 * common to all parts of DB.
235 * The object model of DB is as follows (indentation means inheritance):
237 * DB The main DB class. This is simply a utility class
238 * with some "static" methods for creating DB objects as
239 * well as common utility functions for other DB classes.
241 * DB_common The base for each DB implementation. Provides default
242 * | implementations (in OO lingo virtual methods) for
243 * | the actual DB implementations as well as a bunch of
244 * | query utility functions.
246 * +-DB_mysql The DB implementation for MySQL. Inherits DB_common.
247 * When calling DB::factory or DB::connect for MySQL
248 * connections, the object returned is an instance of this
252 * @author Stig Bakken <ssb@php.net>
253 * @author Tomas V.V.Cox <cox@idecnet.com>
263 * Create a new DB object for the specified database type.
265 * Allows creation of a DB_<driver> object from which the object's
266 * methods can be utilized without actually connecting to a database.
268 * @param string $type database type, for example "mysql"
269 * @param array $options associative array of option names and values
271 * @return object a new DB object. On error, an error object.
273 * @see DB_common::setOption()
276 function &factory($type, $options = false)
278 if (!is_array($options)) {
279 $options = array('persistent' => $options);
282 if (isset($options['debug']) && $options['debug'] >= 2) {
283 // expose php errors with sufficient debug level
284 include_once "DB/{$type}.php";
286 @include_once "DB/{$type}.php";
289 $classname = "DB_${type}";
291 if (!class_exists($classname)) {
292 $tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null,
293 "Unable to include the DB/{$type}.php file",
298 @$obj = new $classname;
300 foreach ($options as $option => $value) {
301 $test = $obj->setOption($option, $value);
302 if (DB::isError($test)) {
314 * Create a new DB object and connect to the specified database.
318 * require_once 'DB.php';
320 * $dsn = 'mysql://user:password@host/database'
323 * 'portability' => DB_PORTABILITY_ALL,
326 * $dbh =& DB::connect($dsn, $options);
327 * if (DB::isError($dbh)) {
328 * die($dbh->getMessage());
332 * @param mixed $dsn string "data source name" or an array in the
333 * format returned by DB::parseDSN()
335 * @param array $options an associative array of option names and
338 * @return object a newly created DB connection object, or a DB
339 * error object on error
341 * @see DB::parseDSN(), DB_common::setOption(), DB::isError()
344 function &connect($dsn, $options = array())
346 $dsninfo = DB::parseDSN($dsn);
347 $type = $dsninfo['phptype'];
349 if (!is_array($options)) {
351 * For backwards compatibility. $options used to be boolean,
352 * indicating whether the connection should be persistent.
354 $options = array('persistent' => $options);
357 if (isset($options['debug']) && $options['debug'] >= 2) {
358 // expose php errors with sufficient debug level
359 include_once "DB/${type}.php";
361 @include_once "DB/${type}.php";
364 $classname = "DB_${type}";
365 if (!class_exists($classname)) {
366 $tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null,
367 "Unable to include the DB/{$type}.php file for `$dsn'",
372 @$obj = new $classname;
374 foreach ($options as $option => $value) {
375 $test = $obj->setOption($option, $value);
376 if (DB::isError($test)) {
381 $err = $obj->connect($dsninfo, $obj->getOption('persistent'));
382 if (DB::isError($err)) {
383 $err->addUserInfo($dsn);
394 * Return the DB API version
396 * @return int the DB API version number
400 function apiVersion()
409 * Tell whether a result code from a DB method is an error
411 * @param int $value result code
413 * @return bool whether $value is an error
417 function isError($value)
419 return is_a($value, 'DB_Error');
423 // {{{ isConnection()
426 * Tell whether a value is a DB connection
428 * @param mixed $value value to test
430 * @return bool whether $value is a DB connection
434 function isConnection($value)
436 return (is_object($value) &&
437 is_subclass_of($value, 'db_common') &&
438 method_exists($value, 'simpleQuery'));
445 * Tell whether a query is a data manipulation query (insert,
446 * update or delete) or a data definition query (create, drop,
447 * alter, grant, revoke).
451 * @param string $query the query
453 * @return boolean whether $query is a data manipulation query
455 function isManip($query)
457 $manips = 'INSERT|UPDATE|DELETE|LOAD DATA|'.'REPLACE|CREATE|DROP|'.
458 'ALTER|GRANT|REVOKE|'.'LOCK|UNLOCK';
459 if (preg_match('/^\s*"?('.$manips.')\s+/i', $query)) {
466 // {{{ errorMessage()
469 * Return a textual error message for a DB error code
471 * @param integer $value error code
473 * @return string error message, or false if the error code was
476 function errorMessage($value)
478 static $errorMessages;
479 if (!isset($errorMessages)) {
480 $errorMessages = array(
481 DB_ERROR => 'unknown error',
482 DB_ERROR_ALREADY_EXISTS => 'already exists',
483 DB_ERROR_CANNOT_CREATE => 'can not create',
484 DB_ERROR_CANNOT_DELETE => 'can not delete',
485 DB_ERROR_CANNOT_DROP => 'can not drop',
486 DB_ERROR_CONSTRAINT => 'constraint violation',
487 DB_ERROR_CONSTRAINT_NOT_NULL=> 'null value violates not-null constraint',
488 DB_ERROR_DIVZERO => 'division by zero',
489 DB_ERROR_INVALID => 'invalid',
490 DB_ERROR_INVALID_DATE => 'invalid date or time',
491 DB_ERROR_INVALID_NUMBER => 'invalid number',
492 DB_ERROR_MISMATCH => 'mismatch',
493 DB_ERROR_NODBSELECTED => 'no database selected',
494 DB_ERROR_NOSUCHFIELD => 'no such field',
495 DB_ERROR_NOSUCHTABLE => 'no such table',
496 DB_ERROR_NOT_CAPABLE => 'DB backend not capable',
497 DB_ERROR_NOT_FOUND => 'not found',
498 DB_ERROR_NOT_LOCKED => 'not locked',
499 DB_ERROR_SYNTAX => 'syntax error',
500 DB_ERROR_UNSUPPORTED => 'not supported',
501 DB_ERROR_VALUE_COUNT_ON_ROW => 'value count on row',
502 DB_ERROR_INVALID_DSN => 'invalid DSN',
503 DB_ERROR_CONNECT_FAILED => 'connect failed',
505 DB_ERROR_NEED_MORE_DATA => 'insufficient data supplied',
506 DB_ERROR_EXTENSION_NOT_FOUND=> 'extension not found',
507 DB_ERROR_NOSUCHDB => 'no such database',
508 DB_ERROR_ACCESS_VIOLATION => 'insufficient permissions',
509 DB_ERROR_TRUNCATED => 'truncated'
513 if (DB::isError($value)) {
514 $value = $value->getCode();
517 return isset($errorMessages[$value]) ? $errorMessages[$value] : $errorMessages[DB_ERROR];
524 * Parse a data source name.
526 * Additional keys can be added by appending a URI query string to the
529 * The format of the supplied DSN is in its fullest form:
531 * phptype(dbsyntax)://username:password@protocol+hostspec/database?option=8&another=true
534 * Most variations are allowed:
536 * phptype://username:password@protocol+hostspec:110//usr/db_file.db?mode=0644
537 * phptype://username:password@hostspec/database_name
538 * phptype://username:password@hostspec
539 * phptype://username@hostspec
540 * phptype://hostspec/database
546 * @param string $dsn Data Source Name to be parsed
548 * @return array an associative array with the following keys:
549 * + phptype: Database backend used in PHP (mysql, odbc etc.)
550 * + dbsyntax: Database used with regards to SQL syntax etc.
551 * + protocol: Communication protocol to use (tcp, unix etc.)
552 * + hostspec: Host specification (hostname[:port])
553 * + database: Database to use on the DBMS server
554 * + username: User name for login
555 * + password: Password for login
557 * @author Tomas V.V.Cox <cox@idecnet.com>
559 function parseDSN($dsn)
573 if (is_array($dsn)) {
574 $dsn = array_merge($parsed, $dsn);
575 if (!$dsn['dbsyntax']) {
576 $dsn['dbsyntax'] = $dsn['phptype'];
581 // Find phptype and dbsyntax
582 if (($pos = strpos($dsn, '://')) !== false) {
583 $str = substr($dsn, 0, $pos);
584 $dsn = substr($dsn, $pos + 3);
590 // Get phptype and dbsyntax
591 // $str => phptype(dbsyntax)
592 if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) {
593 $parsed['phptype'] = $arr[1];
594 $parsed['dbsyntax'] = !$arr[2] ? $arr[1] : $arr[2];
596 $parsed['phptype'] = $str;
597 $parsed['dbsyntax'] = $str;
604 // Get (if found): username and password
605 // $dsn => username:password@protocol+hostspec/database
606 if (($at = strrpos($dsn,'@')) !== false) {
607 $str = substr($dsn, 0, $at);
608 $dsn = substr($dsn, $at + 1);
609 if (($pos = strpos($str, ':')) !== false) {
610 $parsed['username'] = rawurldecode(substr($str, 0, $pos));
611 $parsed['password'] = rawurldecode(substr($str, $pos + 1));
613 $parsed['username'] = rawurldecode($str);
617 // Find protocol and hostspec
619 // $dsn => proto(proto_opts)/database
620 if (preg_match('|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match)) {
622 $proto_opts = $match[2] ? $match[2] : false;
625 // $dsn => protocol+hostspec/database (old format)
627 if (strpos($dsn, '+') !== false) {
628 list($proto, $dsn) = explode('+', $dsn, 2);
630 if (strpos($dsn, '/') !== false) {
631 list($proto_opts, $dsn) = explode('/', $dsn, 2);
638 // process the different protocol options
639 $parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp';
640 $proto_opts = rawurldecode($proto_opts);
641 if ($parsed['protocol'] == 'tcp') {
642 if (strpos($proto_opts, ':') !== false) {
643 list($parsed['hostspec'], $parsed['port']) = explode(':', $proto_opts);
645 $parsed['hostspec'] = $proto_opts;
647 } elseif ($parsed['protocol'] == 'unix') {
648 $parsed['socket'] = $proto_opts;
655 if (($pos = strpos($dsn, '?')) === false) {
656 $parsed['database'] = $dsn;
657 // /database?param1=value1¶m2=value2
659 $parsed['database'] = substr($dsn, 0, $pos);
660 $dsn = substr($dsn, $pos + 1);
661 if (strpos($dsn, '&') !== false) {
662 $opts = explode('&', $dsn);
663 } else { // database?param1=value1
666 foreach ($opts as $opt) {
667 list($key, $value) = explode('=', $opt);
668 if (!isset($parsed[$key])) {
669 // don't allow params overwrite
670 $parsed[$key] = rawurldecode($value);
680 // {{{ assertExtension()
683 * Load a PHP database extension if it is not loaded already.
687 * @param string $name the base name of the extension (without the .so or
690 * @return boolean true if the extension was already or successfully
691 * loaded, false if it could not be loaded
693 function assertExtension($name)
695 if (!extension_loaded($name)) {
696 $dlext = OS_WINDOWS ? '.dll' : '.so';
697 $dlprefix = OS_WINDOWS ? 'php_' : '';
698 @dl($dlprefix . $name . $dlext);
699 return extension_loaded($name);
707 // {{{ class DB_Error
710 * DB_Error implements a class for reporting portable database error
714 * @author Stig Bakken <ssb@php.net>
716 class DB_Error extends PEAR_Error
721 * DB_Error constructor.
723 * @param mixed $code DB error code, or string with error message.
724 * @param integer $mode what "error mode" to operate in
725 * @param integer $level what error level to use for $mode & PEAR_ERROR_TRIGGER
726 * @param mixed $debuginfo additional debug info, such as the last query
732 function DB_Error($code = DB_ERROR, $mode = PEAR_ERROR_RETURN,
733 $level = E_USER_NOTICE, $debuginfo = null)
736 $this->PEAR_Error('DB Error: ' . DB::errorMessage($code), $code, $mode, $level, $debuginfo);
738 $this->PEAR_Error("DB Error: $code", DB_ERROR, $mode, $level, $debuginfo);
745 // {{{ class DB_result
748 * This class implements a wrapper for a DB result set.
749 * A new instance of this class will be returned by the DB implementation
750 * after processing a query that returns data.
753 * @author Stig Bakken <ssb@php.net>
761 var $row_counter = null;
764 * for limit queries, the row to start fetching
767 var $limit_from = null;
770 * for limit queries, the number of rows to fetch
773 var $limit_count = null;
779 * DB_result constructor.
780 * @param resource &$dbh DB object reference
781 * @param resource $result result resource id
782 * @param array $options assoc array with optional result options
784 function DB_result(&$dbh, $result, $options = array())
787 $this->result = $result;
788 foreach ($options as $key => $value) {
789 $this->setOption($key, $value);
791 $this->limit_type = $dbh->features['limit'];
792 $this->autofree = $dbh->options['autofree'];
793 $this->fetchmode = $dbh->fetchmode;
794 $this->fetchmode_object_class = $dbh->fetchmode_object_class;
797 function setOption($key, $value = null)
801 $this->limit_from = $value; break;
803 $this->limit_count = $value; break;
811 * Fetch a row of data and return it by reference into an array.
813 * The type of array returned can be controlled either by setting this
814 * method's <var>$fetchmode</var> parameter or by changing the default
815 * fetch mode setFetchMode() before calling this method.
817 * There are two options for standardizing the information returned
818 * from databases, ensuring their values are consistent when changing
819 * DBMS's. These portability options can be turned on when creating a
820 * new DB object or by using setOption().
822 * + <samp>DB_PORTABILITY_LOWERCASE</samp>
823 * convert names of fields to lower case
825 * + <samp>DB_PORTABILITY_RTRIM</samp>
826 * right trim the data
828 * @param int $fetchmode how the resulting array should be indexed
829 * @param int $rownum the row number to fetch
831 * @return array a row of data, null on no more rows or PEAR_Error
834 * @see DB_common::setOption(), DB_common::setFetchMode()
837 function &fetchRow($fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null)
839 if ($fetchmode === DB_FETCHMODE_DEFAULT) {
840 $fetchmode = $this->fetchmode;
842 if ($fetchmode === DB_FETCHMODE_OBJECT) {
843 $fetchmode = DB_FETCHMODE_ASSOC;
844 $object_class = $this->fetchmode_object_class;
846 if ($this->limit_from !== null) {
847 if ($this->row_counter === null) {
848 $this->row_counter = $this->limit_from;
850 if ($this->limit_type == false) {
852 while ($i++ < $this->limit_from) {
853 $this->dbh->fetchInto($this->result, $arr, $fetchmode);
857 if ($this->row_counter >= (
858 $this->limit_from + $this->limit_count))
860 if ($this->autofree) {
866 if ($this->limit_type == 'emulate') {
867 $rownum = $this->row_counter;
869 $this->row_counter++;
871 $res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum);
872 if ($res === DB_OK) {
873 if (isset($object_class)) {
874 // default mode specified in DB_common::fetchmode_object_class property
875 if ($object_class == 'stdClass') {
876 $arr = (object) $arr;
878 $arr = new $object_class($arr);
883 if ($res == null && $this->autofree) {
893 * Fetch a row of data into an array which is passed by reference.
895 * The type of array returned can be controlled either by setting this
896 * method's <var>$fetchmode</var> parameter or by changing the default
897 * fetch mode setFetchMode() before calling this method.
899 * There are two options for standardizing the information returned
900 * from databases, ensuring their values are consistent when changing
901 * DBMS's. These portability options can be turned on when creating a
902 * new DB object or by using setOption().
904 * + <samp>DB_PORTABILITY_LOWERCASE</samp>
905 * convert names of fields to lower case
907 * + <samp>DB_PORTABILITY_RTRIM</samp>
908 * right trim the data
910 * @param array &$arr (reference) array where data from the row
912 * @param int $fetchmode how the resulting array should be indexed
913 * @param int $rownum the row number to fetch
915 * @return mixed DB_OK on success, null on no more rows or
916 * a DB_Error object on error
918 * @see DB_common::setOption(), DB_common::setFetchMode()
921 function fetchInto(&$arr, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null)
923 if ($fetchmode === DB_FETCHMODE_DEFAULT) {
924 $fetchmode = $this->fetchmode;
926 if ($fetchmode === DB_FETCHMODE_OBJECT) {
927 $fetchmode = DB_FETCHMODE_ASSOC;
928 $object_class = $this->fetchmode_object_class;
930 if ($this->limit_from !== null) {
931 if ($this->row_counter === null) {
932 $this->row_counter = $this->limit_from;
934 if ($this->limit_type == false) {
936 while ($i++ < $this->limit_from) {
937 $this->dbh->fetchInto($this->result, $arr, $fetchmode);
941 if ($this->row_counter >= (
942 $this->limit_from + $this->limit_count))
944 if ($this->autofree) {
949 if ($this->limit_type == 'emulate') {
950 $rownum = $this->row_counter;
953 $this->row_counter++;
955 $res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum);
956 if ($res === DB_OK) {
957 if (isset($object_class)) {
958 // default mode specified in DB_common::fetchmode_object_class property
959 if ($object_class == 'stdClass') {
960 $arr = (object) $arr;
962 $arr = new $object_class($arr);
967 if ($res == null && $this->autofree) {
977 * Get the the number of columns in a result set.
979 * @return int the number of columns, or a DB error
985 return $this->dbh->numCols($this->result);
992 * Get the number of rows in a result set.
994 * @return int the number of rows, or a DB error
1000 return $this->dbh->numRows($this->result);
1007 * Get the next result if a batch of queries was executed.
1009 * @return bool true if a new result is available or false if not.
1013 function nextResult()
1015 return $this->dbh->nextResult($this->result);
1022 * Frees the resources allocated for this result set.
1023 * @return int error code
1029 $err = $this->dbh->freeResult($this->result);
1030 if (DB::isError($err)) {
1033 $this->result = false;
1043 * @see DB_common::tableInfo()
1045 function tableInfo($mode = null)
1047 if (is_string($mode)) {
1048 return $this->dbh->raiseError(DB_ERROR_NEED_MORE_DATA);
1050 return $this->dbh->tableInfo($this, $mode);
1054 // {{{ getRowCounter()
1057 * returns the actual row number
1060 function getRowCounter()
1062 return $this->row_counter;
1071 * Pear DB Row Object
1072 * @see DB_common::setFetchMode()
1081 * @param resource row data as array
1083 function DB_row(&$arr)
1085 foreach ($arr as $key => $value) {
1086 $this->$key = &$arr[$key];