Subversion Repositories Applications.gtt

Rev

Rev 94 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 187
Line 3... Line 3...
3
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
Line 4... Line 4...
4
 
4
 
5
/**
5
/**
6
 * Database independent query interface
6
 * Database independent query interface
7
 *
7
 *
8
 * PHP versions 4 and 5
8
 * PHP version 5
9
 *
9
 *
10
 * LICENSE: This source file is subject to version 3.0 of the PHP license
10
 * LICENSE: This source file is subject to version 3.0 of the PHP license
11
 * that is available through the world-wide-web at the following URI:
11
 * that is available through the world-wide-web at the following URI:
12
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
12
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
Line 16... Line 16...
16
 * @category   Database
16
 * @category   Database
17
 * @package    DB
17
 * @package    DB
18
 * @author     Stig Bakken <ssb@php.net>
18
 * @author     Stig Bakken <ssb@php.net>
19
 * @author     Tomas V.V.Cox <cox@idecnet.com>
19
 * @author     Tomas V.V.Cox <cox@idecnet.com>
20
 * @author     Daniel Convissor <danielc@php.net>
20
 * @author     Daniel Convissor <danielc@php.net>
21
 * @copyright  1997-2005 The PHP Group
21
 * @copyright  1997-2007 The PHP Group
22
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
22
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
23
 * @version    CVS: $Id: DB.php,v 1.80 2005/02/16 02:16:00 danielc Exp $
23
 * @version    CVS: $Id$
24
 * @link       http://pear.php.net/package/DB
24
 * @link       http://pear.php.net/package/DB
25
 */
25
 */
Line 26... Line 26...
26
 
26
 
27
/**
27
/**
Line 422... Line 422...
422
 * @category   Database
422
 * @category   Database
423
 * @package    DB
423
 * @package    DB
424
 * @author     Stig Bakken <ssb@php.net>
424
 * @author     Stig Bakken <ssb@php.net>
425
 * @author     Tomas V.V.Cox <cox@idecnet.com>
425
 * @author     Tomas V.V.Cox <cox@idecnet.com>
426
 * @author     Daniel Convissor <danielc@php.net>
426
 * @author     Daniel Convissor <danielc@php.net>
427
 * @copyright  1997-2005 The PHP Group
427
 * @copyright  1997-2007 The PHP Group
428
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
428
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
429
 * @version    Release: 1.7.6
429
 * @version    Release: 1.9.2
430
 * @link       http://pear.php.net/package/DB
430
 * @link       http://pear.php.net/package/DB
431
 */
431
 */
432
class DB
432
class DB
433
{
433
{
434
    // {{{ &factory()
434
    // {{{ factory()
Line 435... Line 435...
435
 
435
 
436
    /**
436
    /**
437
     * Create a new DB object for the specified database type but don't
437
     * Create a new DB object for the specified database type but don't
438
     * connect to the database
438
     * connect to the database
Line 442... Line 442...
442
     *
442
     *
443
     * @return object  a new DB object.  A DB_Error object on failure.
443
     * @return object  a new DB object.  A DB_Error object on failure.
444
     *
444
     *
445
     * @see DB_common::setOption()
445
     * @see DB_common::setOption()
446
     */
446
     */
447
    function &factory($type, $options = false)
447
    public static function factory($type, $options = false)
448
    {
448
    {
449
        if (!is_array($options)) {
449
        if (!is_array($options)) {
450
            $options = array('persistent' => $options);
450
            $options = array('persistent' => $options);
451
        }
451
        }
Line 465... Line 465...
465
                                    . " file for '$dsn'",
465
                                    . " file for '$dsn'",
466
                                    'DB_Error', true);
466
                                    'DB_Error', true);
467
            return $tmp;
467
            return $tmp;
468
        }
468
        }
Line 469... Line 469...
469
 
469
 
Line 470... Line 470...
470
        @$obj =& new $classname;
470
        @$obj = new $classname;
471
 
471
 
472
        foreach ($options as $option => $value) {
472
        foreach ($options as $option => $value) {
473
            $test = $obj->setOption($option, $value);
473
            $test = $obj->setOption($option, $value);
Line 478... Line 478...
478
 
478
 
479
        return $obj;
479
        return $obj;
Line 480... Line 480...
480
    }
480
    }
481
 
481
 
Line 482... Line 482...
482
    // }}}
482
    // }}}
483
    // {{{ &connect()
483
    // {{{ connect()
484
 
484
 
485
    /**
485
    /**
Line 493... Line 493...
493
     * $options = array(
493
     * $options = array(
494
     *     'debug'       => 2,
494
     *     'debug'       => 2,
495
     *     'portability' => DB_PORTABILITY_ALL,
495
     *     'portability' => DB_PORTABILITY_ALL,
496
     * );
496
     * );
497
     *
497
     *
498
     * $db =& DB::connect($dsn, $options);
498
     * $db = DB::connect($dsn, $options);
499
     * if (PEAR::isError($db)) {
499
     * if (PEAR::isError($db)) {
500
     *     die($db->getMessage());
500
     *     die($db->getMessage());
501
     * }
501
     * }
502
     * </code>
502
     * </code>
503
     *
503
     *
Line 513... Line 513...
513
     *       DB_odbc::connect(), DB_pgsql::connect(), DB_sqlite::connect(),
513
     *       DB_odbc::connect(), DB_pgsql::connect(), DB_sqlite::connect(),
514
     *       DB_sybase::connect()
514
     *       DB_sybase::connect()
515
     *
515
     *
516
     * @uses DB::parseDSN(), DB_common::setOption(), PEAR::isError()
516
     * @uses DB::parseDSN(), DB_common::setOption(), PEAR::isError()
517
     */
517
     */
518
    function &connect($dsn, $options = array())
518
    public static function connect($dsn, $options = array())
519
    {
519
    {
520
        $dsninfo = DB::parseDSN($dsn);
520
        $dsninfo = DB::parseDSN($dsn);
521
        $type = $dsninfo['phptype'];
521
        $type = $dsninfo['phptype'];
Line 522... Line 522...
522
 
522
 
Line 537... Line 537...
537
 
537
 
538
        $classname = "DB_${type}";
538
        $classname = "DB_${type}";
539
        if (!class_exists($classname)) {
539
        if (!class_exists($classname)) {
540
            $tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null,
540
            $tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null,
541
                                    "Unable to include the DB/{$type}.php"
541
                                    "Unable to include the DB/{$type}.php"
-
 
542
                                    . " file for '"
542
                                    . " file for '$dsn'",
543
                                    . DB::getDSNString($dsn, true) . "'",
543
                                    'DB_Error', true);
544
                                    'DB_Error', true);
544
            return $tmp;
545
            return $tmp;
Line 545... Line 546...
545
        }
546
        }
Line 546... Line 547...
546
 
547
 
547
        @$obj =& new $classname;
548
        @$obj = new $classname;
548
 
549
 
549
        foreach ($options as $option => $value) {
550
        foreach ($options as $option => $value) {
550
            $test = $obj->setOption($option, $value);
551
            $test = $obj->setOption($option, $value);
551
            if (DB::isError($test)) {
552
            if (DB::isError($test)) {
Line 552... Line 553...
552
                return $test;
553
                return $test;
553
            }
554
            }
-
 
555
        }
-
 
556
 
-
 
557
        $err = $obj->connect($dsninfo, $obj->getOption('persistent'));
554
        }
558
        if (DB::isError($err)) {
-
 
559
            if (is_array($dsn)) {
555
 
560
                $err->addUserInfo(DB::getDSNString($dsn, true));
556
        $err = $obj->connect($dsninfo, $obj->getOption('persistent'));
561
            } else {
Line 557... Line 562...
557
        if (DB::isError($err)) {
562
                $err->addUserInfo($dsn);
558
            $err->addUserInfo($dsn);
563
            }
Line 570... Line 575...
570
     *
575
     *
571
     * @return string  the DB API version number
576
     * @return string  the DB API version number
572
     */
577
     */
573
    function apiVersion()
578
    function apiVersion()
574
    {
579
    {
575
        return '1.7.6';
580
        return '1.9.2';
576
    }
581
    }
Line 577... Line 582...
577
 
582
 
578
    // }}}
583
    // }}}
Line 583... Line 588...
583
     *
588
     *
584
     * @param mixed $value  the variable to check
589
     * @param mixed $value  the variable to check
585
     *
590
     *
586
     * @return bool  whether $value is DB_Error object
591
     * @return bool  whether $value is DB_Error object
587
     */
592
     */
588
    function isError($value)
593
    public static function isError($value)
589
    {
594
    {
590
        return is_a($value, 'DB_Error');
595
        return is_object($value) && is_a($value, 'DB_Error');		
591
    }
596
    }
Line 592... Line 597...
592
 
597
 
593
    // }}}
598
    // }}}
Line 598... Line 603...
598
     *
603
     *
599
     * @param mixed $value  the value to test
604
     * @param mixed $value  the value to test
600
     *
605
     *
601
     * @return bool  whether $value is a DB_<driver> object
606
     * @return bool  whether $value is a DB_<driver> object
602
     */
607
     */
603
    function isConnection($value)
608
    public static function isConnection($value)
604
    {
609
    {
605
        return (is_object($value) &&
610
        return (is_object($value) &&
606
                is_subclass_of($value, 'db_common') &&
611
                is_subclass_of($value, 'db_common') &&
607
                method_exists($value, 'simpleQuery'));
612
                method_exists($value, 'simpleQuery'));
608
    }
613
    }
Line 619... Line 624...
619
     *
624
     *
620
     * @param string $query  the query
625
     * @param string $query  the query
621
     *
626
     *
622
     * @return boolean  whether $query is a data manipulation query
627
     * @return boolean  whether $query is a data manipulation query
623
     */
628
     */
624
    function isManip($query)
629
    public static function isManip($query)
625
    {
630
    {
626
        $manips = 'INSERT|UPDATE|DELETE|REPLACE|'
631
        $manips = 'INSERT|UPDATE|DELETE|REPLACE|'
627
                . 'CREATE|DROP|'
632
                . 'CREATE|DROP|'
628
                . 'LOAD DATA|SELECT .* INTO|COPY|'
633
                . 'LOAD DATA|SELECT .* INTO .* FROM|COPY|'
629
                . 'ALTER|GRANT|REVOKE|'
634
                . 'ALTER|GRANT|REVOKE|'
630
                . 'LOCK|UNLOCK';
635
                . 'LOCK|UNLOCK';
631
        if (preg_match('/^\s*"?(' . $manips . ')\s+/i', $query)) {
636
        if (preg_match('/^\s*"?(' . $manips . ')\s+/i', $query)) {
632
            return true;
637
            return true;
633
        }
638
        }
Line 643... Line 648...
643
     * @param integer $value  the DB error code
648
     * @param integer $value  the DB error code
644
     *
649
     *
645
     * @return string  the error message or false if the error code was
650
     * @return string  the error message or false if the error code was
646
     *                  not recognized
651
     *                  not recognized
647
     */
652
     */
648
    function errorMessage($value)
653
    public static function errorMessage($value)
649
    {
654
    {
650
        static $errorMessages;
655
        static $errorMessages;
651
        if (!isset($errorMessages)) {
656
        if (!isset($errorMessages)) {
652
            $errorMessages = array(
657
            $errorMessages = array(
653
                DB_ERROR                    => 'unknown error',
658
                DB_ERROR                    => 'unknown error',
Line 724... Line 729...
724
     *  + hostspec: Host specification (hostname[:port])
729
     *  + hostspec: Host specification (hostname[:port])
725
     *  + database: Database to use on the DBMS server
730
     *  + database: Database to use on the DBMS server
726
     *  + username: User name for login
731
     *  + username: User name for login
727
     *  + password: Password for login
732
     *  + password: Password for login
728
     */
733
     */
729
    function parseDSN($dsn)
734
    public static function parseDSN($dsn)
730
    {
735
    {
731
        $parsed = array(
736
        $parsed = array(
732
            'phptype'  => false,
737
            'phptype'  => false,
733
            'dbsyntax' => false,
738
            'dbsyntax' => false,
734
            'username' => false,
739
            'username' => false,
Line 806... Line 811...
806
        }
811
        }
Line 807... Line 812...
807
 
812
 
808
        // process the different protocol options
813
        // process the different protocol options
809
        $parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp';
814
        $parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp';
-
 
815
        $proto_opts = rawurldecode($proto_opts);
-
 
816
        if (strpos($proto_opts, ':') !== false) {
-
 
817
            list($proto_opts, $parsed['port']) = explode(':', $proto_opts);
810
        $proto_opts = rawurldecode($proto_opts);
818
        }
811
        if ($parsed['protocol'] == 'tcp') {
-
 
812
            if (strpos($proto_opts, ':') !== false) {
-
 
813
                list($parsed['hostspec'],
-
 
814
                     $parsed['port']) = explode(':', $proto_opts);
-
 
815
            } else {
819
        if ($parsed['protocol'] == 'tcp') {
816
                $parsed['hostspec'] = $proto_opts;
-
 
817
            }
820
            $parsed['hostspec'] = $proto_opts;
818
        } elseif ($parsed['protocol'] == 'unix') {
821
        } elseif ($parsed['protocol'] == 'unix') {
819
            $parsed['socket'] = $proto_opts;
822
            $parsed['socket'] = $proto_opts;
Line 820... Line 823...
820
        }
823
        }
Line 846... Line 849...
846
 
849
 
847
        return $parsed;
850
        return $parsed;
Line 848... Line 851...
848
    }
851
    }
-
 
852
 
-
 
853
    // }}}
-
 
854
    // {{{ getDSNString()
-
 
855
 
-
 
856
    /**
-
 
857
     * Returns the given DSN in a string format suitable for output.
-
 
858
     *
-
 
859
     * @param array|string the DSN to parse and format
-
 
860
     * @param boolean true to hide the password, false to include it
-
 
861
     * @return string
-
 
862
     */
-
 
863
    public static function getDSNString($dsn, $hidePassword) {
-
 
864
        /* Calling parseDSN will ensure that we have all the array elements
-
 
865
         * defined, and means that we deal with strings and array in the same
-
 
866
         * manner. */
-
 
867
        $dsnArray = DB::parseDSN($dsn);
-
 
868
        
-
 
869
        if ($hidePassword) {
-
 
870
            $dsnArray['password'] = 'PASSWORD';
-
 
871
        }
-
 
872
 
-
 
873
        /* Protocol is special-cased, as using the default "tcp" along with an
-
 
874
         * Oracle TNS connection string fails. */
-
 
875
        if (is_string($dsn) && strpos($dsn, 'tcp') === false && $dsnArray['protocol'] == 'tcp') {
-
 
876
            $dsnArray['protocol'] = false;
-
 
877
        }
-
 
878
        
-
 
879
        // Now we just have to construct the actual string. This is ugly.
-
 
880
        $dsnString = $dsnArray['phptype'];
-
 
881
        if ($dsnArray['dbsyntax']) {
-
 
882
            $dsnString .= '('.$dsnArray['dbsyntax'].')';
-
 
883
        }
-
 
884
        $dsnString .= '://'
-
 
885
                     .$dsnArray['username']
-
 
886
                     .':'
-
 
887
                     .$dsnArray['password']
-
 
888
                     .'@'
-
 
889
                     .$dsnArray['protocol'];
-
 
890
        if ($dsnArray['socket']) {
-
 
891
            $dsnString .= '('.$dsnArray['socket'].')';
-
 
892
        }
-
 
893
        if ($dsnArray['protocol'] && $dsnArray['hostspec']) {
-
 
894
            $dsnString .= '+';
-
 
895
        }
-
 
896
        $dsnString .= $dsnArray['hostspec'];
-
 
897
        if ($dsnArray['port']) {
-
 
898
            $dsnString .= ':'.$dsnArray['port'];
-
 
899
        }
-
 
900
        $dsnString .= '/'.$dsnArray['database'];
-
 
901
        
-
 
902
        /* Option handling. Unfortunately, parseDSN simply places options into
-
 
903
         * the top-level array, so we'll first get rid of the fields defined by
-
 
904
         * DB and see what's left. */
-
 
905
        unset($dsnArray['phptype'],
-
 
906
              $dsnArray['dbsyntax'],
-
 
907
              $dsnArray['username'],
-
 
908
              $dsnArray['password'],
-
 
909
              $dsnArray['protocol'],
-
 
910
              $dsnArray['socket'],
-
 
911
              $dsnArray['hostspec'],
-
 
912
              $dsnArray['port'],
-
 
913
              $dsnArray['database']
-
 
914
        );
-
 
915
        if (count($dsnArray) > 0) {
-
 
916
            $dsnString .= '?';
-
 
917
            $i = 0;
-
 
918
            foreach ($dsnArray as $key => $value) {
-
 
919
                if (++$i > 1) {
-
 
920
                    $dsnString .= '&';
-
 
921
                }
-
 
922
                $dsnString .= $key.'='.$value;
-
 
923
            }
-
 
924
        }
-
 
925
 
-
 
926
        return $dsnString;
-
 
927
    }
849
 
928
    
Line 850... Line 929...
850
    // }}}
929
    // }}}
851
}
930
}
Line 858... Line 937...
858
 * messages
937
 * messages
859
 *
938
 *
860
 * @category   Database
939
 * @category   Database
861
 * @package    DB
940
 * @package    DB
862
 * @author     Stig Bakken <ssb@php.net>
941
 * @author     Stig Bakken <ssb@php.net>
863
 * @copyright  1997-2005 The PHP Group
942
 * @copyright  1997-2007 The PHP Group
864
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
943
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
865
 * @version    Release: 1.7.6
944
 * @version    Release: 1.9.2
866
 * @link       http://pear.php.net/package/DB
945
 * @link       http://pear.php.net/package/DB
867
 */
946
 */
868
class DB_Error extends PEAR_Error
947
class DB_Error extends PEAR_Error
869
{
948
{
870
    // {{{ constructor
949
    // {{{ constructor
Line 878... Line 957...
878
     *                           PEAR_ERROR_TRIGGER
957
     *                           PEAR_ERROR_TRIGGER
879
     * @param mixed $debuginfo  additional debug info, such as the last query
958
     * @param mixed $debuginfo  additional debug info, such as the last query
880
     *
959
     *
881
     * @see PEAR_Error
960
     * @see PEAR_Error
882
     */
961
     */
883
    function DB_Error($code = DB_ERROR, $mode = PEAR_ERROR_RETURN,
962
    function __construct($code = DB_ERROR, $mode = PEAR_ERROR_RETURN,
884
                      $level = E_USER_NOTICE, $debuginfo = null)
963
                      $level = E_USER_NOTICE, $debuginfo = null)
885
    {
964
    {
886
        if (is_int($code)) {
965
        if (is_int($code)) {
887
            $this->PEAR_Error('DB Error: ' . DB::errorMessage($code), $code,
966
            parent::__construct('DB Error: ' . DB::errorMessage($code), $code,
888
                              $mode, $level, $debuginfo);
967
                              $mode, $level, $debuginfo);
889
        } else {
968
        } else {
890
            $this->PEAR_Error("DB Error: $code", DB_ERROR,
969
            parent::__construct("DB Error: $code", DB_ERROR,
891
                              $mode, $level, $debuginfo);
970
                              $mode, $level, $debuginfo);
892
        }
971
        }
893
    }
972
    }
Line -... Line 973...
-
 
973
 
-
 
974
    /**
-
 
975
     * Workaround to both avoid the "Redefining already defined constructor"
-
 
976
     * PHP error and provide backward compatibility in case someone is calling
-
 
977
     * DB_Error() dynamically
-
 
978
     */
-
 
979
    public function __call($method, $arguments)
-
 
980
    {
-
 
981
        if ($method == 'DB_Error') {
-
 
982
            return call_user_func_array(array($this, '__construct'), $arguments);
-
 
983
        }
-
 
984
        trigger_error(
-
 
985
            'Call to undefined method DB_Error::' . $method . '()', E_USER_ERROR
-
 
986
        );
894
 
987
    }
895
    // }}}
988
    // }}}
Line 896... Line 989...
896
}
989
}
897
 
990
 
Line 905... Line 998...
905
 * after processing a query that returns data.
998
 * after processing a query that returns data.
906
 *
999
 *
907
 * @category   Database
1000
 * @category   Database
908
 * @package    DB
1001
 * @package    DB
909
 * @author     Stig Bakken <ssb@php.net>
1002
 * @author     Stig Bakken <ssb@php.net>
910
 * @copyright  1997-2005 The PHP Group
1003
 * @copyright  1997-2007 The PHP Group
911
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
1004
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
912
 * @version    Release: 1.7.6
1005
 * @version    Release: 1.9.2
913
 * @link       http://pear.php.net/package/DB
1006
 * @link       http://pear.php.net/package/DB
914
 */
1007
 */
915
class DB_result
1008
class DB_result
916
{
1009
{
917
    // {{{ properties
1010
    // {{{ properties
Line 1014... Line 1107...
1014
     * @param resource $result   the result resource id
1107
     * @param resource $result   the result resource id
1015
     * @param array    $options  an associative array with result options
1108
     * @param array    $options  an associative array with result options
1016
     *
1109
     *
1017
     * @return void
1110
     * @return void
1018
     */
1111
     */
1019
    function DB_result(&$dbh, $result, $options = array())
1112
    function __construct(&$dbh, $result, $options = array())
1020
    {
1113
    {
1021
        $this->autofree    = $dbh->options['autofree'];
1114
        $this->autofree    = $dbh->options['autofree'];
1022
        $this->dbh         = &$dbh;
1115
        $this->dbh         = &$dbh;
1023
        $this->fetchmode   = $dbh->fetchmode;
1116
        $this->fetchmode   = $dbh->fetchmode;
1024
        $this->fetchmode_object_class = $dbh->fetchmode_object_class;
1117
        $this->fetchmode_object_class = $dbh->fetchmode_object_class;
Line 1087... Line 1180...
1087
        }
1180
        }
1088
        if ($fetchmode === DB_FETCHMODE_OBJECT) {
1181
        if ($fetchmode === DB_FETCHMODE_OBJECT) {
1089
            $fetchmode = DB_FETCHMODE_ASSOC;
1182
            $fetchmode = DB_FETCHMODE_ASSOC;
1090
            $object_class = $this->fetchmode_object_class;
1183
            $object_class = $this->fetchmode_object_class;
1091
        }
1184
        }
1092
        if ($this->limit_from !== null) {
1185
        if (is_null($rownum) && $this->limit_from !== null) {
1093
            if ($this->row_counter === null) {
1186
            if ($this->row_counter === null) {
1094
                $this->row_counter = $this->limit_from;
1187
                $this->row_counter = $this->limit_from;
1095
                // Skip rows
1188
                // Skip rows
1096
                if ($this->dbh->features['limit'] === false) {
1189
                if ($this->dbh->features['limit'] === false) {
1097
                    $i = 0;
1190
                    $i = 0;
Line 1119... Line 1212...
1119
                // The default mode is specified in the
1212
                // The default mode is specified in the
1120
                // DB_common::fetchmode_object_class property
1213
                // DB_common::fetchmode_object_class property
1121
                if ($object_class == 'stdClass') {
1214
                if ($object_class == 'stdClass') {
1122
                    $arr = (object) $arr;
1215
                    $arr = (object) $arr;
1123
                } else {
1216
                } else {
1124
                    $arr = &new $object_class($arr);
1217
                    $arr = new $object_class($arr);
1125
                }
1218
                }
1126
            }
1219
            }
1127
            return $arr;
1220
            return $arr;
1128
        }
1221
        }
1129
        if ($res == null && $this->autofree) {
1222
        if ($res == null && $this->autofree) {
Line 1169... Line 1262...
1169
        }
1262
        }
1170
        if ($fetchmode === DB_FETCHMODE_OBJECT) {
1263
        if ($fetchmode === DB_FETCHMODE_OBJECT) {
1171
            $fetchmode = DB_FETCHMODE_ASSOC;
1264
            $fetchmode = DB_FETCHMODE_ASSOC;
1172
            $object_class = $this->fetchmode_object_class;
1265
            $object_class = $this->fetchmode_object_class;
1173
        }
1266
        }
1174
        if ($this->limit_from !== null) {
1267
        if (is_null($rownum) && $this->limit_from !== null) {
1175
            if ($this->row_counter === null) {
1268
            if ($this->row_counter === null) {
1176
                $this->row_counter = $this->limit_from;
1269
                $this->row_counter = $this->limit_from;
1177
                // Skip rows
1270
                // Skip rows
1178
                if ($this->dbh->features['limit'] === false) {
1271
                if ($this->dbh->features['limit'] === false) {
1179
                    $i = 0;
1272
                    $i = 0;
Line 1251... Line 1344...
1251
            }
1344
            }
1252
            $i = 0;
1345
            $i = 0;
1253
            while ($res->fetchInto($tmp, DB_FETCHMODE_ORDERED)) {
1346
            while ($res->fetchInto($tmp, DB_FETCHMODE_ORDERED)) {
1254
                $i++;
1347
                $i++;
1255
            }
1348
            }
1256
            return $i;
1349
            $count = $i;
1257
        } else {
1350
        } else {
1258
            return $this->dbh->numRows($this->result);
1351
            $count = $this->dbh->numRows($this->result);
1259
        }
1352
        }
-
 
1353
 
-
 
1354
        /* fbsql is checked for here because limit queries are implemented
-
 
1355
         * using a TOP() function, which results in fbsql_num_rows still
-
 
1356
         * returning the total number of rows that would have been returned,
-
 
1357
         * rather than the real number. As a result, we'll just do the limit
-
 
1358
         * calculations for fbsql in the same way as a database with emulated
-
 
1359
         * limits. Unfortunately, we can't just do this in DB_fbsql::numRows()
-
 
1360
         * because that only gets the result resource, rather than the full
-
 
1361
         * DB_Result object. */
-
 
1362
        if (($this->dbh->features['limit'] === 'emulate'
-
 
1363
             && $this->limit_from !== null)
-
 
1364
            || $this->dbh->phptype == 'fbsql') {
-
 
1365
            $limit_count = is_null($this->limit_count) ? $count : $this->limit_count;
-
 
1366
            if ($count < $this->limit_from) {
-
 
1367
                $count = 0;
-
 
1368
            } elseif ($count < ($this->limit_from + $limit_count)) {
-
 
1369
                $count -= $this->limit_from;
-
 
1370
            } else {
-
 
1371
                $count = $limit_count;
-
 
1372
            }
-
 
1373
        }
-
 
1374
 
-
 
1375
        return $count;
1260
    }
1376
    }
Line 1261... Line 1377...
1261
 
1377
 
1262
    // }}}
1378
    // }}}
Line 1347... Line 1463...
1347
 * is placed in a property named for the column.
1463
 * is placed in a property named for the column.
1348
 *
1464
 *
1349
 * @category   Database
1465
 * @category   Database
1350
 * @package    DB
1466
 * @package    DB
1351
 * @author     Stig Bakken <ssb@php.net>
1467
 * @author     Stig Bakken <ssb@php.net>
1352
 * @copyright  1997-2005 The PHP Group
1468
 * @copyright  1997-2007 The PHP Group
1353
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
1469
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
1354
 * @version    Release: 1.7.6
1470
 * @version    Release: 1.9.2
1355
 * @link       http://pear.php.net/package/DB
1471
 * @link       http://pear.php.net/package/DB
1356
 * @see        DB_common::setFetchMode()
1472
 * @see        DB_common::setFetchMode()
1357
 */
1473
 */
1358
class DB_row
1474
class DB_row
1359
{
1475
{
Line 1364... Line 1480...
1364
     *
1480
     *
1365
     * @param array  the array containing the row's data
1481
     * @param array  the array containing the row's data
1366
     *
1482
     *
1367
     * @return void
1483
     * @return void
1368
     */
1484
     */
1369
    function DB_row(&$arr)
1485
    function __construct(&$arr)
1370
    {
1486
    {
1371
        foreach ($arr as $key => $value) {
1487
        foreach ($arr as $key => $value) {
1372
            $this->$key = &$arr[$key];
1488
            $this->$key = &$arr[$key];
1373
        }
1489
        }
1374
    }
1490
    }