Ignore:
Timestamp:
09/26/13 15:41:49 (11 years ago)
Author:
angelo
Message:

Ticket #3491 - Compatibilizar Expresso com novas versoes do PHP

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/adodb.inc.php

    r34 r8222  
    33 * Set tabs to 4 for best viewing. 
    44 *  
    5  * Latest version is available at http://adodb.sourceforge.net/ 
     5 * Latest version is available at http://adodb.sourceforge.net 
    66 *  
    77 * This is the main include file for ADOdb. 
     
    1313 
    1414/** 
    15         \mainpage        
    16          
    17          @version V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved. 
     15        \mainpage 
     16         
     17         @version V5.18 3 Sep 2012   (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved. 
    1818 
    1919        Released under both BSD license and Lesser GPL library license. You can choose which license 
     
    5555                $ADODB_COUNTRECS,       // count number of records returned - slows down query 
    5656                $ADODB_CACHE_DIR,       // directory to cache recordsets 
     57                $ADODB_CACHE, 
     58                $ADODB_CACHE_CLASS, 
    5759                $ADODB_EXTENSION,   // ADODB extension installed 
    5860                $ADODB_COMPAT_FETCH, // If $ADODB_COUNTRECS and this is true, $rs->fields is available on EOF 
    5961                $ADODB_FETCH_MODE,      // DEFAULT, NUM, ASSOC or BOTH. Default follows native driver default... 
     62                $ADODB_GETONE_EOF, 
    6063                $ADODB_QUOTE_FIELDNAMES; // Allows you to force quotes (backticks) around field names in queries generated by getinsertsql and getupdatesql.     
    6164         
     
    116119                } else if ($_adodb_ver >= 5.0) { 
    117120                        define('ADODB_PHPVER',0x5000); 
    118                 } else if ($_adodb_ver > 4.299999) { # 4.3 
    119                         define('ADODB_PHPVER',0x4300); 
    120                 } else if ($_adodb_ver > 4.199999) { # 4.2 
    121                         define('ADODB_PHPVER',0x4200); 
    122                 } else if (strnatcmp(PHP_VERSION,'4.0.5')>=0) { 
    123                         define('ADODB_PHPVER',0x4050); 
    124                 } else { 
    125                         define('ADODB_PHPVER',0x4000); 
    126                 } 
    127         } 
     121                } else  
     122                        die("PHP5 or later required. You are running ".PHP_VERSION); 
     123        } 
     124         
    128125         
    129126        //if (!defined('ADODB_ASSOC_CASE')) define('ADODB_ASSOC_CASE',2); 
     
    154151                $ADODB_CACHE_DIR,       // directory to cache recordsets 
    155152                $ADODB_FETCH_MODE, 
     153                $ADODB_CACHE, 
     154                $ADODB_CACHE_CLASS, 
    156155                $ADODB_FORCE_TYPE, 
     156                $ADODB_GETONE_EOF, 
    157157                $ADODB_QUOTE_FIELDNAMES; 
    158158                 
     159                if (empty($ADODB_CACHE_CLASS)) $ADODB_CACHE_CLASS =  'ADODB_Cache_File' ; 
    159160                $ADODB_FETCH_MODE = ADODB_FETCH_DEFAULT; 
    160161                $ADODB_FORCE_TYPE = ADODB_FORCE_VALUE; 
    161  
     162                $ADODB_GETONE_EOF = null; 
    162163 
    163164                if (!isset($ADODB_CACHE_DIR)) { 
     
    177178                 * ADODB version as a string. 
    178179                 */ 
    179                 $ADODB_vers = 'V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved. Released BSD & LGPL.'; 
     180                $ADODB_vers = 'V5.18 3 Sep 2012  (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved. Released BSD & LGPL.'; 
    180181         
    181182                /** 
     
    216217        } 
    217218         
    218  
     219         
     220        function _adodb_safedate($s) 
     221        { 
     222                return str_replace(array("'", '\\'), '', $s); 
     223        } 
     224 
     225        // parse date string to prevent injection attack 
     226        // date string will have one quote at beginning e.g. '3434343' 
     227        function _adodb_safedateq($s) 
     228        { 
     229                $len = strlen($s); 
     230                if ($s[0] !== "'") $s2 = "'".$s[0]; 
     231                else $s2 = "'"; 
     232                for($i=1; $i<$len; $i++) { 
     233                        $ch = $s[$i]; 
     234                        if ($ch === '\\') { 
     235                                $s2 .= "'"; 
     236                                break; 
     237                        } elseif ($ch === "'") { 
     238                                $s2 .= $ch; 
     239                                break; 
     240                        } 
     241                         
     242                        $s2 .= $ch; 
     243                } 
     244                 
     245                return strlen($s2) == 0 ? 'null' : $s2; 
     246        } 
     247 
     248         
     249        // for transaction handling 
    219250         
    220251        function ADODB_TransMonitor($dbms, $fn, $errno, $errmsg, $p1, $p2, &$thisConnection) 
     
    225256                        $fn = $thisConnection->_oldRaiseFn; 
    226257                        $fn($dbms, $fn, $errno, $errmsg, $p1, $p2,$thisConnection); 
     258                } 
     259        } 
     260         
     261        //------------------ 
     262        // class for caching 
     263        class ADODB_Cache_File { 
     264         
     265                var $createdir = true; // requires creation of temp dirs 
     266                 
     267                function ADODB_Cache_File() 
     268                { 
     269                global $ADODB_INCLUDED_CSV; 
     270                        if (empty($ADODB_INCLUDED_CSV)) include_once(ADODB_DIR.'/adodb-csvlib.inc.php'); 
     271                } 
     272                 
     273                // write serialised recordset to cache item/file 
     274                function writecache($filename, $contents,  $debug, $secs2cache) 
     275                { 
     276                        return adodb_write_file($filename, $contents,$debug); 
     277                } 
     278                 
     279                // load serialised recordset and unserialise it 
     280                function &readcache($filename, &$err, $secs2cache, $rsClass) 
     281                { 
     282                        $rs = csv2rs($filename,$err,$secs2cache,$rsClass); 
     283                        return $rs; 
     284                } 
     285                 
     286                // flush all items in cache 
     287                function flushall($debug=false) 
     288                { 
     289                global $ADODB_CACHE_DIR; 
     290 
     291                $rez = false; 
     292                 
     293                        if (strlen($ADODB_CACHE_DIR) > 1) { 
     294                                $rez = $this->_dirFlush($ADODB_CACHE_DIR); 
     295                        if ($debug) ADOConnection::outp( "flushall: $dir<br><pre>\n". $rez."</pre>"); 
     296                        } 
     297                        return $rez; 
     298                } 
     299                 
     300                // flush one file in cache 
     301                function flushcache($f, $debug=false) 
     302                { 
     303                        if (!@unlink($f)) { 
     304                                if ($debug) ADOConnection::outp( "flushcache: failed for $f"); 
     305                        } 
     306                } 
     307                 
     308                function getdirname($hash) 
     309                { 
     310                global $ADODB_CACHE_DIR; 
     311                        if (!isset($this->notSafeMode)) $this->notSafeMode = !ini_get('safe_mode'); 
     312                        return ($this->notSafeMode) ? $ADODB_CACHE_DIR.'/'.substr($hash,0,2) : $ADODB_CACHE_DIR; 
     313                } 
     314                 
     315                // create temp directories 
     316                function createdir($hash, $debug) 
     317                { 
     318                global $ADODB_CACHE_PERMS; 
     319                 
     320                        $dir = $this->getdirname($hash); 
     321                        if ($this->notSafeMode && !file_exists($dir)) { 
     322                                $oldu = umask(0); 
     323                                if (!@mkdir($dir, empty($ADODB_CACHE_PERMS) ? 0771 : $ADODB_CACHE_PERMS)) if(!is_dir($dir) && $debug) ADOConnection::outp("Cannot create $dir"); 
     324                                umask($oldu); 
     325                        } 
     326                 
     327                        return $dir; 
     328                } 
     329                 
     330                /** 
     331                * Private function to erase all of the files and subdirectories in a directory. 
     332                * 
     333                * Just specify the directory, and tell it if you want to delete the directory or just clear it out. 
     334                * Note: $kill_top_level is used internally in the function to flush subdirectories. 
     335                */ 
     336                function _dirFlush($dir, $kill_top_level = false)  
     337                { 
     338                   if(!$dh = @opendir($dir)) return; 
     339                    
     340                   while (($obj = readdir($dh))) { 
     341                                if($obj=='.' || $obj=='..') continue; 
     342                                $f = $dir.'/'.$obj; 
     343                 
     344                                if (strpos($obj,'.cache')) @unlink($f); 
     345                                if (is_dir($f)) $this->_dirFlush($f, true); 
     346                   } 
     347                   if ($kill_top_level === true) @rmdir($dir); 
     348                   return true; 
    227349                } 
    228350        } 
     
    288410        var $sysDate = false; /// name of function that returns the current date 
    289411        var $sysTimeStamp = false; /// name of function that returns the current timestamp 
     412        var $sysUTimeStamp = false; // name of function that returns the current timestamp accurate to the microsecond or nearest fraction 
    290413        var $arrayClass = 'ADORecordSet_array'; /// name of class used to generate array recordsets, which are pre-downloaded recordsets 
    291414         
     
    313436         
    314437        var $null2null = 'null'; // in autoexecute/getinsertsql/getupdatesql, this value will be converted to a null 
     438        var $bulkBind = false; // enable 2D Execute array 
    315439         // 
    316440         // PRIVATE VARS 
     
    341465        } 
    342466         
    343         function Version() 
     467        static function Version() 
    344468        { 
    345469        global $ADODB_vers; 
    346470         
    347                 return (float) substr($ADODB_vers,1); 
     471                $ok = preg_match( '/^[Vv]([0-9\.]+)/', $ADODB_vers, $matches ); 
     472                if (!$ok) return (float) substr($ADODB_vers,1); 
     473                else return $matches[1]; 
    348474        } 
    349475         
     
    374500        * You can define your own handler by defining the function name in ADODB_OUTP. 
    375501        */ 
    376         function outp($msg,$newline=true) 
     502        static function outp($msg,$newline=true) 
    377503        { 
    378504        global $ADODB_FLUSH,$ADODB_OUTP; 
     
    400526        function Time() 
    401527        { 
    402                 $rs =& $this->_Execute("select $this->sysTimeStamp"); 
     528                $rs = $this->_Execute("select $this->sysTimeStamp"); 
    403529                if ($rs && !$rs->EOF) return $this->UnixTimeStamp(reset($rs->fields)); 
    404530                 
     
    421547                if ($argHostname != "") $this->host = $argHostname; 
    422548                if ($argUsername != "") $this->user = $argUsername; 
    423                 if ($argPassword != "") $this->password = $argPassword; // not stored for security reasons 
     549                if ($argPassword != "") $this->password = 'not stored'; // not stored for security reasons 
    424550                if ($argDatabaseName != "") $this->database = $argDatabaseName;          
    425551                 
    426552                $this->_isPersistentConnection = false;  
     553                         
    427554                if ($forceNew) { 
    428                         if ($rez=$this->_nconnect($this->host, $this->user, $this->password, $this->database)) return true; 
     555                        if ($rez=$this->_nconnect($this->host, $this->user, $argPassword, $this->database)) return true; 
    429556                } else { 
    430                          if ($rez=$this->_connect($this->host, $this->user, $this->password, $this->database)) return true; 
     557                         if ($rez=$this->_connect($this->host, $this->user, $argPassword, $this->database)) return true; 
    431558                } 
    432559                if (isset($rez)) { 
     
    480607        function PConnect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "") 
    481608        { 
     609                 
    482610                if (defined('ADODB_NEVER_PERSIST'))  
    483611                        return $this->Connect($argHostname,$argUsername,$argPassword,$argDatabaseName); 
     
    485613                if ($argHostname != "") $this->host = $argHostname; 
    486614                if ($argUsername != "") $this->user = $argUsername; 
    487                 if ($argPassword != "") $this->password = $argPassword; 
     615                if ($argPassword != "") $this->password = 'not stored'; 
    488616                if ($argDatabaseName != "") $this->database = $argDatabaseName;          
    489617                         
    490618                $this->_isPersistentConnection = true;   
    491                 if ($rez = $this->_pconnect($this->host, $this->user, $this->password, $this->database)) return true; 
     619                 
     620                if ($rez = $this->_pconnect($this->host, $this->user, $argPassword, $this->database)) return true; 
    492621                if (isset($rez)) { 
    493622                        $err = $this->ErrorMsg(); 
     
    507636        } 
    508637 
     638        function outp_throw($msg,$src='WARN',$sql='') 
     639        { 
     640                if (defined('ADODB_ERROR_HANDLER') &&  ADODB_ERROR_HANDLER == 'adodb_throw') { 
     641                        adodb_throw($this->databaseType,$src,-9999,$msg,$sql,false,$this); 
     642                        return; 
     643                }  
     644                ADOConnection::outp($msg); 
     645        } 
     646         
     647        // create cache class. Code is backward compat with old memcache implementation 
     648        function _CreateCache() 
     649        { 
     650        global $ADODB_CACHE, $ADODB_CACHE_CLASS; 
     651         
     652                if ($this->memCache) { 
     653                global $ADODB_INCLUDED_MEMCACHE; 
     654                 
     655                        if (empty($ADODB_INCLUDED_MEMCACHE)) include(ADODB_DIR.'/adodb-memcache.lib.inc.php'); 
     656                                $ADODB_CACHE = new ADODB_Cache_MemCache($this); 
     657                } else 
     658                                $ADODB_CACHE = new $ADODB_CACHE_CLASS($this); 
     659                 
     660        } 
     661         
    509662        // Format date column in sql string given an input format that understands Y M D 
    510663        function SQLDate($fmt, $col=false) 
     
    533686                return $sql; 
    534687        } 
    535          
     688 
    536689        /** 
    537690         * Some databases, eg. mssql require a different function for preparing 
     
    552705                return $this->Prepare($sql,$param); 
    553706        } 
    554          
     707 
    555708        /** 
    556709        * PEAR DB Compat 
     
    599752        *  @param $where        where clause to use, eg: "WHERE row=12". If left empty, will escalate to table lock 
    600753        */ 
    601         function RowLock($table,$where) 
     754        function RowLock($table,$where,$col='1 as adodbignore') 
    602755        { 
    603756                return false; 
     
    639792        * PEAR DB Compat - do not use internally.  
    640793        */ 
    641         function &Query($sql, $inputarr=false) 
    642         { 
    643                 $rs = &$this->Execute($sql, $inputarr); 
     794        function Query($sql, $inputarr=false) 
     795        { 
     796                $rs = $this->Execute($sql, $inputarr); 
    644797                if (!$rs && defined('ADODB_PEAR')) return ADODB_PEAR_Error(); 
    645798                return $rs; 
     
    650803        * PEAR DB Compat - do not use internally 
    651804        */ 
    652         function &LimitQuery($sql, $offset, $count, $params=false) 
    653         { 
    654                 $rs = &$this->SelectLimit($sql, $count, $offset, $params);  
     805        function LimitQuery($sql, $offset, $count, $params=false) 
     806        { 
     807                $rs = $this->SelectLimit($sql, $count, $offset, $params);  
    655808                if (!$rs && defined('ADODB_PEAR')) return ADODB_PEAR_Error(); 
    656809                return $rs; 
     
    744897                if ($this->transOff > 0) { 
    745898                        $this->transOff += 1; 
    746                         return; 
     899                        return true; 
    747900                } 
    748901                 
     
    752905                 
    753906                if ($this->debug && $this->transCnt > 0) ADOConnection::outp("Bad Transaction: StartTrans called within BeginTrans"); 
    754                 $this->BeginTrans(); 
     907                $ok = $this->BeginTrans(); 
    755908                $this->transOff = 1; 
     909                return $ok; 
    756910        } 
    757911         
     
    820974         * @return              RecordSet or false 
    821975         */ 
    822         function &Execute($sql,$inputarr=false)  
     976        function Execute($sql,$inputarr=false)  
    823977        { 
    824978                if ($this->fnExecute) { 
    825979                        $fn = $this->fnExecute; 
    826                         $ret =& $fn($this,$sql,$inputarr); 
     980                        $ret = $fn($this,$sql,$inputarr); 
    827981                        if (isset($ret)) return $ret; 
    828982                } 
     
    832986                        $element0 = reset($inputarr); 
    833987                        # is_object check because oci8 descriptors can be passed in 
    834                         $array_2d = is_array($element0) && !is_object(reset($element0)); 
     988                        $array_2d = $this->bulkBind && is_array($element0) && !is_object(reset($element0)); 
     989                 
    835990                        //remove extra memory copy of input -mikefedyk 
    836991                        unset($element0); 
     
    838993                        if (!is_array($sql) && !$this->_bindInputArray) { 
    839994                                $sqlarr = explode('?',$sql); 
    840                                          
     995                                $nparams = sizeof($sqlarr)-1; 
    841996                                if (!$array_2d) $inputarr = array($inputarr); 
     997         
    842998                                foreach($inputarr as $arr) { 
    843999                                        $sql = ''; $i = 0; 
     
    8631019                                                        $sql .= $v; 
    8641020                                                $i += 1; 
    865                                         } 
     1021                                                 
     1022                                                if ($i == $nparams) break; 
     1023                                        } // while 
    8661024                                        if (isset($sqlarr[$i])) { 
    8671025                                                $sql .= $sqlarr[$i]; 
    868                                                 if ($i+1 != sizeof($sqlarr)) ADOConnection::outp( "Input Array does not match ?: ".htmlspecialchars($sql)); 
     1026                                                if ($i+1 != sizeof($sqlarr)) $this->outp_throw( "Input Array does not match ?: ".htmlspecialchars($sql),'Execute'); 
    8691027                                        } else if ($i != sizeof($sqlarr))        
    870                                                 ADOConnection::outp( "Input array does not match ?: ".htmlspecialchars($sql)); 
    871                  
    872                                         $ret =& $this->_Execute($sql); 
     1028                                                $this->outp_throw( "Input array does not match ?: ".htmlspecialchars($sql),'Execute'); 
     1029                 
     1030                                        $ret = $this->_Execute($sql); 
    8731031                                        if (!$ret) return $ret; 
    8741032                                }        
     
    8791037                                        else 
    8801038                                                $stmt = $sql; 
    881                                                  
     1039                                         
    8821040                                        foreach($inputarr as $arr) { 
    883                                                 $ret =& $this->_Execute($stmt,$arr); 
     1041                                                $ret = $this->_Execute($stmt,$arr); 
    8841042                                                if (!$ret) return $ret; 
    8851043                                        } 
    8861044                                } else { 
    887                                         $ret =& $this->_Execute($sql,$inputarr); 
     1045                                        $ret = $this->_Execute($sql,$inputarr); 
    8881046                                } 
    8891047                        } 
    8901048                } else { 
    891                         $ret =& $this->_Execute($sql,false); 
     1049                        $ret = $this->_Execute($sql,false); 
    8921050                } 
    8931051 
     
    8961054         
    8971055         
    898         function &_Execute($sql,$inputarr=false) 
     1056        function _Execute($sql,$inputarr=false) 
    8991057        { 
    9001058                if ($this->debug) { 
     
    9211079                 
    9221080                if ($this->_queryID === true) { // return simplified recordset for inserts/updates/deletes with lower overhead 
    923                         $rs = new ADORecordSet_empty(); 
     1081                        $rsclass = $this->rsPrefix.'empty'; 
     1082                        $rs = (class_exists($rsclass)) ? new $rsclass():  new ADORecordSet_empty(); 
     1083                         
    9241084                        return $rs; 
    9251085                } 
     
    9281088                $rsclass = $this->rsPrefix.$this->databaseType; 
    9291089                $rs = new $rsclass($this->_queryID,$this->fetchMode); 
    930                 $rs->connection = &$this; // Pablo suggestion 
     1090                $rs->connection = $this; // Pablo suggestion 
    9311091                $rs->Init(); 
    9321092                if (is_array($sql)) $rs->sql = $sql[0]; 
     
    9361096                        if ($ADODB_COUNTRECS) { 
    9371097                                if (!$rs->EOF) {  
    938                                         $rs = &$this->_rs2rs($rs,-1,-1,!is_array($sql)); 
     1098                                        $rs = $this->_rs2rs($rs,-1,-1,!is_array($sql)); 
    9391099                                        $rs->_queryID = $this->_queryID; 
    9401100                                } else 
     
    10811241        // owner not used in base class - see oci8 
    10821242                $p = array(); 
    1083                 $objs =& $this->MetaColumns($table); 
     1243                $objs = $this->MetaColumns($table); 
    10841244                if ($objs) { 
    10851245                        foreach($objs as $v) { 
     
    11301290        * @return               the recordset ($rs->databaseType == 'array') 
    11311291        */ 
    1132         function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) 
     1292        function SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) 
    11331293        { 
    11341294                if ($this->hasTop && $nrows > 0) { 
     
    11471307 
    11481308                                                if ($secs2cache != 0) { 
    1149                                                         $ret =& $this->CacheExecute($secs2cache, $sql,$inputarr); 
     1309                                                        $ret = $this->CacheExecute($secs2cache, $sql,$inputarr); 
    11501310                                                } else { 
    1151                                                         $ret =& $this->Execute($sql,$inputarr); 
     1311                                                        $ret = $this->Execute($sql,$inputarr); 
    11521312                                                } 
    11531313                                                return $ret; // PHP5 fix 
     
    11781338                $ADODB_COUNTRECS = false; 
    11791339                         
    1180                 if ($offset>0){ 
    1181                         if ($secs2cache != 0) $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr); 
    1182                         else $rs = &$this->Execute($sql,$inputarr); 
    1183                 } else { 
    1184                         if ($secs2cache != 0) $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr); 
    1185                         else $rs = &$this->Execute($sql,$inputarr); 
    1186                 } 
     1340 
     1341                if ($secs2cache != 0) $rs = $this->CacheExecute($secs2cache,$sql,$inputarr); 
     1342                else $rs = $this->Execute($sql,$inputarr); 
     1343                 
    11871344                $ADODB_COUNTRECS = $savec; 
    11881345                if ($rs && !$rs->EOF) { 
    1189                         $rs =& $this->_rs2rs($rs,$nrows,$offset); 
     1346                        $rs = $this->_rs2rs($rs,$nrows,$offset); 
    11901347                } 
    11911348                //print_r($rs); 
     
    11981355        * @param rs                     the recordset to serialize 
    11991356        */ 
    1200         function &SerializableRS(&$rs) 
    1201         { 
    1202                 $rs2 =& $this->_rs2rs($rs); 
     1357        function SerializableRS(&$rs) 
     1358        { 
     1359                $rs2 = $this->_rs2rs($rs); 
    12031360                $ignore = false; 
    1204                 $rs2->connection =& $ignore; 
     1361                $rs2->connection = $ignore; 
    12051362                 
    12061363                return $rs2; 
     
    12251382                $dbtype = $rs->databaseType; 
    12261383                if (!$dbtype) { 
    1227                         $rs = &$rs;  // required to prevent crashing in 4.2.1, but does not happen in 4.3.1 -- why ? 
     1384                        $rs = $rs;  // required to prevent crashing in 4.2.1, but does not happen in 4.3.1 -- why ? 
    12281385                        return $rs; 
    12291386                } 
    12301387                if (($dbtype == 'array' || $dbtype == 'csv') && $nrows == -1 && $offset == -1) { 
    12311388                        $rs->MoveFirst(); 
    1232                         $rs = &$rs; // required to prevent crashing in 4.2.1, but does not happen in 4.3.1-- why ? 
     1389                        $rs = $rs; // required to prevent crashing in 4.2.1, but does not happen in 4.3.1-- why ? 
    12331390                        return $rs; 
    12341391                } 
     
    12381395                } 
    12391396 
    1240                 $arr =& $rs->GetArrayLimit($nrows,$offset); 
     1397                $arr = $rs->GetArrayLimit($nrows,$offset); 
    12411398                //print_r($arr); 
    12421399                if ($close) $rs->Close(); 
     
    12451402                 
    12461403                $rs2 = new $arrayClass(); 
    1247                 $rs2->connection = &$this; 
     1404                $rs2->connection = $this; 
    12481405                $rs2->sql = $rs->sql; 
    12491406                $rs2->dataProvider = $this->dataProvider; 
     
    12561413        * Return all rows. Compat with PEAR DB 
    12571414        */ 
    1258         function &GetAll($sql, $inputarr=false) 
    1259         { 
    1260                 $arr =& $this->GetArray($sql,$inputarr); 
     1415        function GetAll($sql, $inputarr=false) 
     1416        { 
     1417                $arr = $this->GetArray($sql,$inputarr); 
    12611418                return $arr; 
    12621419        } 
    12631420         
    1264         function &GetAssoc($sql, $inputarr=false,$force_array = false, $first2cols = false) 
    1265         { 
    1266                 $rs =& $this->Execute($sql, $inputarr); 
     1421        function GetAssoc($sql, $inputarr=false,$force_array = false, $first2cols = false) 
     1422        { 
     1423                $rs = $this->Execute($sql, $inputarr); 
    12671424                if (!$rs) { 
    12681425                        $false = false; 
    12691426                        return $false; 
    12701427                } 
    1271                 $arr =& $rs->GetAssoc($force_array,$first2cols); 
     1428                $arr = $rs->GetAssoc($force_array,$first2cols); 
    12721429                return $arr; 
    12731430        } 
    12741431         
    1275         function &CacheGetAssoc($secs2cache, $sql=false, $inputarr=false,$force_array = false, $first2cols = false) 
     1432        function CacheGetAssoc($secs2cache, $sql=false, $inputarr=false,$force_array = false, $first2cols = false) 
    12761433        { 
    12771434                if (!is_numeric($secs2cache)) { 
     
    12791436                        $force_array = $inputarr; 
    12801437                } 
    1281                 $rs =& $this->CacheExecute($secs2cache, $sql, $inputarr); 
     1438                $rs = $this->CacheExecute($secs2cache, $sql, $inputarr); 
    12821439                if (!$rs) { 
    12831440                        $false = false; 
    12841441                        return $false; 
    12851442                } 
    1286                 $arr =& $rs->GetAssoc($force_array,$first2cols); 
     1443                $arr = $rs->GetAssoc($force_array,$first2cols); 
    12871444                return $arr; 
    12881445        } 
     
    12971454        function GetOne($sql,$inputarr=false) 
    12981455        { 
    1299         global $ADODB_COUNTRECS; 
     1456        global $ADODB_COUNTRECS,$ADODB_GETONE_EOF; 
    13001457                $crecs = $ADODB_COUNTRECS; 
    13011458                $ADODB_COUNTRECS = false; 
    13021459                 
    13031460                $ret = false; 
    1304                 $rs = &$this->Execute($sql,$inputarr); 
     1461                $rs = $this->Execute($sql,$inputarr); 
    13051462                if ($rs) {       
    1306                         if (!$rs->EOF) $ret = reset($rs->fields); 
     1463                        if ($rs->EOF) $ret = $ADODB_GETONE_EOF; 
     1464                        else $ret = reset($rs->fields); 
     1465                         
    13071466                        $rs->Close(); 
    13081467                } 
     
    13111470        } 
    13121471         
     1472        // $where should include 'WHERE fld=value' 
     1473        function GetMedian($table, $field,$where = '') 
     1474        { 
     1475                $total = $this->GetOne("select count(*) from $table $where"); 
     1476                if (!$total) return false; 
     1477         
     1478                $midrow = (integer) ($total/2); 
     1479                $rs = $this->SelectLimit("select $field from $table $where order by 1",1,$midrow); 
     1480                if ($rs && !$rs->EOF) return reset($rs->fields); 
     1481                return false; 
     1482        } 
     1483         
     1484         
    13131485        function CacheGetOne($secs2cache,$sql=false,$inputarr=false) 
    13141486        { 
     1487        global $ADODB_GETONE_EOF; 
    13151488                $ret = false; 
    1316                 $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr); 
    1317                 if ($rs) {               
    1318                         if (!$rs->EOF) $ret = reset($rs->fields); 
     1489                $rs = $this->CacheExecute($secs2cache,$sql,$inputarr); 
     1490                if ($rs) { 
     1491                        if ($rs->EOF) $ret = $ADODB_GETONE_EOF; 
     1492                        else $ret = reset($rs->fields); 
    13191493                        $rs->Close(); 
    13201494                }  
     
    13251499        function GetCol($sql, $inputarr = false, $trim = false) 
    13261500        { 
    1327                 $rv = false; 
    1328                 $rs = &$this->Execute($sql, $inputarr); 
     1501                 
     1502                $rs = $this->Execute($sql, $inputarr); 
    13291503                if ($rs) { 
    13301504                        $rv = array(); 
     
    13411515                        } 
    13421516                        $rs->Close(); 
    1343                 } 
     1517                } else 
     1518                        $rv = false; 
    13441519                return $rv; 
    13451520        } 
     
    13471522        function CacheGetCol($secs, $sql = false, $inputarr = false,$trim=false) 
    13481523        { 
    1349                 $rv = false; 
    1350                 $rs = &$this->CacheExecute($secs, $sql, $inputarr); 
     1524                $rs = $this->CacheExecute($secs, $sql, $inputarr); 
    13511525                if ($rs) { 
     1526                        $rv = array(); 
    13521527                        if ($trim) { 
    13531528                                while (!$rs->EOF) { 
     
    13621537                        } 
    13631538                        $rs->Close(); 
    1364                 } 
     1539                } else 
     1540                        $rv = false; 
     1541                         
    13651542                return $rv; 
    13661543        } 
    13671544         
    1368         function &Transpose(&$rs,$addfieldnames=true) 
    1369         { 
    1370                 $rs2 =& $this->_rs2rs($rs); 
     1545        function Transpose(&$rs,$addfieldnames=true) 
     1546        { 
     1547                $rs2 = $this->_rs2rs($rs); 
    13711548                $false = false; 
    13721549                if (!$rs2) return $false; 
     
    13951572        * @param [inputarr]             input bind array 
    13961573        */ 
    1397         function &GetArray($sql,$inputarr=false) 
     1574        function GetArray($sql,$inputarr=false) 
    13981575        { 
    13991576        global $ADODB_COUNTRECS; 
     
    14011578                $savec = $ADODB_COUNTRECS; 
    14021579                $ADODB_COUNTRECS = false; 
    1403                 $rs =& $this->Execute($sql,$inputarr); 
     1580                $rs = $this->Execute($sql,$inputarr); 
    14041581                $ADODB_COUNTRECS = $savec; 
    14051582                if (!$rs)  
     
    14111588                                return $false; 
    14121589                        } 
    1413                 $arr =& $rs->GetArray(); 
     1590                $arr = $rs->GetArray(); 
    14141591                $rs->Close(); 
    14151592                return $arr; 
    14161593        } 
    14171594         
    1418         function &CacheGetAll($secs2cache,$sql=false,$inputarr=false) 
    1419         { 
    1420                 $arr =& $this->CacheGetArray($secs2cache,$sql,$inputarr); 
     1595        function CacheGetAll($secs2cache,$sql=false,$inputarr=false) 
     1596        { 
     1597                $arr = $this->CacheGetArray($secs2cache,$sql,$inputarr); 
    14211598                return $arr; 
    14221599        } 
    14231600         
    1424         function &CacheGetArray($secs2cache,$sql=false,$inputarr=false) 
     1601        function CacheGetArray($secs2cache,$sql=false,$inputarr=false) 
    14251602        { 
    14261603        global $ADODB_COUNTRECS; 
     
    14281605                $savec = $ADODB_COUNTRECS; 
    14291606                $ADODB_COUNTRECS = false; 
    1430                 $rs =& $this->CacheExecute($secs2cache,$sql,$inputarr); 
     1607                $rs = $this->CacheExecute($secs2cache,$sql,$inputarr); 
    14311608                $ADODB_COUNTRECS = $savec; 
    14321609                 
     
    14391616                                return $false; 
    14401617                        } 
    1441                 $arr =& $rs->GetArray(); 
     1618                $arr = $rs->GetArray(); 
    14421619                $rs->Close(); 
    14431620                return $arr; 
    14441621        } 
    14451622         
    1446          
    1447          
    1448         /** 
    1449         * Return one row of sql statement. Recordset is disposed for you. 
     1623        function GetRandRow($sql, $arr= false) 
     1624        { 
     1625                $rezarr = $this->GetAll($sql, $arr); 
     1626                $sz = sizeof($rezarr); 
     1627                return $rezarr[abs(rand()) % $sz]; 
     1628        } 
     1629         
     1630        /** 
     1631        * Return one row of sql statement. Recordset is disposed for you.  
     1632        * Note that SelectLimit should not be called. 
    14501633        * 
    14511634        * @param sql                    SQL statement 
    14521635        * @param [inputarr]             input bind array 
    14531636        */ 
    1454         function &GetRow($sql,$inputarr=false) 
     1637        function GetRow($sql,$inputarr=false) 
    14551638        { 
    14561639        global $ADODB_COUNTRECS; 
     
    14581641                $ADODB_COUNTRECS = false; 
    14591642                 
    1460                 $rs =& $this->Execute($sql,$inputarr); 
     1643                $rs = $this->Execute($sql,$inputarr); 
    14611644                 
    14621645                $ADODB_COUNTRECS = $crecs; 
     
    14721655        } 
    14731656         
    1474         function &CacheGetRow($secs2cache,$sql=false,$inputarr=false) 
    1475         { 
    1476                 $rs =& $this->CacheExecute($secs2cache,$sql,$inputarr); 
     1657        function CacheGetRow($secs2cache,$sql=false,$inputarr=false) 
     1658        { 
     1659                $rs = $this->CacheExecute($secs2cache,$sql,$inputarr); 
    14771660                if ($rs) { 
    1478                         $arr = false; 
    14791661                        if (!$rs->EOF) $arr = $rs->fields; 
     1662                        else $arr = array(); 
     1663                         
    14801664                        $rs->Close(); 
    14811665                        return $arr; 
     
    15321716        * @return               the recordset ($rs->databaseType == 'array') 
    15331717        */ 
    1534         function &CacheSelectLimit($secs2cache,$sql,$nrows=-1,$offset=-1,$inputarr=false) 
     1718        function CacheSelectLimit($secs2cache,$sql,$nrows=-1,$offset=-1,$inputarr=false) 
    15351719        {        
    15361720                if (!is_numeric($secs2cache)) { 
     
    15381722                        if ($offset == -1) $offset = false; 
    15391723                                                                          // sql,       nrows, offset,inputarr 
    1540                         $rs =& $this->SelectLimit($secs2cache,$sql,$nrows,$offset,$this->cacheSecs); 
     1724                        $rs = $this->SelectLimit($secs2cache,$sql,$nrows,$offset,$this->cacheSecs); 
    15411725                } else { 
    1542                         if ($sql === false) ADOConnection::outp( "Warning: \$sql missing from CacheSelectLimit()"); 
    1543                         $rs =& $this->SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); 
     1726                        if ($sql === false) $this->outp_throw("Warning: \$sql missing from CacheSelectLimit()",'CacheSelectLimit'); 
     1727                        $rs = $this->SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); 
    15441728                } 
    15451729                return $rs; 
     
    15581742        function CacheFlush($sql=false,$inputarr=false) 
    15591743        { 
    1560         global $ADODB_CACHE_DIR; 
    1561          
    1562                 if ($this->memCache) { 
    1563                 global $ADODB_INCLUDED_MEMCACHE; 
    1564                  
    1565                         $key = false; 
    1566                         if (empty($ADODB_INCLUDED_MEMCACHE)) include(ADODB_DIR.'/adodb-memcache.lib.inc.php'); 
    1567                         if ($sql) $key = $this->_gencachename($sql.serialize($inputarr),false,true); 
    1568                         FlushMemCache($key, $this->memCacheHost, $this->memCachePort, $this->debug); 
    1569                         return; 
    1570                 } 
    1571          
    1572                 if (strlen($ADODB_CACHE_DIR) > 1 && !$sql) { 
    1573          /*if (strncmp(PHP_OS,'WIN',3) === 0) 
    1574             $dir = str_replace('/', '\\', $ADODB_CACHE_DIR); 
    1575          else */ 
    1576             $dir = $ADODB_CACHE_DIR; 
    1577              
    1578          if ($this->debug) { 
    1579             ADOConnection::outp( "CacheFlush: $dir<br><pre>\n". $this->_dirFlush($dir)."</pre>"); 
    1580          } else { 
    1581             $this->_dirFlush($dir); 
    1582          } 
    1583          return; 
    1584       }  
    1585        
    1586       global $ADODB_INCLUDED_CSV; 
    1587       if (empty($ADODB_INCLUDED_CSV)) include(ADODB_DIR.'/adodb-csvlib.inc.php'); 
    1588        
    1589       $f = $this->_gencachename($sql.serialize($inputarr),false); 
    1590       adodb_write_file($f,''); // is adodb_write_file needed? 
    1591       if (!@unlink($f)) { 
    1592          if ($this->debug) ADOConnection::outp( "CacheFlush: failed for $f"); 
    1593       } 
    1594    } 
     1744        global $ADODB_CACHE_DIR, $ADODB_CACHE; 
     1745                 
     1746                if (empty($ADODB_CACHE)) return false; 
     1747                 
     1748                if (!$sql) { 
     1749                         $ADODB_CACHE->flushall($this->debug); 
     1750                 return; 
     1751            } 
     1752                 
     1753                $f = $this->_gencachename($sql.serialize($inputarr),false); 
     1754                return $ADODB_CACHE->flushcache($f, $this->debug); 
     1755        } 
    15951756    
    1596    /** 
    1597    * Private function to erase all of the files and subdirectories in a directory. 
    1598    * 
    1599    * Just specify the directory, and tell it if you want to delete the directory or just clear it out. 
    1600    * Note: $kill_top_level is used internally in the function to flush subdirectories. 
    1601    */ 
    1602    function _dirFlush($dir, $kill_top_level = false)  
    1603    { 
    1604       if(!$dh = @opendir($dir)) return; 
    1605        
    1606       while (($obj = readdir($dh))) { 
    1607          if($obj=='.' || $obj=='..') continue; 
    1608                 $f = $dir.'/'.$obj; 
    1609                  
    1610                 if (strpos($obj,'.cache')) @unlink($f); 
    1611                 if (is_dir($f)) $this->_dirFlush($f, true); 
    1612       } 
    1613       if ($kill_top_level === true) @rmdir($dir); 
    1614       return true; 
    1615    } 
    1616     
    1617     
    1618         function xCacheFlush($sql=false,$inputarr=false) 
    1619         { 
    1620         global $ADODB_CACHE_DIR; 
    1621          
    1622                 if ($this->memCache) { 
    1623                         global $ADODB_INCLUDED_MEMCACHE; 
    1624                         $key = false; 
    1625                         if (empty($ADODB_INCLUDED_MEMCACHE)) include(ADODB_DIR.'/adodb-memcache.lib.inc.php'); 
    1626                         if ($sql) $key = $this->_gencachename($sql.serialize($inputarr),false,true); 
    1627                         flushmemCache($key, $this->memCacheHost, $this->memCachePort, $this->debug); 
    1628                         return; 
    1629                 } 
    1630  
    1631                 if (strlen($ADODB_CACHE_DIR) > 1 && !$sql) { 
    1632                         if (strncmp(PHP_OS,'WIN',3) === 0) { 
    1633                                 $cmd = 'del /s '.str_replace('/','\\',$ADODB_CACHE_DIR).'\adodb_*.cache'; 
    1634                         } else { 
    1635                                 //$cmd = 'find "'.$ADODB_CACHE_DIR.'" -type f -maxdepth 1 -print0 | xargs -0 rm -f'; 
    1636                                 $cmd = 'rm -rf '.$ADODB_CACHE_DIR.'/[0-9a-f][0-9a-f]/';  
    1637                                 // old version 'rm -f `find '.$ADODB_CACHE_DIR.' -name adodb_*.cache`'; 
    1638                         } 
    1639                         if ($this->debug) { 
    1640                                 ADOConnection::outp( "CacheFlush: $cmd<br><pre>\n", system($cmd),"</pre>"); 
    1641                         } else { 
    1642                                 exec($cmd); 
    1643                         } 
    1644                         return; 
    1645                 }  
    1646                  
    1647                 global $ADODB_INCLUDED_CSV; 
    1648                 if (empty($ADODB_INCLUDED_CSV)) include(ADODB_DIR.'/adodb-csvlib.inc.php'); 
    1649                  
    1650                 $f = $this->_gencachename($sql.serialize($inputarr),false); 
    1651                 adodb_write_file($f,''); // is adodb_write_file needed? 
    1652                 if (!@unlink($f)) { 
    1653                         if ($this->debug) ADOConnection::outp( "CacheFlush: failed for $f"); 
    1654                 } 
    1655         } 
    16561757         
    16571758        /** 
     
    16691770        * then we can scale to 12.8 million unique cached recordsets. Wow! 
    16701771        */ 
    1671         function _gencachename($sql,$createdir,$memcache=false) 
    1672         { 
    1673         global $ADODB_CACHE_DIR; 
    1674         static $notSafeMode; 
     1772        function _gencachename($sql,$createdir) 
     1773        { 
     1774        global $ADODB_CACHE, $ADODB_CACHE_DIR; 
    16751775                 
    16761776                if ($this->fetchMode === false) {  
     
    16811781                } 
    16821782                $m = md5($sql.$this->databaseType.$this->database.$this->user.$mode); 
    1683                 if ($memcache) return $m; 
    1684                  
    1685                 if (!isset($notSafeMode)) $notSafeMode = !ini_get('safe_mode'); 
    1686                 $dir = ($notSafeMode) ? $ADODB_CACHE_DIR.'/'.substr($m,0,2) : $ADODB_CACHE_DIR; 
    1687                          
    1688                 if ($createdir && $notSafeMode && !file_exists($dir)) { 
    1689                         $oldu = umask(0); 
    1690                         if (!mkdir($dir,0771))  
    1691                                 if ($this->debug) ADOConnection::outp( "Unable to mkdir $dir for $sql"); 
    1692                         umask($oldu); 
    1693                 } 
     1783                if (!$ADODB_CACHE->createdir) return $m; 
     1784                if (!$createdir) $dir = $ADODB_CACHE->getdirname($m); 
     1785                else $dir = $ADODB_CACHE->createdir($m, $this->debug); 
     1786                 
    16941787                return $dir.'/adodb_'.$m.'.cache'; 
    16951788        } 
     
    17051798         * @return              RecordSet or false 
    17061799         */ 
    1707         function &CacheExecute($secs2cache,$sql=false,$inputarr=false) 
    1708         { 
    1709  
    1710                          
     1800        function CacheExecute($secs2cache,$sql=false,$inputarr=false) 
     1801        { 
     1802        global $ADODB_CACHE; 
     1803         
     1804                if (empty($ADODB_CACHE)) $this->_CreateCache(); 
     1805                 
    17111806                if (!is_numeric($secs2cache)) { 
    17121807                        $inputarr = $sql; 
     
    17211816                        $sqlparam = $sql; 
    17221817                         
    1723                 if ($this->memCache) { 
    1724                         global $ADODB_INCLUDED_MEMCACHE; 
    1725                         if (empty($ADODB_INCLUDED_MEMCACHE)) include(ADODB_DIR.'/adodb-memcache.lib.inc.php'); 
    1726                         $md5file = $this->_gencachename($sql.serialize($inputarr),false,true); 
    1727                 } else { 
    1728                 global $ADODB_INCLUDED_CSV; 
    1729                         if (empty($ADODB_INCLUDED_CSV)) include(ADODB_DIR.'/adodb-csvlib.inc.php'); 
    1730                         $md5file = $this->_gencachename($sql.serialize($inputarr),true); 
    1731                 } 
    1732  
     1818                 
     1819                $md5file = $this->_gencachename($sql.serialize($inputarr),true); 
    17331820                $err = ''; 
    17341821                 
    17351822                if ($secs2cache > 0){ 
    1736                         if ($this->memCache) 
    1737                                 $rs = &getmemCache($md5file,$err,$secs2cache, $this->memCacheHost, $this->memCachePort); 
    1738                         else 
    1739                                 $rs = &csv2rs($md5file,$err,$secs2cache,$this->arrayClass); 
     1823                        $rs = $ADODB_CACHE->readcache($md5file,$err,$secs2cache,$this->arrayClass); 
    17401824                        $this->numCacheHits += 1; 
    17411825                } else { 
     
    17441828                        $this->numCacheMisses += 1; 
    17451829                } 
     1830                 
    17461831                if (!$rs) { 
    17471832                // no cached rs found 
     
    17501835                                        ADOConnection::outp("Please disable magic_quotes_runtime - it corrupts cache files :("); 
    17511836                                } 
    1752                                 if ($this->debug !== -1) ADOConnection::outp( " $md5file cache failure: $err (see sql below)"); 
    1753                         } 
    1754                          
    1755                         $rs = &$this->Execute($sqlparam,$inputarr); 
    1756  
    1757                         if ($rs && $this->memCache) { 
    1758                                 $rs = &$this->_rs2rs($rs); // read entire recordset into memory immediately 
    1759                                 if(!putmemCache($md5file, $rs, $this->memCacheHost, $this->memCachePort, $this->memCacheCompress, $this->debug)) { 
    1760                                         if ($fn = $this->raiseErrorFn) 
    1761                                                 $fn($this->databaseType,'CacheExecute',-32000,"Cache write error",$md5file,$sql,$this); 
    1762                                         if ($this->debug) ADOConnection::outp( " Cache write error"); 
    1763                                 } 
    1764                         } else 
     1837                                if ($this->debug !== -1) ADOConnection::outp( " $md5file cache failure: $err (this is a notice and not an error)"); 
     1838                        } 
     1839                         
     1840                        $rs = $this->Execute($sqlparam,$inputarr); 
     1841 
    17651842                        if ($rs) { 
     1843 
    17661844                                $eof = $rs->EOF; 
    1767                                 $rs = &$this->_rs2rs($rs); // read entire recordset into memory immediately 
     1845                                $rs = $this->_rs2rs($rs); // read entire recordset into memory immediately 
     1846                                $rs->timeCreated = time(); // used by caching 
    17681847                                $txt = _rs2serialize($rs,false,$sql); // serialize 
    1769                  
    1770                                 if (!adodb_write_file($md5file,$txt,$this->debug)) { 
    1771                                         if ($fn = $this->raiseErrorFn) { 
    1772                                                 $fn($this->databaseType,'CacheExecute',-32000,"Cache write error",$md5file,$sql,$this); 
     1848         
     1849                                $ok = $ADODB_CACHE->writecache($md5file,$txt,$this->debug, $secs2cache); 
     1850                                if (!$ok) { 
     1851                                        if ($ok === false) { 
     1852                                                $em = 'Cache write error'; 
     1853                                                $en = -32000; 
     1854                                                 
     1855                                                if ($fn = $this->raiseErrorFn) { 
     1856                                                        $fn($this->databaseType,'CacheExecute', $en, $em, $md5file,$sql,$this); 
     1857                                                } 
     1858                                        } else { 
     1859                                                $em = 'Cache file locked warning'; 
     1860                                                $en = -32001; 
     1861                                                // do not call error handling for just a warning 
    17731862                                        } 
    1774                                         if ($this->debug) ADOConnection::outp( " Cache write error"); 
     1863                                         
     1864                                        if ($this->debug) ADOConnection::outp( " ".$em); 
    17751865                                } 
    17761866                                if ($rs->EOF && !$eof) { 
    17771867                                        $rs->MoveFirst(); 
    1778                                         //$rs = &csv2rs($md5file,$err);          
    1779                                         $rs->connection = &$this; // Pablo suggestion 
     1868                                        //$rs = csv2rs($md5file,$err);           
     1869                                        $rs->connection = $this; // Pablo suggestion 
    17801870                                }   
    17811871                                 
    1782                         } else 
    1783                         if (!$this->memCache) 
    1784                                 @unlink($md5file); 
     1872                        } else if (!$this->memCache) 
     1873                                $ADODB_CACHE->flushcache($md5file); 
    17851874                } else { 
    17861875                        $this->_errorMsg = ''; 
     
    17921881                        } 
    17931882                // ok, set cached object found 
    1794                         $rs->connection = &$this; // Pablo suggestion 
    1795                         if ($this->debug){  
    1796                                          
     1883                        $rs->connection = $this; // Pablo suggestion 
     1884                        if ($this->debug){                       
     1885                                if ($this->debug == 99) adodb_backtrace(); 
    17971886                                $inBrowser = isset($_SERVER['HTTP_USER_AGENT']); 
    17981887                                $ttl = $rs->timeCreated + $secs2cache - time(); 
     
    18141903                $forceUpdate means that even if the data has not changed, perform update. 
    18151904         */ 
    1816         function& AutoExecute($table, $fields_values, $mode = 'INSERT', $where = FALSE, $forceUpdate=true, $magicq=false)  
     1905        function AutoExecute($table, $fields_values, $mode = 'INSERT', $where = FALSE, $forceUpdate=true, $magicq=false)  
    18171906        { 
    18181907                $false = false; 
     
    18201909                if ($where!==FALSE) $sql .= ' WHERE '.$where; 
    18211910                else if ($mode == 'UPDATE' || $mode == 2 /* DB_AUTOQUERY_UPDATE */) { 
    1822                         ADOConnection::outp('AutoExecute: Illegal mode=UPDATE with empty WHERE clause'); 
     1911                        $this->outp_throw('AutoExecute: Illegal mode=UPDATE with empty WHERE clause','AutoExecute'); 
    18231912                        return $false; 
    18241913                } 
    18251914 
    1826                 $rs =& $this->SelectLimit($sql,1); 
     1915                $rs = $this->SelectLimit($sql,1); 
    18271916                if (!$rs) return $false; // table does not exist 
    18281917                $rs->tableName = $table; 
     1918                $rs->sql = $sql; 
    18291919                 
    18301920                switch((string) $mode) { 
     
    18381928                        break; 
    18391929                default: 
    1840                         ADOConnection::outp("AutoExecute: Unknown mode=$mode"); 
     1930                        $this->outp_throw("AutoExecute: Unknown mode=$mode",'AutoExecute'); 
    18411931                        return $false; 
    18421932                } 
     
    19972087                        $rsclass = $this->rsPrefix.$this->databaseType; 
    19982088                        $this->_metars = new $rsclass(false,$this->fetchMode);  
    1999                         $this->_metars->connection =& $this; 
     2089                        $this->_metars->connection = $this; 
    20002090                } 
    20012091                return $this->_metars->MetaType($t,$len,$fieldobj); 
     
    20432133        } 
    20442134 
    2045         function &GetActiveRecordsClass($class, $table,$whereOrderBy=false,$bindarr=false, $primkeyArr=false) 
     2135        /** 
     2136         * GetActiveRecordsClass Performs an 'ALL' query  
     2137         *  
     2138         * @param mixed $class This string represents the class of the current active record 
     2139         * @param mixed $table Table used by the active record object 
     2140         * @param mixed $whereOrderBy Where, order, by clauses 
     2141         * @param mixed $bindarr  
     2142         * @param mixed $primkeyArr  
     2143         * @param array $extra Query extras: limit, offset... 
     2144         * @param mixed $relations Associative array: table's foreign name, "hasMany", "belongsTo" 
     2145         * @access public 
     2146         * @return void 
     2147         */ 
     2148        function GetActiveRecordsClass( 
     2149                        $class, $table,$whereOrderBy=false,$bindarr=false, $primkeyArr=false, 
     2150                        $extra=array(), 
     2151                        $relations=array()) 
    20462152        { 
    20472153        global $_ADODB_ACTIVE_DBS; 
    2048          
    2049                 $save = $this->SetFetchMode(ADODB_FETCH_NUM); 
    2050                 if (empty($whereOrderBy)) $whereOrderBy = '1=1'; 
    2051                 $rows = $this->GetAll("select * from ".$table.' WHERE '.$whereOrderBy,$bindarr); 
    2052                 $this->SetFetchMode($save); 
    2053                  
    2054                 $false = false; 
    2055                  
    2056                 if ($rows === false) {   
    2057                         return $false; 
    2058                 } 
    2059                  
    2060                  
    2061                 if (!isset($_ADODB_ACTIVE_DBS)) { 
    2062                         include(ADODB_DIR.'/adodb-active-record.inc.php'); 
    2063                 }        
    2064                 if (!class_exists($class)) { 
    2065                         ADOConnection::outp("Unknown class $class in GetActiveRcordsClass()"); 
    2066                         return $false; 
    2067                 } 
    2068                 $arr = array(); 
    2069                 foreach($rows as $row) { 
    2070                  
    2071                         $obj = new $class($table,$primkeyArr,$this); 
    2072                         if ($obj->ErrorMsg()){ 
    2073                                 $this->_errorMsg = $obj->ErrorMsg(); 
    2074                                 return $false; 
    2075                         } 
    2076                         $obj->Set($row); 
    2077                         $arr[] = $obj; 
    2078                 } 
    2079                 return $arr; 
    2080         } 
    2081          
    2082         function &GetActiveRecords($table,$where=false,$bindarr=false,$primkeyArr=false) 
    2083         { 
    2084                 $arr =& $this->GetActiveRecordsClass('ADODB_Active_Record', $table, $where, $bindarr, $primkeyArr); 
     2154                ## reduce overhead of adodb.inc.php -- moved to adodb-active-record.inc.php 
     2155                ## if adodb-active-recordx is loaded -- should be no issue as they will probably use Find() 
     2156                if (!isset($_ADODB_ACTIVE_DBS))include_once(ADODB_DIR.'/adodb-active-record.inc.php'); 
     2157                return adodb_GetActiveRecordsClass($this, $class, $table, $whereOrderBy, $bindarr, $primkeyArr, $extra, $relations); 
     2158        } 
     2159         
     2160        function GetActiveRecords($table,$where=false,$bindarr=false,$primkeyArr=false) 
     2161        { 
     2162                $arr = $this->GetActiveRecordsClass('ADODB_Active_Record', $table, $where, $bindarr, $primkeyArr); 
    20852163                return $arr; 
    20862164        } 
     
    22052283                } 
    22062284         
     2285          /** 
     2286      * List procedures or functions in an array. 
     2287      * @param procedureNamePattern  a procedure name pattern; must match the procedure name as it is stored in the database 
     2288      * @param catalog a catalog name; must match the catalog name as it is stored in the database; 
     2289      * @param schemaPattern a schema name pattern; 
     2290      * 
     2291      * @return array of procedures on current database. 
     2292           
     2293                 Array ( 
     2294                    [name_of_procedure] => Array 
     2295                      ( 
     2296                      [type] => PROCEDURE or FUNCTION 
     2297                      [catalog] => Catalog_name 
     2298                      [schema] => Schema_name 
     2299                      [remarks] => explanatory comment on the procedure  
     2300                      ) 
     2301                 )               
     2302      */ 
     2303     function MetaProcedures($procedureNamePattern = null, $catalog  = null, $schemaPattern  = null) 
     2304     { 
     2305            return false; 
     2306     } 
     2307 
    22072308                 
    22082309        /** 
     
    22162317         * @return  array of tables for current database. 
    22172318         */  
    2218         function &MetaTables($ttype=false,$showSchema=false,$mask=false)  
     2319        function MetaTables($ttype=false,$showSchema=false,$mask=false)  
    22192320        { 
    22202321        global $ADODB_FETCH_MODE; 
     
    22362337                         
    22372338                        if ($rs === false) return $false; 
    2238                         $arr =& $rs->GetArray(); 
     2339                        $arr = $rs->GetArray(); 
    22392340                        $arr2 = array(); 
    22402341                         
     
    22782379         * @return  array of ADOFieldObjects for current table. 
    22792380         */ 
    2280         function &MetaColumns($table,$normalize=true)  
     2381        function MetaColumns($table,$normalize=true)  
    22812382        { 
    22822383        global $ADODB_FETCH_MODE; 
     
    23372438                )                
    23382439      */ 
    2339      function &MetaIndexes($table, $primary = false, $owner = false) 
     2440     function MetaIndexes($table, $primary = false, $owner = false) 
    23402441     { 
    23412442                        $false = false; 
     
    23492450         * @return  array of column names for current table. 
    23502451         */  
    2351         function &MetaColumnNames($table, $numIndexes=false,$useattnum=false /* only for postgres */)  
    2352         { 
    2353                 $objarr =& $this->MetaColumns($table); 
     2452        function MetaColumnNames($table, $numIndexes=false,$useattnum=false /* only for postgres */)  
     2453        { 
     2454                $objarr = $this->MetaColumns($table); 
    23542455                if (!is_array($objarr)) { 
    23552456                        $false = false; 
     
    23952496         * @return  date string in database date format 
    23962497         */ 
    2397         function DBDate($d) 
     2498        function DBDate($d, $isfld=false) 
    23982499        { 
    23992500                if (empty($d) && $d !== 0) return 'null'; 
    2400  
     2501                if ($isfld) return $d; 
     2502                 
     2503                if (is_object($d)) return $d->format($this->fmtDate); 
     2504                 
     2505                 
    24012506                if (is_string($d) && !is_numeric($d)) { 
    2402                         if ($d === 'null' || strncmp($d,"'",1) === 0) return $d; 
     2507                        if ($d === 'null') return $d; 
     2508                        if (strncmp($d,"'",1) === 0) { 
     2509                                $d = _adodb_safedateq($d); 
     2510                                return $d; 
     2511                        } 
    24032512                        if ($this->isoDates) return "'$d'"; 
    24042513                        $d = ADOConnection::UnixDate($d); 
     
    24322541         * @return  timestamp string in database timestamp format 
    24332542         */ 
    2434         function DBTimeStamp($ts) 
     2543        function DBTimeStamp($ts,$isfld=false) 
    24352544        { 
    24362545                if (empty($ts) && $ts !== 0) return 'null'; 
    2437  
     2546                if ($isfld) return $ts; 
     2547                if (is_object($ts)) return $ts->format($this->fmtTimeStamp); 
     2548                 
    24382549                # strlen(14) allows YYYYMMDDHHMMSS format 
    24392550                if (!is_string($ts) || (is_numeric($ts) && strlen($ts)<14))  
     
    24412552                 
    24422553                if ($ts === 'null') return $ts; 
    2443                 if ($this->isoDates && strlen($ts) !== 14) return "'$ts'"; 
    2444                  
     2554                if ($this->isoDates && strlen($ts) !== 14) { 
     2555                        $ts = _adodb_safedate($ts); 
     2556                        return "'$ts'"; 
     2557                } 
    24452558                $ts = ADOConnection::UnixTimeStamp($ts); 
    24462559                return adodb_date($this->fmtTimeStamp,$ts); 
     
    24532566         * @return date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format 
    24542567         */ 
    2455         function UnixDate($v) 
     2568        static function UnixDate($v) 
    24562569        { 
    24572570                if (is_object($v)) { 
     
    24772590         * @return date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format 
    24782591         */ 
    2479         function UnixTimeStamp($v) 
     2592        static function UnixTimeStamp($v) 
    24802593        { 
    24812594                if (is_object($v)) { 
     
    25632676                $s = str_replace('\\"','"',$s); 
    25642677                 
    2565                 if ($this->replaceQuote == "\\'")  // ' already quoted, no need to change anything 
     2678                if ($this->replaceQuote == "\\'" || ini_get('magic_quotes_sybase'))  // ' already quoted, no need to change anything 
    25662679                        return $s; 
    25672680                else {// change \' to '' for sybase/mssql 
     
    25972710                $s = str_replace('\\"','"',$s); 
    25982711                 
    2599                 if ($this->replaceQuote == "\\'")  // ' already quoted, no need to change anything 
     2712                if ($this->replaceQuote == "\\'" || ini_get('magic_quotes_sybase'))  // ' already quoted, no need to change anything 
    26002713                        return "'$s'"; 
    26012714                else {// change \' to '' for sybase/mssql 
     
    26232736        * 
    26242737        */ 
    2625         function &PageExecute($sql, $nrows, $page, $inputarr=false, $secs2cache=0)  
     2738        function PageExecute($sql, $nrows, $page, $inputarr=false, $secs2cache=0)  
    26262739        { 
    26272740                global $ADODB_INCLUDED_LIB; 
    26282741                if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php'); 
    2629                 if ($this->pageExecuteCountRows) $rs =& _adodb_pageexecute_all_rows($this, $sql, $nrows, $page, $inputarr, $secs2cache); 
    2630                 else $rs =& _adodb_pageexecute_no_last_page($this, $sql, $nrows, $page, $inputarr, $secs2cache); 
     2742                if ($this->pageExecuteCountRows) $rs = _adodb_pageexecute_all_rows($this, $sql, $nrows, $page, $inputarr, $secs2cache); 
     2743                else $rs = _adodb_pageexecute_no_last_page($this, $sql, $nrows, $page, $inputarr, $secs2cache); 
    26312744                return $rs; 
    26322745        } 
     
    26452758        * @return               the recordset ($rs->databaseType == 'array') 
    26462759        */ 
    2647         function &CachePageExecute($secs2cache, $sql, $nrows, $page,$inputarr=false)  
     2760        function CachePageExecute($secs2cache, $sql, $nrows, $page,$inputarr=false)  
    26482761        { 
    26492762                /*switch($this->dataProvider) { 
     
    26532766                default: $secs2cache = 0; break; 
    26542767                }*/ 
    2655                 $rs =& $this->PageExecute($sql,$nrows,$page,$inputarr,$secs2cache); 
     2768                $rs = $this->PageExecute($sql,$nrows,$page,$inputarr,$secs2cache); 
    26562769                return $rs; 
    26572770        } 
     
    26752788        //==============================================================================================         
    26762789         
     2790        class ADODB_Iterator_empty implements Iterator { 
     2791         
     2792            private $rs; 
     2793         
     2794            function __construct($rs)  
     2795                { 
     2796                $this->rs = $rs; 
     2797            } 
     2798            function rewind()  
     2799                { 
     2800            } 
     2801         
     2802                function valid()  
     2803                { 
     2804                return !$this->rs->EOF; 
     2805            } 
     2806                 
     2807            function key()  
     2808                { 
     2809                return false; 
     2810            } 
     2811                 
     2812            function current()  
     2813                { 
     2814                return false; 
     2815            } 
     2816                 
     2817            function next()  
     2818                { 
     2819            } 
     2820                 
     2821                function __call($func, $params) 
     2822                { 
     2823                        return call_user_func_array(array($this->rs, $func), $params); 
     2824                } 
     2825                 
     2826                function hasMore() 
     2827                { 
     2828                        return false; 
     2829                } 
     2830         
     2831        } 
     2832 
     2833         
    26772834        /** 
    26782835        * Lightweight recordset when there are no records to be returned 
    26792836        */ 
    2680         class ADORecordSet_empty 
     2837        class ADORecordSet_empty implements IteratorAggregate 
    26812838        { 
    26822839                var $dataProvider = 'empty'; 
     
    26932850                function FieldCount(){ return 0;} 
    26942851                function Init() {} 
     2852                function getIterator() {return new ADODB_Iterator_empty($this);} 
     2853                function GetAssoc() {return array();} 
    26952854        } 
    26962855         
     
    27042863        //==============================================================================================         
    27052864 
    2706         if (PHP_VERSION < 5) include_once(ADODB_DIR.'/adodb-php4.inc.php'); 
    2707         else include_once(ADODB_DIR.'/adodb-iterator.inc.php'); 
     2865        class ADODB_Iterator implements Iterator { 
     2866         
     2867            private $rs; 
     2868         
     2869            function __construct($rs)  
     2870                { 
     2871                $this->rs = $rs; 
     2872            } 
     2873            function rewind()  
     2874                { 
     2875                $this->rs->MoveFirst(); 
     2876            } 
     2877         
     2878                function valid()  
     2879                { 
     2880                return !$this->rs->EOF; 
     2881            } 
     2882                 
     2883            function key()  
     2884                { 
     2885                return $this->rs->_currentRow; 
     2886            } 
     2887                 
     2888            function current()  
     2889                { 
     2890                return $this->rs->fields; 
     2891            } 
     2892                 
     2893            function next()  
     2894                { 
     2895                $this->rs->MoveNext(); 
     2896            } 
     2897                 
     2898                function __call($func, $params) 
     2899                { 
     2900                        return call_user_func_array(array($this->rs, $func), $params); 
     2901                } 
     2902         
     2903                 
     2904                function hasMore() 
     2905                { 
     2906                        return !$this->rs->EOF; 
     2907                } 
     2908         
     2909        } 
     2910 
     2911 
     2912 
    27082913   /** 
    27092914         * RecordSet class that represents the dataset returned by the database. 
     
    27122917         * means recordcount not known). 
    27132918         */ 
    2714         class ADORecordSet extends ADODB_BASE_RS { 
     2919        class ADORecordSet implements IteratorAggregate { 
    27152920        /* 
    27162921         * public variables      
     
    27622967        } 
    27632968         
     2969        function getIterator()  
     2970        { 
     2971        return new ADODB_Iterator($this); 
     2972    } 
     2973         
     2974        /* this is experimental - i don't really know what to return... */ 
     2975        function __toString() 
     2976        { 
     2977                include_once(ADODB_DIR.'/toexport.inc.php'); 
     2978                return _adodb_export($this,',',',',false,true); 
     2979        } 
    27642980         
    27652981         
     
    28483064         * @return an array indexed by the rows (0-based) from the recordset 
    28493065         */ 
    2850         function &GetArray($nRows = -1)  
     3066        function GetArray($nRows = -1)  
    28513067        { 
    28523068        global $ADODB_EXTENSION; if ($ADODB_EXTENSION) { 
     
    28643080        } 
    28653081         
    2866         function &GetAll($nRows = -1) 
    2867         { 
    2868                 $arr =& $this->GetArray($nRows); 
     3082        function GetAll($nRows = -1) 
     3083        { 
     3084                $arr = $this->GetArray($nRows); 
    28693085                return $arr; 
    28703086        } 
     
    28883104         * @return an array indexed by the rows (0-based) from the recordset 
    28893105         */ 
    2890         function &GetArrayLimit($nrows,$offset=-1)  
     3106        function GetArrayLimit($nrows,$offset=-1)  
    28913107        {        
    28923108                if ($offset <= 0) { 
    2893                         $arr =& $this->GetArray($nrows); 
     3109                        $arr = $this->GetArray($nrows); 
    28943110                        return $arr; 
    28953111                }  
     
    29153131         * @return an array indexed by the rows (0-based) from the recordset 
    29163132         */ 
    2917         function &GetRows($nRows = -1)  
    2918         { 
    2919                 $arr =& $this->GetArray($nRows); 
     3133        function GetRows($nRows = -1)  
     3134        { 
     3135                $arr = $this->GetArray($nRows); 
    29203136                return $arr; 
    29213137        } 
     
    29373153         *      or false if the  data has less than 2 cols. 
    29383154         */ 
    2939         function &GetAssoc($force_array = false, $first2cols = false)  
     3155        function GetAssoc($force_array = false, $first2cols = false)  
    29403156        { 
    29413157        global $ADODB_EXTENSION; 
     
    29463162                        return $false; 
    29473163                } 
    2948                 $numIndex = isset($this->fields[0]); 
     3164                $numIndex = isset($this->fields[0]) && isset($this->fields[1]); 
    29493165                $results = array(); 
    29503166                 
     
    30283244                } 
    30293245                 
    3030                 $ref =& $results; # workaround accelerator incompat with PHP 4.4 :( 
     3246                $ref = $results; # workaround accelerator incompat with PHP 4.4 :( 
    30313247                return $ref;  
    30323248        } 
     
    30743290         * @return date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format 
    30753291         */ 
    3076         function UnixDate($v) 
     3292        static function UnixDate($v) 
    30773293        { 
    30783294                return ADOConnection::UnixDate($v); 
     
    30853301         * @return date in unix timestamp format, or 0 if before TIMESTAMP_FIRST_YEAR, or false if invalid date format 
    30863302         */ 
    3087         function UnixTimeStamp($v) 
     3303        static function UnixTimeStamp($v) 
    30883304        { 
    30893305                return ADOConnection::UnixTimeStamp($v); 
     
    31233339        * @return false or array containing the current record 
    31243340        */ 
    3125         function &FetchRow() 
     3341        function FetchRow() 
    31263342        { 
    31273343                if ($this->EOF) { 
     
    32873503   * $upper  0 = lowercase, 1 = uppercase, 2 = whatever is returned by FetchField 
    32883504   */ 
    3289         function &GetRowAssoc($upper=1) 
     3505        function GetRowAssoc($upper=1)  
    32903506        { 
    32913507                $record = array(); 
    3292          //     if (!$this->fields) return $record; 
    3293                  
    3294                 if (!$this->bind) { 
     3508                if (!$this->bind) { 
    32953509                        $this->GetAssocKeys($upper); 
    32963510                } 
    3297                  
    32983511                foreach($this->bind as $k => $v) { 
    3299                         $record[$k] = $this->fields[$v]; 
    3300                 } 
    3301  
     3512                        if( isset( $this->fields[$v] ) ) { 
     3513                                $record[$k] = $this->fields[$v]; 
     3514                        } else if (isset($this->fields[$k])) { 
     3515                                $record[$k] = $this->fields[$k]; 
     3516                        } else 
     3517                                $record[$k] = $this->fields[$v]; 
     3518                } 
    33023519                return $record; 
    33033520        } 
    3304          
    33053521         
    33063522        /** 
     
    33613577                        IF ($table) { 
    33623578                                if ($condition) $condition = " WHERE " . $condition;  
    3363                                 $resultrows = &$this->connection->Execute("SELECT COUNT(*) FROM $table $condition"); 
     3579                                $resultrows = $this->connection->Execute("SELECT COUNT(*) FROM $table $condition"); 
    33643580                                if ($resultrows) $lnumrows = reset($resultrows->fields); 
    33653581                        } 
     
    33953611         * @return the ADOFieldObject for that column, or false. 
    33963612         */ 
    3397         function &FetchField($fieldoffset = -1)  
     3613        function FetchField($fieldoffset = -1)  
    33983614        { 
    33993615                // must be defined by child class 
     
    34073623         * 
    34083624         */ 
    3409         function& FieldTypesArray() 
     3625        function FieldTypesArray() 
    34103626        { 
    34113627                $arr = array(); 
     
    34213637        * @return the object with the properties set to the fields of the current row 
    34223638        */ 
    3423         function &FetchObj() 
    3424         { 
    3425                 $o =& $this->FetchObject(false); 
     3639        function FetchObj() 
     3640        { 
     3641                $o = $this->FetchObject(false); 
    34263642                return $o; 
    34273643        } 
     
    34353651        * @return the object with the properties set to the fields of the current row 
    34363652        */ 
    3437         function &FetchObject($isupper=true) 
     3653        function FetchObject($isupper=true) 
    34383654        { 
    34393655                if (empty($this->_obj)) { 
     
    34683684        * Fixed bug reported by tim@orotech.net 
    34693685        */ 
    3470         function &FetchNextObj() 
    3471         { 
    3472                 $o =& $this->FetchNextObject(false); 
     3686        function FetchNextObj() 
     3687        { 
     3688                $o = $this->FetchNextObject(false); 
    34733689                return $o; 
    34743690        } 
     
    34863702        * Fixed bug reported by tim@orotech.net 
    34873703        */ 
    3488         function &FetchNextObject($isupper=true) 
     3704        function FetchNextObject($isupper=true) 
    34893705        { 
    34903706                $o = false; 
     
    35433759                'INTERVAL' => 'C',  # Postgres 
    35443760                'MACADDR' => 'C', # postgres 
     3761                'VAR_STRING' => 'C', # mysql 
    35453762                ## 
    35463763                'LONGCHAR' => 'X', 
     
    35663783                'UNIQUEIDENTIFIER' => 'C', # MS SQL Server 
    35673784                ## 
     3785                'SMALLDATETIME' => 'T', 
    35683786                'TIME' => 'T', 
    35693787                'TIMESTAMP' => 'T', 
     
    37573975                         
    37583976                        $this->_skiprow1 = false; 
    3759                         $this->_array =& $newarr; 
     3977                        $this->_array = $newarr; 
    37603978                        $this->_colnames = $hdr; 
    37613979                         
     
    38114029                function InitArrayFields(&$array,&$fieldarr) 
    38124030                { 
    3813                         $this->_array =& $array; 
     4031                        $this->_array = $array; 
    38144032                        $this->_skiprow1= false; 
    38154033                        if ($fieldarr) { 
    3816                                 $this->_fieldobjects =& $fieldarr; 
     4034                                $this->_fieldobjects = $fieldarr; 
    38174035                        }  
    38184036                        $this->Init(); 
    38194037                } 
    38204038                 
    3821                 function &GetArray($nRows=-1) 
     4039                function GetArray($nRows=-1) 
    38224040                { 
    38234041                        if ($nRows == -1 && $this->_currentRow <= 0 && !$this->_skiprow1) { 
    38244042                                return $this->_array; 
    38254043                        } else { 
    3826                                 $arr =& ADORecordSet::GetArray($nRows); 
     4044                                $arr = ADORecordSet::GetArray($nRows); 
    38274045                                return $arr; 
    38284046                        } 
     
    38444062                         
    38454063                        if ($mode & ADODB_FETCH_ASSOC) { 
    3846                                 if (!isset($this->fields[$colname])) $colname = strtolower($colname); 
     4064                                if (!isset($this->fields[$colname]) && !is_null($this->fields[$colname])) $colname = strtolower($colname); 
    38474065                                return $this->fields[$colname]; 
    38484066                        } 
     
    38574075                } 
    38584076                 
    3859                 function &FetchField($fieldOffset = -1)  
     4077                function FetchField($fieldOffset = -1)  
    38604078                { 
    38614079                        if (isset($this->_fieldobjects)) { 
     
    39724190         * synonym for ADONewConnection for people like me who cannot remember the correct name 
    39734191         */ 
    3974         function &NewADOConnection($db='') 
    3975         { 
    3976                 $tmp =& ADONewConnection($db); 
     4192        function NewADOConnection($db='') 
     4193        { 
     4194                $tmp = ADONewConnection($db); 
    39774195                return $tmp; 
    39784196        } 
     
    39864204         * @return the freshly created instance of the Connection class. 
    39874205         */ 
    3988         function &ADONewConnection($db='') 
     4206        function ADONewConnection($db='') 
    39894207        { 
    39904208        GLOBAL $ADODB_NEWCONNECTION, $ADODB_LASTDB; 
     
    39934211                $errorfn = (defined('ADODB_ERROR_HANDLER')) ? ADODB_ERROR_HANDLER : false; 
    39944212                $false = false; 
    3995                 if ($at = strpos($db,'://')) { 
     4213                if (($at = strpos($db,'://')) !== FALSE) { 
    39964214                        $origdsn = $db; 
    3997                         if (PHP_VERSION < 5) $dsna = @parse_url($db); 
    3998                         else { 
    3999                                 $fakedsn = 'fake'.substr($db,$at); 
     4215                        $fakedsn = 'fake'.substr($origdsn,$at); 
     4216                        if (($at2 = strpos($origdsn,'@/')) !== FALSE) { 
     4217                                // special handling of oracle, which might not have host 
     4218                                $fakedsn = str_replace('@/','@adodb-fakehost/',$fakedsn); 
     4219                        } 
     4220                         
     4221                         if ((strpos($origdsn, 'sqlite')) !== FALSE && stripos($origdsn, '%2F') === FALSE) { 
     4222             // special handling for SQLite, it only might have the path to the database file. 
     4223             // If you try to connect to a SQLite database using a dsn like 'sqlite:///path/to/database', the 'parse_url' php function 
     4224             // will throw you an exception with a message such as "unable to parse url" 
     4225                list($scheme, $path) = explode('://', $origdsn); 
     4226                $dsna['scheme'] = $scheme; 
     4227                                if ($qmark = strpos($path,'?')) { 
     4228                                        $dsn['query'] = substr($path,$qmark+1); 
     4229                                        $path = substr($path,0,$qmark); 
     4230                                } 
     4231                $dsna['path'] = '/' . urlencode($path); 
     4232                        } else 
    40004233                                $dsna = @parse_url($fakedsn); 
    4001                                 $dsna['scheme'] = substr($db,0,$at); 
    4002                          
    4003                                 if (strncmp($db,'pdo',3) == 0) { 
    4004                                         $sch = explode('_',$dsna['scheme']); 
    4005                                         if (sizeof($sch)>1) { 
    4006                                                 $dsna['host'] = isset($dsna['host']) ? rawurldecode($dsna['host']) : ''; 
     4234                                 
     4235                        if (!$dsna) { 
     4236                                return $false; 
     4237                        } 
     4238                        $dsna['scheme'] = substr($origdsn,0,$at); 
     4239                        if ($at2 !== FALSE) { 
     4240                                $dsna['host'] = ''; 
     4241                        } 
     4242                         
     4243                        if (strncmp($origdsn,'pdo',3) == 0) { 
     4244                                $sch = explode('_',$dsna['scheme']); 
     4245                                if (sizeof($sch)>1) { 
     4246                                 
     4247                                        $dsna['host'] = isset($dsna['host']) ? rawurldecode($dsna['host']) : ''; 
     4248                                        if ($sch[1] == 'sqlite') 
     4249                                                $dsna['host'] = rawurlencode($sch[1].':'.rawurldecode($dsna['host'])); 
     4250                                        else 
    40074251                                                $dsna['host'] = rawurlencode($sch[1].':host='.rawurldecode($dsna['host'])); 
    4008                                                 $dsna['scheme'] = 'pdo'; 
    4009                                         } 
     4252                                        $dsna['scheme'] = 'pdo'; 
    40104253                                } 
    40114254                        } 
    40124255                         
    4013                         if (!$dsna) { 
    4014                                 // special handling of oracle, which might not have host 
    4015                                 $db = str_replace('@/','@adodb-fakehost/',$db); 
    4016                                 $dsna = parse_url($db); 
    4017                                 if (!$dsna) return $false; 
    4018                                 $dsna['host'] = ''; 
    4019                         } 
    40204256                        $db = @$dsna['scheme']; 
    40214257                        if (!$db) return $false; 
     
    40454281                        $obj = $ADODB_NEWCONNECTION($db); 
    40464282 
    4047                 } else { 
     4283                }  
     4284                 
     4285                if(empty($obj)) { 
    40484286                 
    40494287                        if (!isset($ADODB_LASTDB)) $ADODB_LASTDB = ''; 
     
    41034341                                        #oci8 
    41044342                                        case 'nls_date_format': $obj->NLS_DATE_FORMAT = $v; break; 
     4343                                        case 'cachesecs': $obj->cacheSecs = $v; break; 
     4344                                        case 'memcache':  
     4345                                                $varr = explode(':',$v); 
     4346                                                $vlen = sizeof($varr); 
     4347                                                if ($vlen == 0) break;   
     4348                                                $obj->memCache = true; 
     4349                                                $obj->memCacheHost = explode(',',$varr[0]); 
     4350                                                if ($vlen == 1) break;   
     4351                                                $obj->memCachePort = $varr[1]; 
     4352                                                if ($vlen == 2) break;   
     4353                                                $obj->memCacheCompress = $varr[2] ?  true : false; 
     4354                                                break; 
    41054355                                        } 
    41064356                                } 
     
    41534403        } 
    41544404         
    4155         function &NewPerfMonitor(&$conn) 
     4405        function NewPerfMonitor(&$conn) 
    41564406        { 
    41574407                $false = false; 
     
    41674417        } 
    41684418         
    4169         function &NewDataDictionary(&$conn,$drivername=false) 
     4419        function NewDataDictionary(&$conn,$drivername=false) 
    41704420        { 
    41714421                $false = false; 
     
    41844434                $dict = new $class(); 
    41854435                $dict->dataProvider = $conn->dataProvider; 
    4186                 $dict->connection = &$conn; 
     4436                $dict->connection = $conn; 
    41874437                $dict->upperName = strtoupper($drivername); 
    41884438                $dict->quote = $conn->nameQuote; 
     
    42204470                @param levels Number of levels to display 
    42214471        */ 
    4222         function adodb_backtrace($printOrArr=true,$levels=9999) 
     4472        function adodb_backtrace($printOrArr=true,$levels=9999,$ishtml=null) 
    42234473        { 
    42244474                global $ADODB_INCLUDED_LIB; 
    42254475                if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php'); 
    4226                 return _adodb_backtrace($printOrArr,$levels); 
     4476                return _adodb_backtrace($printOrArr,$levels,0,$ishtml); 
    42274477        } 
    42284478 
Note: See TracChangeset for help on using the changeset viewer.