From: skodak Date: Sat, 7 Apr 2007 08:30:19 +0000 (+0000) Subject: MDL-8429 Upgrade ADOdb to 4.9.4 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=7e810d419ae6922f41c312049bf4a95d98c30759;p=moodle.git MDL-8429 Upgrade ADOdb to 4.9.4 --- diff --git a/lib/adodb/adodb-active-record.inc.php b/lib/adodb/adodb-active-record.inc.php index fb2395154f..35bf968edd 100644 --- a/lib/adodb/adodb-active-record.inc.php +++ b/lib/adodb/adodb-active-record.inc.php @@ -1,7 +1,7 @@ $d) { if (PHP_VERSION >= 5) { - if ($d->db == $db) return $k; + if ($d->db === $db) return $k; } else { - if ($d->db->_connectionID == $db->_connectionID && $db->database == $d->db->database) + if ($d->db->_connectionID === $db->_connectionID && $db->database == $d->db->database) return $k; } } @@ -223,7 +223,7 @@ class ADODB_Active_Record { break; default: foreach($cols as $name => $fldobj) { - $name = ($fldobj->$name); + $name = ($fldobj->name); $this->$name = null; $attr[$name] = $fldobj; } @@ -285,6 +285,15 @@ class ADODB_Active_Record { return $this->_lasterr; } + function ErrorNo() + { + if ($this->_dbat < 0) return -9999; // no database connection... + $db = $this->DB(); + + return (int) $db->ErrorNo(); + } + + // retrieve ADOConnection from _ADODB_Active_DBs function &DB() { diff --git a/lib/adodb/adodb-csvlib.inc.php b/lib/adodb/adodb-csvlib.inc.php index a031d985cc..1e34d39eef 100644 --- a/lib/adodb/adodb-csvlib.inc.php +++ b/lib/adodb/adodb-csvlib.inc.php @@ -8,7 +8,7 @@ $ADODB_INCLUDED_CSV = 1; /* - V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved. + V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved. Released under both BSD license and Lesser GPL library license. Whenever there is any discrepancy between the two licenses, the BSD license will take precedence. See License.txt. diff --git a/lib/adodb/adodb-datadict.inc.php b/lib/adodb/adodb-datadict.inc.php index edfa5a65c8..c31edd8223 100644 --- a/lib/adodb/adodb-datadict.inc.php +++ b/lib/adodb/adodb-datadict.inc.php @@ -1,7 +1,7 @@ TableName ($tabname); $sql = array(); - list($lines,$pkey) = $this->_GenFields($flds); + list($lines,$pkey,$idxs) = $this->_GenFields($flds); + // genfields can return FALSE at times + if ($lines == null) $lines = array(); $alter = 'ALTER TABLE ' . $tabname . $this->addCol . ' '; foreach($lines as $v) { $sql[] = $alter . $v; } + if (is_array($idxs)) { + foreach($idxs as $idx => $idxdef) { + $sql_idxs = $this->CreateIndexSql($idx, $tabname, $idxdef['cols'], $idxdef['opts']); + $sql = array_merge($sql, $sql_idxs); + } + } return $sql; } @@ -367,11 +375,20 @@ class ADODB_DataDict { { $tabname = $this->TableName ($tabname); $sql = array(); - list($lines,$pkey) = $this->_GenFields($flds); + list($lines,$pkey,$idxs) = $this->_GenFields($flds); + // genfields can return FALSE at times + if ($lines == null) $lines = array(); $alter = 'ALTER TABLE ' . $tabname . $this->alterCol . ' '; foreach($lines as $v) { $sql[] = $alter . $v; } + if (is_array($idxs)) { + foreach($idxs as $idx => $idxdef) { + $sql_idxs = $this->CreateIndexSql($idx, $tabname, $idxdef['cols'], $idxdef['opts']); + $sql = array_merge($sql, $sql_idxs); + } + + } return $sql; } @@ -389,7 +406,9 @@ class ADODB_DataDict { { $tabname = $this->TableName ($tabname); if ($flds) { - list($lines,$pkey) = $this->_GenFields($flds); + list($lines,$pkey,$idxs) = $this->_GenFields($flds); + // genfields can return FALSE at times + if ($lines == null) $lines = array(); list(,$first) = each($lines); list(,$column_def) = split("[\t ]+",$first,2); } @@ -429,22 +448,36 @@ class ADODB_DataDict { return array (sprintf($this->renameTable, $this->TableName($tabname),$this->TableName($newname))); } - /* + /** Generate the SQL to create table. Returns an array of sql strings. */ - function CreateTableSQL($tabname, $flds, $tableoptions=false) + function CreateTableSQL($tabname, $flds, $tableoptions=array()) { - if (!$tableoptions) $tableoptions = array(); - - list($lines,$pkey) = $this->_GenFields($flds, true); + list($lines,$pkey,$idxs) = $this->_GenFields($flds, true); + // genfields can return FALSE at times + if ($lines == null) $lines = array(); $taboptions = $this->_Options($tableoptions); $tabname = $this->TableName ($tabname); $sql = $this->_TableSQL($tabname,$lines,$pkey,$taboptions); + // ggiunta - 2006/10/12 - KLUDGE: + // if we are on autoincrement, and table options includes REPLACE, the + // autoincrement sequence has already been dropped on table creation sql, so + // we avoid passing REPLACE to trigger creation code. This prevents + // creating sql that double-drops the sequence + if ($this->autoIncrement && isset($taboptions['REPLACE'])) + unset($taboptions['REPLACE']); $tsql = $this->_Triggers($tabname,$taboptions); foreach($tsql as $s) $sql[] = $s; + if (is_array($idxs)) { + foreach($idxs as $idx => $idxdef) { + $sql_idxs = $this->CreateIndexSql($idx, $tabname, $idxdef['cols'], $idxdef['opts']); + $sql = array_merge($sql, $sql_idxs); + } + } + return $sql; } @@ -460,6 +493,9 @@ class ADODB_DataDict { $f1 = array(); foreach($f0 as $token) { switch (strtoupper($token)) { + case 'INDEX': + $f1['INDEX'] = ''; + // fall through intentionally case 'CONSTRAINT': case 'DEFAULT': $hasparam = $token; @@ -471,6 +507,20 @@ class ADODB_DataDict { break; } } + // 'index' token without a name means single column index: name it after column + if (array_key_exists('INDEX', $f1) && $f1['INDEX'] == '') { + $f1['INDEX'] = isset($f0['NAME']) ? $f0['NAME'] : $f0[0]; + // check if column name used to create an index name was quoted + if (($f1['INDEX'][0] == '"' || $f1['INDEX'][0] == "'" || $f1['INDEX'][0] == "`") && + ($f1['INDEX'][0] == substr($f1['INDEX'], -1))) { + $f1['INDEX'] = $f1['INDEX'][0].'idx_'.substr($f1['INDEX'], 1, -1).$f1['INDEX'][0]; + } + else + $f1['INDEX'] = 'idx_'.$f1['INDEX']; + } + // reset it, so we don't get next field 1st token as INDEX... + $hasparam = false; + $flds[] = $f1; } @@ -478,9 +528,10 @@ class ADODB_DataDict { $this->autoIncrement = false; $lines = array(); $pkey = array(); + $idxs = array(); foreach($flds as $fld) { $fld = _array_change_key_case($fld); - + $fname = false; $fdefault = false; $fautoinc = false; @@ -494,6 +545,8 @@ class ADODB_DataDict { $fconstraint = false; $fnotnull = false; $funsigned = false; + $findex = ''; + $funiqueindex = false; //----------------- // Parse attributes @@ -519,7 +572,8 @@ class ADODB_DataDict { case 'AUTOINCREMENT': case 'AUTO': $fautoinc = true; $fnotnull = true; break; case 'KEY': - case 'PRIMARY': $fprimary = $v; $fnotnull = true; break; + // a primary key col can be non unique in itself (if key spans many cols...) + case 'PRIMARY': $fprimary = $v; $fnotnull = true; /*$funiqueindex = true;*/ break; case 'DEF': case 'DEFAULT': $fdefault = $v; break; case 'NOTNULL': $fnotnull = $v; break; @@ -527,6 +581,9 @@ class ADODB_DataDict { case 'DEFDATE': $fdefdate = $v; break; case 'DEFTIMESTAMP': $fdefts = $v; break; case 'CONSTRAINT': $fconstraint = $v; break; + // let INDEX keyword create a 'very standard' index on column + case 'INDEX': $findex = $v; break; + case 'UNIQUE': $funiqueindex = true; break; } //switch } // foreach $fld @@ -556,6 +613,27 @@ class ADODB_DataDict { // some databases do not allow blobs to have defaults if ($ty == 'X') $fdefault = false; + // build list of indexes + if ($findex != '') { + if (array_key_exists($findex, $idxs)) { + $idxs[$findex]['cols'][] = ($fname); + if (in_array('UNIQUE', $idxs[$findex]['opts']) != $funiqueindex) { + if ($this->debug) ADOConnection::outp("Index $findex defined once UNIQUE and once not"); + } + if ($funiqueindex && !in_array('UNIQUE', $idxs[$findex]['opts'])) + $idxs[$findex]['opts'][] = 'UNIQUE'; + } + else + { + $idxs[$findex] = array(); + $idxs[$findex]['cols'] = array($fname); + if ($funiqueindex) + $idxs[$findex]['opts'] = array('UNIQUE'); + else + $idxs[$findex]['opts'] = array(); + } + } + //-------------------- // CONSTRUCT FIELD SQL if ($fdefts) { @@ -570,24 +648,47 @@ class ADODB_DataDict { } else { $fdefault = $this->connection->sysDate; } - } else if ($fdefault !== false && !$fnoquote) + } else if ($fdefault !== false && !$fnoquote) { if ($ty == 'C' or $ty == 'X' or - ( substr($fdefault,0,1) != "'" && !is_numeric($fdefault))) + ( substr($fdefault,0,1) != "'" && !is_numeric($fdefault))) { + + if (($ty == 'D' || $ty == 'T') && strtolower($fdefault) != 'null') { + // convert default date into database-aware code + if ($ty == 'T') + { + $fdefault = $this->connection->DBTimeStamp($fdefault); + } + else + { + $fdefault = $this->connection->DBDate($fdefault); + } + } + else if (strlen($fdefault) != 1 && substr($fdefault,0,1) == ' ' && substr($fdefault,strlen($fdefault)-1) == ' ') $fdefault = trim($fdefault); else if (strtolower($fdefault) != 'null') $fdefault = $this->connection->qstr($fdefault); + } + } $suffix = $this->_CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned); + // add index creation if ($widespacing) $fname = str_pad($fname,24); + + // check for field names appearing twice + if (array_key_exists($fid, $lines)) { + ADOConnection::outp("Field '$fname' defined twice"); + } + $lines[$fid] = $fname.' '.$ftype.$suffix; if ($fautoinc) $this->autoIncrement = true; } // foreach $flds - return array($lines,$pkey); + return array($lines,$pkey,$idxs); } - /* + + /** GENERATE THE SIZE PART OF THE DATATYPE $ftype is the actual type $ty is the type defined originally in the DDL @@ -680,7 +781,7 @@ class ADODB_DataDict { return $sql; } - /* + /** GENERATE TRIGGERS IF NEEDED used when table has auto-incrementing field that is emulated using triggers */ @@ -689,7 +790,7 @@ class ADODB_DataDict { return array(); } - /* + /** Sanitize options, so that array elements with no keys are promoted to keys */ function _Options($opts) @@ -703,7 +804,7 @@ class ADODB_DataDict { return $newopts; } - /* + /** "Florian Buzin [ easywe ]" This function changes/adds new fields to your table. You don't @@ -760,7 +861,9 @@ class ADODB_DataDict { // already exists, alter table instead - list($lines,$pkey) = $this->_GenFields($flds); + list($lines,$pkey,$idxs) = $this->_GenFields($flds); + // genfields can return FALSE at times + if ($lines == null) $lines = array(); $alter = 'ALTER TABLE ' . $this->TableName($tablename); $sql = array(); @@ -770,8 +873,10 @@ class ADODB_DataDict { $flds = Lens_ParseArgs($v,','); // We are trying to change the size of the field, if not allowed, simply ignore the request. - if ($flds && in_array(strtoupper(substr($flds[0][1],0,4)),$this->invalidResizeTypes4)) continue; - + if ($flds && in_array(strtoupper(substr($flds[0][1],0,4)),$this->invalidResizeTypes4)) { + echo "

$this->alterCol cannot be changed to $flds currently

"; + continue; + } $sql[] = $alter . $this->alterCol . ' ' . $v; } else { $sql[] = $alter . $this->addCol . ' ' . $v; diff --git a/lib/adodb/adodb-error.inc.php b/lib/adodb/adodb-error.inc.php index 8c959dc82c..e60976b0d8 100644 --- a/lib/adodb/adodb-error.inc.php +++ b/lib/adodb/adodb-error.inc.php @@ -1,6 +1,6 @@ name); + } else + $newarr[] = array(); + for ($y = 0; $y < $oldY; $y++) { $newarr[$x-$startx][] = $arr[$y][$x]; } @@ -560,6 +566,8 @@ function &_adodb_pageexecute_no_last_page(&$zthis, $sql, $nrows, $page, $inputar function _adodb_getupdatesql(&$zthis,&$rs, $arrFields,$forceUpdate=false,$magicq=false,$force=2) { + global $ADODB_QUOTE_FIELDNAMES; + if (!$rs) { printf(ADODB_BAD_RS,'GetUpdateSQL'); return false; @@ -606,7 +614,7 @@ function _adodb_getupdatesql(&$zthis,&$rs, $arrFields,$forceUpdate=false,$magicq $type = 'C'; } - if (strpos($upperfname,' ') !== false) + if ((strpos($upperfname,' ') !== false) || ($ADODB_QUOTE_FIELDNAMES)) $fnameq = $zthis->nameQuote.$upperfname.$zthis->nameQuote; else $fnameq = $upperfname; @@ -720,6 +728,7 @@ function _adodb_getinsertsql(&$zthis,&$rs,$arrFields,$magicq=false,$force=2) static $cacheRS = false; static $cacheSig = 0; static $cacheCols; + global $ADODB_QUOTE_FIELDNAMES; $tableName = ''; $values = ''; @@ -769,7 +778,7 @@ static $cacheCols; $upperfname = strtoupper($field->name); if (adodb_key_exists($upperfname,$arrFields,$force)) { $bad = false; - if (strpos($upperfname,' ') !== false) + if ((strpos($upperfname,' ') !== false) || ($ADODB_QUOTE_FIELDNAMES)) $fnameq = $zthis->nameQuote.$upperfname.$zthis->nameQuote; else $fnameq = $upperfname; diff --git a/lib/adodb/adodb-memcache.lib.inc.php b/lib/adodb/adodb-memcache.lib.inc.php index fc4748a36c..bc6b420bc6 100644 --- a/lib/adodb/adodb-memcache.lib.inc.php +++ b/lib/adodb/adodb-memcache.lib.inc.php @@ -1,118 +1,118 @@ -pconnect($host, $port)) { - $err = 'Can\'t connect to memcache server on: '.$host.':'.$port; - return $false; - } - - $rs = $memcache->get($key); - if (!$rs) { - $err = 'Item with such key doesn\'t exists on the memcached server.'; - return $false; - } - - $tdiff = intval($rs->timeCreated+$timeout - time()); - if ($tdiff <= 2) { - switch($tdiff) { - case 2: - if ((rand() & 15) == 0) { - $err = "Timeout 2"; - return $false; - } - break; - case 1: - if ((rand() & 3) == 0) { - $err = "Timeout 1"; - return $false; - } - break; - default: - $err = "Timeout 0"; - return $false; - } - } - return $rs; - } - - function putmemcache($key, $rs, $host, $port, $compress, $debug=false) - { - $false = false; - $true = true; - - if (!function_exists('memcache_pconnect')) { - if ($debug) ADOConnection::outp(" Memcache module PECL extension not found!
\n"); - return $false; - } - - $memcache = new Memcache; - if (!@$memcache->pconnect($host, $port)) { - if ($debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port
\n"); - return $false; - } - - $rs->timeCreated = time(); - if (!$memcache->set($key, $rs, $compress, 0)) { - if ($debug) ADOConnection::outp(" Failed to save data at the memcached server!
\n"); - return $false; - } - return $true; - } - - function flushmemcache($key=false, $host, $port, $debug=false) - { - if (!function_exists('memcache_pconnect')) { - if ($debug) ADOConnection::outp(" Memcache module PECL extension not found!
\n"); - return; - } - - $memcache = new Memcache; - if (!@$memcache->pconnect($host, $port)) { - if ($debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port
\n"); - return; - } - - if ($key) { - if (!$memcache->delete($key)) { - if ($debug) ADOConnection::outp("CacheFlush: $key entery doesn't exist on memcached server!
\n"); - } else { - if ($debug) ADOConnection::outp("CacheFlush: $key entery flushed from memcached server!
\n"); - } - } else { - if (!$memcache->flush()) { - if ($debug) ADOConnection::outp("CacheFlush: Failure flushing all enteries from memcached server!
\n"); - } else { - if ($debug) ADOConnection::outp("CacheFlush: All enteries flushed from memcached server!
\n"); - } - } - return; - } -?> +pconnect($host, $port)) { + $err = 'Can\'t connect to memcache server on: '.$host.':'.$port; + return $false; + } + + $rs = $memcache->get($key); + if (!$rs) { + $err = 'Item with such key doesn\'t exists on the memcached server.'; + return $false; + } + + $tdiff = intval($rs->timeCreated+$timeout - time()); + if ($tdiff <= 2) { + switch($tdiff) { + case 2: + if ((rand() & 15) == 0) { + $err = "Timeout 2"; + return $false; + } + break; + case 1: + if ((rand() & 3) == 0) { + $err = "Timeout 1"; + return $false; + } + break; + default: + $err = "Timeout 0"; + return $false; + } + } + return $rs; + } + + function putmemcache($key, $rs, $host, $port, $compress, $debug=false) + { + $false = false; + $true = true; + + if (!function_exists('memcache_pconnect')) { + if ($debug) ADOConnection::outp(" Memcache module PECL extension not found!
\n"); + return $false; + } + + $memcache = new Memcache; + if (!@$memcache->pconnect($host, $port)) { + if ($debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port
\n"); + return $false; + } + + $rs->timeCreated = time(); + if (!$memcache->set($key, $rs, $compress, 0)) { + if ($debug) ADOConnection::outp(" Failed to save data at the memcached server!
\n"); + return $false; + } + return $true; + } + + function flushmemcache($key=false, $host, $port, $debug=false) + { + if (!function_exists('memcache_pconnect')) { + if ($debug) ADOConnection::outp(" Memcache module PECL extension not found!
\n"); + return; + } + + $memcache = new Memcache; + if (!@$memcache->pconnect($host, $port)) { + if ($debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port
\n"); + return; + } + + if ($key) { + if (!$memcache->delete($key)) { + if ($debug) ADOConnection::outp("CacheFlush: $key entery doesn't exist on memcached server!
\n"); + } else { + if ($debug) ADOConnection::outp("CacheFlush: $key entery flushed from memcached server!
\n"); + } + } else { + if (!$memcache->flush()) { + if ($debug) ADOConnection::outp("CacheFlush: Failure flushing all enteries from memcached server!
\n"); + } else { + if ($debug) ADOConnection::outp("CacheFlush: All enteries flushed from memcached server!
\n"); + } + } + return; + } +?> diff --git a/lib/adodb/adodb-pager.inc.php b/lib/adodb/adodb-pager.inc.php index 0aa3e6a69b..22321b2eb0 100644 --- a/lib/adodb/adodb-pager.inc.php +++ b/lib/adodb/adodb-pager.inc.php @@ -1,7 +1,7 @@ fields is available on EOF - $ADODB_FETCH_MODE; // DEFAULT, NUM, ASSOC or BOTH. Default follows native driver default... + $ADODB_FETCH_MODE, // DEFAULT, NUM, ASSOC or BOTH. Default follows native driver default... + $ADODB_QUOTE_FIELDNAMES; // Allows you to force quotes (backticks) around field names in queries generated by getinsertsql and getupdatesql. //============================================================================================== // GLOBAL SETUP @@ -152,7 +153,8 @@ $ADODB_COUNTRECS, // count number of records returned - slows down query $ADODB_CACHE_DIR, // directory to cache recordsets $ADODB_FETCH_MODE, - $ADODB_FORCE_TYPE; + $ADODB_FORCE_TYPE, + $ADODB_QUOTE_FIELDNAMES; $ADODB_FETCH_MODE = ADODB_FETCH_DEFAULT; $ADODB_FORCE_TYPE = ADODB_FORCE_VALUE; @@ -174,7 +176,7 @@ /** * ADODB version as a string. */ - $ADODB_vers = 'V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved. Released BSD & LGPL.'; + $ADODB_vers = 'V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved. Released BSD & LGPL.'; /** * Determines whether recordset->RecordCount() is used. @@ -918,7 +920,7 @@ } if ($this->_queryID === true) { // return simplified recordset for inserts/updates/deletes with lower overhead - $rs =& new ADORecordSet_empty(); + $rs = new ADORecordSet_empty(); return $rs; } @@ -1363,13 +1365,13 @@ return $rv; } - function &Transpose(&$rs) + function &Transpose(&$rs,$addfieldnames=true) { $rs2 =& $this->_rs2rs($rs); $false = false; if (!$rs2) return $false; - $rs2->_transpose(); + $rs2->_transpose($addfieldnames); return $rs2; } @@ -1993,7 +1995,7 @@ if (empty($this->_metars)) { $rsclass = $this->rsPrefix.$this->databaseType; - $this->_metars =& new $rsclass(false,$this->fetchMode); + $this->_metars = new $rsclass(false,$this->fetchMode); $this->_metars->connection =& $this; } return $this->_metars->MetaType($t,$len,$fieldobj); @@ -2019,6 +2021,7 @@ $this->fmtTimeStamp = "'m-d-Y H:i:s'"; break; + case 'PT_BR': case 'NL': case 'FR': case 'RO': @@ -2065,13 +2068,13 @@ $arr = array(); foreach($rows as $row) { - $obj =& new $class($table,$primkeyArr,$this); + $obj = new $class($table,$primkeyArr,$this); if ($obj->ErrorMsg()){ $this->_errorMsg = $obj->ErrorMsg(); return $false; } $obj->Set($row); - $arr[] =& $obj; + $arr[] = $obj; } return $arr; } @@ -2097,7 +2100,11 @@ * * @return true if succeeded or false if database does not support transactions */ - function BeginTrans() {return false;} + function BeginTrans() + { + if ($this->debug) ADOConnection::outp("BeginTrans: Transactions not supported for this driver"); + return false; + } /* set transaction mode */ function SetTransactionMode( $transaction_mode ) @@ -3387,9 +3394,12 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 * * @return the ADOFieldObject for that column, or false. */ - function &FetchField($fieldoffset) + function &FetchField($fieldoffset = -1) { // must be defined by child class + + $false = false; + return $false; } /** @@ -3734,14 +3744,15 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 $this->fetchMode = $ADODB_FETCH_MODE; } - function _transpose() + function _transpose($addfieldnames=true) { global $ADODB_INCLUDED_LIB; if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php'); $hdr = true; - adodb_transpose($this->_array, $newarr, $hdr); + $fobjs = $addfieldnames ? $this->_fieldobjects : false; + adodb_transpose($this->_array, $newarr, $hdr, $fobjs); //adodb_pr($newarr); $this->_skiprow1 = false; @@ -3758,7 +3769,6 @@ http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_1 $f->type = $this->_types[$k]; $f->max_length = -1; $this->_fieldobjects[] = $f; - } $this->fields = reset($this->_array); diff --git a/lib/adodb/datadict/datadict-access.inc.php b/lib/adodb/datadict/datadict-access.inc.php index b6b5379e39..4b62eb8481 100644 --- a/lib/adodb/datadict/datadict-access.inc.php +++ b/lib/adodb/datadict/datadict-access.inc.php @@ -1,7 +1,7 @@ seqPrefix.$tabname; $trigname = $this->trigPrefix.$seqname; } + + if (strlen($seqname) > 30) { + $seqname = $this->seqPrefix.uniqid(''); + } // end if + if (strlen($trigname) > 30) { + $trigname = $this->trigPrefix.uniqid(''); + } // end if + if (isset($tableoptions['REPLACE'])) $sql[] = "DROP SEQUENCE $seqname"; $seqCache = ''; if (isset($tableoptions['SEQUENCE_CACHE'])){$seqCache = $tableoptions['SEQUENCE_CACHE'];} diff --git a/lib/adodb/datadict/datadict-postgres.inc.php b/lib/adodb/datadict/datadict-postgres.inc.php index 36c8b853d4..c56d3b6e7f 100644 --- a/lib/adodb/datadict/datadict-postgres.inc.php +++ b/lib/adodb/datadict/datadict-postgres.inc.php @@ -1,7 +1,7 @@ type; - $len = $fieldobj->max_length; - } - static $maxdb_type2adodb = array( - 'VARCHAR' => 'C', - 'CHARACTER' => 'C', - 'LONG' => 'X', // no way to differ between 'X' and 'B' :-( - 'DATE' => 'D', - 'TIMESTAMP' => 'T', - 'BOOLEAN' => 'L', - 'INTEGER' => 'I4', - 'SMALLINT' => 'I2', - 'FLOAT' => 'F', - 'FIXED' => 'N', - ); - $type = isset($maxdb_type2adodb[$t]) ? $maxdb_type2adodb[$t] : 'C'; - - // convert integer-types simulated with fixed back to integer - if ($t == 'FIXED' && !$fieldobj->scale && ($len == 20 || $len == 3)) { - $type = $len == 20 ? 'I8' : 'I1'; - } - if ($fieldobj->auto_increment) $type = 'R'; - - return $type; - } - - // return string must begin with space - function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned) - { - $suffix = ''; - if ($funsigned) $suffix .= ' UNSIGNED'; - if ($fnotnull) $suffix .= ' NOT NULL'; - if ($fautoinc) $suffix .= ' DEFAULT SERIAL'; - elseif (strlen($fdefault)) $suffix .= " DEFAULT $fdefault"; - if ($fconstraint) $suffix .= ' '.$fconstraint; - return $suffix; - } - - function AddColumnSQL($tabname, $flds) - { - $tabname = $this->TableName ($tabname); - $sql = array(); - list($lines,$pkey) = $this->_GenFields($flds); - return array( 'ALTER TABLE ' . $tabname . ' ADD (' . implode(', ',$lines) . ')' ); - } - - function AlterColumnSQL($tabname, $flds) - { - $tabname = $this->TableName ($tabname); - $sql = array(); - list($lines,$pkey) = $this->_GenFields($flds); - return array( 'ALTER TABLE ' . $tabname . ' MODIFY (' . implode(', ',$lines) . ')' ); - } - - function DropColumnSQL($tabname, $flds) - { - $tabname = $this->TableName ($tabname); - if (!is_array($flds)) $flds = explode(',',$flds); - foreach($flds as $k => $v) { - $flds[$k] = $this->NameQuote($v); - } - return array( 'ALTER TABLE ' . $tabname . ' DROP (' . implode(', ',$flds) . ')' ); - } -} - +type; + $len = $fieldobj->max_length; + } + static $maxdb_type2adodb = array( + 'VARCHAR' => 'C', + 'CHARACTER' => 'C', + 'LONG' => 'X', // no way to differ between 'X' and 'B' :-( + 'DATE' => 'D', + 'TIMESTAMP' => 'T', + 'BOOLEAN' => 'L', + 'INTEGER' => 'I4', + 'SMALLINT' => 'I2', + 'FLOAT' => 'F', + 'FIXED' => 'N', + ); + $type = isset($maxdb_type2adodb[$t]) ? $maxdb_type2adodb[$t] : 'C'; + + // convert integer-types simulated with fixed back to integer + if ($t == 'FIXED' && !$fieldobj->scale && ($len == 20 || $len == 3)) { + $type = $len == 20 ? 'I8' : 'I1'; + } + if ($fieldobj->auto_increment) $type = 'R'; + + return $type; + } + + // return string must begin with space + function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned) + { + $suffix = ''; + if ($funsigned) $suffix .= ' UNSIGNED'; + if ($fnotnull) $suffix .= ' NOT NULL'; + if ($fautoinc) $suffix .= ' DEFAULT SERIAL'; + elseif (strlen($fdefault)) $suffix .= " DEFAULT $fdefault"; + if ($fconstraint) $suffix .= ' '.$fconstraint; + return $suffix; + } + + function AddColumnSQL($tabname, $flds) + { + $tabname = $this->TableName ($tabname); + $sql = array(); + list($lines,$pkey) = $this->_GenFields($flds); + return array( 'ALTER TABLE ' . $tabname . ' ADD (' . implode(', ',$lines) . ')' ); + } + + function AlterColumnSQL($tabname, $flds) + { + $tabname = $this->TableName ($tabname); + $sql = array(); + list($lines,$pkey) = $this->_GenFields($flds); + return array( 'ALTER TABLE ' . $tabname . ' MODIFY (' . implode(', ',$lines) . ')' ); + } + + function DropColumnSQL($tabname, $flds) + { + $tabname = $this->TableName ($tabname); + if (!is_array($flds)) $flds = explode(',',$flds); + foreach($flds as $k => $v) { + $flds[$k] = $this->NameQuote($v); + } + return array( 'ALTER TABLE ' . $tabname . ' DROP (' . implode(', ',$flds) . ')' ); + } +} + ?> \ No newline at end of file diff --git a/lib/adodb/datadict/datadict-sybase.inc.php b/lib/adodb/datadict/datadict-sybase.inc.php index e9fd86f4e3..4d2150212a 100644 --- a/lib/adodb/datadict/datadict-sybase.inc.php +++ b/lib/adodb/datadict/datadict-sybase.inc.php @@ -1,7 +1,7 @@ Execute("SET TRANSACTION ".$transaction_mode); } + function qstr($s,$magic_quotes=false) + { + $s = ADOConnection::qstr($s, $magic_quotes); + return str_replace("\0", "\\\\000", $s); + } + function MetaColumns($table) { $table = strtoupper($table); diff --git a/lib/adodb/drivers/adodb-borland_ibase.inc.php b/lib/adodb/drivers/adodb-borland_ibase.inc.php index a5e748b177..ab15feff39 100644 --- a/lib/adodb/drivers/adodb-borland_ibase.inc.php +++ b/lib/adodb/drivers/adodb-borland_ibase.inc.php @@ -1,6 +1,6 @@ _appendN($sql); - return ADODB_mssql::_query($sql,$inputarr); - } - - /** - * This function will intercept all the literals used in the SQL, prepending the "N" char to them - * in order to allow mssql to store properly data sent in the correct UCS-2 encoding (by freeTDS - * and ODBTP) keeping SQL compatibility at ADOdb level (instead of hacking every project to add - * the "N" notation when working against MSSQL. - * - * Note that this hack only must be used if ALL the char-based columns in your DB are of type nchar, - * nvarchar and ntext - */ - function _appendN($sql) { - - $result = $sql; - - /// Check we have some single quote in the query. Exit ok. - if (strpos($sql, SINGLEQUOTE) === false) { - return $sql; - } - - /// Check we haven't an odd number of single quotes (this can cause problems below - /// and should be considered one wrong SQL). Exit with debug info. - if ((substr_count($sql, SINGLEQUOTE) & 1)) { - if ($this->debug) { - ADOConnection::outp("{$this->databaseType} internal transformation: not converted. Wrong number of quotes (odd)"); - } - return $sql; - } - - /// Check we haven't any backslash + single quote combination. It should mean wrong - /// backslashes use (bad magic_quotes_sybase?). Exit with debug info. - $regexp = '/(\\\\' . SINGLEQUOTE . '[^' . SINGLEQUOTE . '])/'; - if (preg_match($regexp, $sql)) { - if ($this->debug) { - ADOConnection::outp("{$this->databaseType} internal transformation: not converted. Found bad use of backslash + single quote"); - } - return $sql; - } - - /// Remove pairs of single-quotes - $pairs = array(); - $regexp = '/(' . SINGLEQUOTE . SINGLEQUOTE . ')/'; - preg_match_all($regexp, $result, $list_of_pairs); - if ($list_of_pairs) { - foreach (array_unique($list_of_pairs[0]) as $key=>$value) { - $pairs['<@#@#@PAIR-'.$key.'@#@#@>'] = $value; - } - if (!empty($pairs)) { - $result = str_replace($pairs, array_keys($pairs), $result); - } - } - - /// Remove the rest of literals present in the query - $literals = array(); - $regexp = '/(N?' . SINGLEQUOTE . '.*?' . SINGLEQUOTE . ')/is'; - preg_match_all($regexp, $result, $list_of_literals); - if ($list_of_literals) { - foreach (array_unique($list_of_literals[0]) as $key=>$value) { - $literals['<#@#@#LITERAL-'.$key.'#@#@#>'] = $value; - } - if (!empty($literals)) { - $result = str_replace($literals, array_keys($literals), $result); - } - } - - /// Analyse literals to prepend the N char to them if their contents aren't numeric - if (!empty($literals)) { - foreach ($literals as $key=>$value) { - if (!is_numeric(trim($value, SINGLEQUOTE))) { - /// Non numeric string, prepend our dear N - $literals[$key] = 'N' . trim($value, 'N'); //Trimming potentially existing previous "N" - } - } - } - - /// Re-apply literals to the text - if (!empty($literals)) { - $result = str_replace(array_keys($literals), $literals, $result); - } - - /// Re-apply pairs of single-quotes to the text - if (!empty($pairs)) { - $result = str_replace(array_keys($pairs), $pairs, $result); - } - - /// Print transformation if debug = on - if ($result != $sql && $this->debug) { - ADOConnection::outp("{$this->databaseType} internal transformation:
{$sql}
to
{$result}"); - } - - return $result; - } -} - -class ADORecordset_mssql_n extends ADORecordset_mssql { - var $databaseType = "mssql_n"; - function ADORecordset_mssql_n($id,$mode=false) - { - $this->ADORecordset_mssql($id,$mode); - } -} -?> +_appendN($sql); + return ADODB_mssql::_query($sql,$inputarr); + } + + /** + * This function will intercept all the literals used in the SQL, prepending the "N" char to them + * in order to allow mssql to store properly data sent in the correct UCS-2 encoding (by freeTDS + * and ODBTP) keeping SQL compatibility at ADOdb level (instead of hacking every project to add + * the "N" notation when working against MSSQL. + * + * Note that this hack only must be used if ALL the char-based columns in your DB are of type nchar, + * nvarchar and ntext + */ + function _appendN($sql) { + + $result = $sql; + + /// Check we have some single quote in the query. Exit ok. + if (strpos($sql, SINGLEQUOTE) === false) { + return $sql; + } + + /// Check we haven't an odd number of single quotes (this can cause problems below + /// and should be considered one wrong SQL). Exit with debug info. + if ((substr_count($sql, SINGLEQUOTE) & 1)) { + if ($this->debug) { + ADOConnection::outp("{$this->databaseType} internal transformation: not converted. Wrong number of quotes (odd)"); + } + return $sql; + } + + /// Check we haven't any backslash + single quote combination. It should mean wrong + /// backslashes use (bad magic_quotes_sybase?). Exit with debug info. + $regexp = '/(\\\\' . SINGLEQUOTE . '[^' . SINGLEQUOTE . '])/'; + if (preg_match($regexp, $sql)) { + if ($this->debug) { + ADOConnection::outp("{$this->databaseType} internal transformation: not converted. Found bad use of backslash + single quote"); + } + return $sql; + } + + /// Remove pairs of single-quotes + $pairs = array(); + $regexp = '/(' . SINGLEQUOTE . SINGLEQUOTE . ')/'; + preg_match_all($regexp, $result, $list_of_pairs); + if ($list_of_pairs) { + foreach (array_unique($list_of_pairs[0]) as $key=>$value) { + $pairs['<@#@#@PAIR-'.$key.'@#@#@>'] = $value; + } + if (!empty($pairs)) { + $result = str_replace($pairs, array_keys($pairs), $result); + } + } + + /// Remove the rest of literals present in the query + $literals = array(); + $regexp = '/(N?' . SINGLEQUOTE . '.*?' . SINGLEQUOTE . ')/is'; + preg_match_all($regexp, $result, $list_of_literals); + if ($list_of_literals) { + foreach (array_unique($list_of_literals[0]) as $key=>$value) { + $literals['<#@#@#LITERAL-'.$key.'#@#@#>'] = $value; + } + if (!empty($literals)) { + $result = str_replace($literals, array_keys($literals), $result); + } + } + + /// Analyse literals to prepend the N char to them if their contents aren't numeric + if (!empty($literals)) { + foreach ($literals as $key=>$value) { + if (!is_numeric(trim($value, SINGLEQUOTE))) { + /// Non numeric string, prepend our dear N + $literals[$key] = 'N' . trim($value, 'N'); //Trimming potentially existing previous "N" + } + } + } + + /// Re-apply literals to the text + if (!empty($literals)) { + $result = str_replace(array_keys($literals), $literals, $result); + } + + /// Re-apply pairs of single-quotes to the text + if (!empty($pairs)) { + $result = str_replace(array_keys($pairs), $pairs, $result); + } + + /// Print transformation if debug = on + if ($result != $sql && $this->debug) { + ADOConnection::outp("{$this->databaseType} internal transformation:
{$sql}
to
{$result}"); + } + + return $result; + } +} + +class ADORecordset_mssql_n extends ADORecordset_mssql { + var $databaseType = "mssql_n"; + function ADORecordset_mssql_n($id,$mode=false) + { + $this->ADORecordset_mssql($id,$mode); + } +} +?> \ No newline at end of file diff --git a/lib/adodb/drivers/adodb-mssqlpo.inc.php b/lib/adodb/drivers/adodb-mssqlpo.inc.php index 5e7ae1f404..df482860b5 100644 --- a/lib/adodb/drivers/adodb-mssqlpo.inc.php +++ b/lib/adodb/drivers/adodb-mssqlpo.inc.php @@ -1,6 +1,6 @@ _queryID, $fieldOffset); $f = @mysql_field_flags($this->_queryID,$fieldOffset); - $o->max_length = @mysql_field_len($this->_queryID,$fieldOffset); // suggested by: Jim Nicholson (jnich@att.com) + $o->max_length = @mysql_field_len($this->_queryID,$fieldOffset); // suggested by: Jim Nicholson (jnich#att.com) //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable $o->binary = (strpos($f,'binary')!== false); } else if ($fieldOffset == -1) { /* The $fieldOffset argument is not provided thus its -1 */ $o = @mysql_fetch_field($this->_queryID); - $o->max_length = @mysql_field_len($this->_queryID); // suggested by: Jim Nicholson (jnich@att.com) + $o->max_length = @mysql_field_len($this->_queryID); // suggested by: Jim Nicholson (jnich#att.com) //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable } diff --git a/lib/adodb/drivers/adodb-mysqli.inc.php b/lib/adodb/drivers/adodb-mysqli.inc.php index 415ae2bd2c..00b53ccf83 100644 --- a/lib/adodb/drivers/adodb-mysqli.inc.php +++ b/lib/adodb/drivers/adodb-mysqli.inc.php @@ -1,6 +1,6 @@ Execute($sql,$inputarr); + if ($rs) { + if (!$rs->EOF) $ret = reset($rs->fields); + $rs->Close(); + } + return $ret; + } + function ServerInfo() { $arr['description'] = $this->GetOne("select version()"); @@ -150,7 +162,9 @@ class ADODB_mysqli extends ADOConnection { { if ($this->transOff) return true; $this->transCnt += 1; - $this->Execute('SET AUTOCOMMIT=0'); + + //$this->Execute('SET AUTOCOMMIT=0'); + mysqli_autocommit($this->_connectionID, false); $this->Execute('BEGIN'); return true; } @@ -162,7 +176,9 @@ class ADODB_mysqli extends ADOConnection { if ($this->transCnt) $this->transCnt -= 1; $this->Execute('COMMIT'); - $this->Execute('SET AUTOCOMMIT=1'); + + //$this->Execute('SET AUTOCOMMIT=1'); + mysqli_autocommit($this->_connectionID, true); return true; } @@ -171,7 +187,8 @@ class ADODB_mysqli extends ADOConnection { if ($this->transOff) return true; if ($this->transCnt) $this->transCnt -= 1; $this->Execute('ROLLBACK'); - $this->Execute('SET AUTOCOMMIT=1'); + //$this->Execute('SET AUTOCOMMIT=1'); + mysqli_autocommit($this->_connectionID, true); return true; } diff --git a/lib/adodb/drivers/adodb-mysqlt.inc.php b/lib/adodb/drivers/adodb-mysqlt.inc.php index 715d6934a1..9f1b53a799 100644 --- a/lib/adodb/drivers/adodb-mysqlt.inc.php +++ b/lib/adodb/drivers/adodb-mysqlt.inc.php @@ -1,7 +1,7 @@ Connect: 1st argument should be left blank for $this->databaseType

"; if ($mode==1) { $this->_connectionID = ($this->charSet) ? - OCIPLogon($argUsername,$argPassword, $argDatabasename) + OCIPLogon($argUsername,$argPassword, $argDatabasename,$this->charSet) : - OCIPLogon($argUsername,$argPassword, $argDatabasename, $this->charSet) + OCIPLogon($argUsername,$argPassword, $argDatabasename) ; if ($this->_connectionID && $this->autoRollback) OCIrollback($this->_connectionID); } else if ($mode==2) { $this->_connectionID = ($this->charSet) ? - OCINLogon($argUsername,$argPassword, $argDatabasename) + OCINLogon($argUsername,$argPassword, $argDatabasename,$this->charSet) : - OCINLogon($argUsername,$argPassword, $argDatabasename, $this->charSet); + OCINLogon($argUsername,$argPassword, $argDatabasename); } else { $this->_connectionID = ($this->charSet) ? - OCILogon($argUsername,$argPassword, $argDatabasename) + OCILogon($argUsername,$argPassword, $argDatabasename,$this->charSet) : - OCILogon($argUsername,$argPassword, $argDatabasename,$this->charSet); + OCILogon($argUsername,$argPassword, $argDatabasename); } if (!$this->_connectionID) return false; if ($this->_initdate) { @@ -434,10 +434,10 @@ NATSOFT.DOMAIN = { if ($this->_errorMsg !== false) return $this->_errorMsg; - if (is_resource($this->_stmt)) $arr = @OCIerror($this->_stmt); + if (is_resource($this->_stmt)) $arr = @OCIError($this->_stmt); if (empty($arr)) { - $arr = @OCIerror($this->_connectionID); - if ($arr === false) $arr = @OCIError(); + if (is_resource($this->_connectionID)) $arr = @OCIError($this->_connectionID); + else $arr = @OCIError(); if ($arr === false) return ''; } $this->_errorMsg = $arr['message']; @@ -783,8 +783,17 @@ NATSOFT.DOMAIN = $stmt = OCIParse($this->_connectionID,$sql); - if (!$stmt) return false; - + if (!$stmt) { + $this->_errorMsg = false; + $this->_errorCode = false; + $arr = @OCIError($this->_connectionID); + if ($arr === false) return false; + + $this->_errorMsg = $arr['message']; + $this->_errorCode = $arr['code']; + return false; + } + $BINDNUM += 1; $sttype = @OCIStatementType($stmt); @@ -1374,10 +1383,11 @@ class ADORecordset_oci8 extends ADORecordSet { $arr =& $this->GetArray($nrows); return $arr; } + $arr = array(); for ($i=1; $i < $offset; $i++) - if (!@OCIFetch($this->_queryID)) return array(); + if (!@OCIFetch($this->_queryID)) return $arr; - if (!@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) return array(); + if (!@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) return $arr;; $results = array(); $cnt = 0; while (!$this->EOF && $nrows != $cnt) { diff --git a/lib/adodb/drivers/adodb-oci805.inc.php b/lib/adodb/drivers/adodb-oci805.inc.php index 4073b604c4..8da0ba1980 100644 --- a/lib/adodb/drivers/adodb-oci805.inc.php +++ b/lib/adodb/drivers/adodb-oci805.inc.php @@ -1,6 +1,6 @@ _connectionID = @odbtp_connect($HostOrInterface,$UserOrDSN,$argPassword,$argDatabase); - odbtp_convert_datetime($this->_connectionID,true); - + $this->_connectionID = odbtp_connect($HostOrInterface,$UserOrDSN,$argPassword,$argDatabase); if ($this->_connectionID === false) { $this->_errorMsg = $this->ErrorMsg() ; return false; } + + odbtp_convert_datetime($this->_connectionID,true); + if ($this->_dontPoolDBC) { if (function_exists('odbtp_dont_pool_dbc')) @odbtp_dont_pool_dbc($this->_connectionID); @@ -217,6 +218,7 @@ class ADODB_odbtp extends ADOConnection{ $this->replaceQuote = "'+chr(39)+'"; $this->true = '.T.'; $this->false = '.F.'; + break; case 'oracle': $this->databaseType = 'odbtp_oci8'; @@ -288,7 +290,7 @@ class ADODB_odbtp extends ADOConnection{ for ($i=0; $i < sizeof($arr); $i++) { if ($arr[$i][3] == 'SYSTEM TABLE' ) continue; if ($arr[$i][2]) - $arr2[] = $showSchema ? $arr[$i][1].'.'.$arr[$i][2] : $arr[$i][2]; + $arr2[] = $showSchema && $arr[$i][1]? $arr[$i][1].'.'.$arr[$i][2] : $arr[$i][2]; } return $arr2; } @@ -324,10 +326,11 @@ class ADODB_odbtp extends ADOConnection{ $fld->max_length = $rs->fields[6]; $fld->not_null = !empty($rs->fields[9]); $fld->scale = $rs->fields[7]; - if (!is_null($rs->fields[12])) { - $fld->has_default = true; - $fld->default_value = $rs->fields[12]; - } + if (isset($rs->fields[12])) // vfp does not have field 12 + if (!is_null($rs->fields[12])) { + $fld->has_default = true; + $fld->default_value = $rs->fields[12]; + } $retarr[strtoupper($fld->name)] = $fld; } else if (!empty($retarr)) break; @@ -547,7 +550,7 @@ class ADODB_odbtp extends ADOConnection{ return false; } } else { - $stmtid = @odbtp_query($sql,$this->_connectionID); + $stmtid = odbtp_query($sql,$this->_connectionID); } $this->_lastAffectedRows = 0; if ($stmtid) { @@ -642,6 +645,12 @@ class ADORecordSet_odbtp extends ADORecordSet { default: $this->fields = @odbtp_fetch_array($this->_queryID, $type); } + if ($this->databaseType = 'odbtp_vfp') { + if ($this->fields) + foreach($this->fields as $k => $v) { + if (strncmp($v,'1899-12-30',10) == 0) $this->fields[$k] = ''; + } + } return is_array($this->fields); } diff --git a/lib/adodb/drivers/adodb-odbtp_unicode.inc.php b/lib/adodb/drivers/adodb-odbtp_unicode.inc.php index 2a8b44db86..ff79373385 100644 --- a/lib/adodb/drivers/adodb-odbtp_unicode.inc.php +++ b/lib/adodb/drivers/adodb-odbtp_unicode.inc.php @@ -1,6 +1,6 @@ random = $d->random; $this->concat_operator = $d->concat_operator; $this->nameQuote = $d->nameQuote; - + + $this->hasGenID = $d->hasGenID; + $this->_genIDSQL = $d->_genIDSQL; + $this->_genSeqSQL = $d->_genSeqSQL; + $this->_dropSeqSQL = $d->_dropSeqSQL; + $d->_init($this); } diff --git a/lib/adodb/drivers/adodb-pdo_mssql.inc.php b/lib/adodb/drivers/adodb-pdo_mssql.inc.php index cdfcaae1ee..9470dd8f07 100644 --- a/lib/adodb/drivers/adodb-pdo_mssql.inc.php +++ b/lib/adodb/drivers/adodb-pdo_mssql.inc.php @@ -2,7 +2,7 @@ /* -V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved. +V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved. Released under both BSD license and Lesser GPL library license. Whenever there is any discrepancy between the two licenses, the BSD license will take precedence. diff --git a/lib/adodb/drivers/adodb-pdo_mysql.inc.php b/lib/adodb/drivers/adodb-pdo_mysql.inc.php index fc803b7669..b80241df04 100644 --- a/lib/adodb/drivers/adodb-pdo_mysql.inc.php +++ b/lib/adodb/drivers/adodb-pdo_mysql.inc.php @@ -2,7 +2,7 @@ /* -V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved. +V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved. Released under both BSD license and Lesser GPL library license. Whenever there is any discrepancy between the two licenses, the BSD license will take precedence. diff --git a/lib/adodb/drivers/adodb-pdo_oci.inc.php b/lib/adodb/drivers/adodb-pdo_oci.inc.php index ebfd4a3986..9d40f14ab4 100644 --- a/lib/adodb/drivers/adodb-pdo_oci.inc.php +++ b/lib/adodb/drivers/adodb-pdo_oci.inc.php @@ -2,7 +2,7 @@ /* -V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved. +V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved. Released under both BSD license and Lesser GPL library license. Whenever there is any discrepancy between the two licenses, the BSD license will take precedence. diff --git a/lib/adodb/drivers/adodb-pdo_pgsql.inc.php b/lib/adodb/drivers/adodb-pdo_pgsql.inc.php index 5c0c531a07..e802d799e2 100644 --- a/lib/adodb/drivers/adodb-pdo_pgsql.inc.php +++ b/lib/adodb/drivers/adodb-pdo_pgsql.inc.php @@ -1,7 +1,7 @@ _connectionID,$s); + $rez = pg_exec($this->_connectionID,$s); //echo $this->ErrorMsg(); } - - $rez = pg_exec($this->_connectionID,$exsql); + if ($rez) + $rez = pg_exec($this->_connectionID,$exsql); } else { //adodb_backtrace(); $rez = pg_exec($this->_connectionID,$sql); diff --git a/lib/adodb/drivers/adodb-postgres7.inc.php b/lib/adodb/drivers/adodb-postgres7.inc.php index 83b225cff0..5c3d7bb63b 100644 --- a/lib/adodb/drivers/adodb-postgres7.inc.php +++ b/lib/adodb/drivers/adodb-postgres7.inc.php @@ -1,6 +1,6 @@ databaseType,'access') !== false; - // note - vfp 6 still doesn' work even with IIF enabled || $db->databaseType == 'vfp'; - - //$hidecnt = false; - - if ($where) $where = "\nWHERE $where"; - if (!is_array($colfield)) $colarr = $db->GetCol("select distinct $colfield from $tables $where order by 1"); - if (!$aggfield) $hidecnt = false; - - $sel = "$rowfields, "; - if (is_array($colfield)) { - foreach ($colfield as $k => $v) { - $k = trim($k); - if (!$hidecnt) { - $sel .= $iif ? - "\n\t$aggfn(IIF($v,1,0)) AS \"$k\", " - : - "\n\t$aggfn(CASE WHEN $v THEN 1 ELSE 0 END) AS \"$k\", "; - } - if ($aggfield) { - $sel .= $iif ? - "\n\t$aggfn(IIF($v,$aggfield,0)) AS \"$sumlabel$k\", " - : - "\n\t$aggfn(CASE WHEN $v THEN $aggfield ELSE 0 END) AS \"$sumlabel$k\", "; - } - } - } else { - foreach ($colarr as $v) { - if (!is_numeric($v)) $vq = $db->qstr($v); - else $vq = $v; - $v = trim($v); - if (strlen($v) == 0 ) $v = 'null'; - if (!$hidecnt) { - $sel .= $iif ? - "\n\t$aggfn(IIF($colfield=$vq,1,0)) AS \"$v\", " - : - "\n\t$aggfn(CASE WHEN $colfield=$vq THEN 1 ELSE 0 END) AS \"$v\", "; - } - if ($aggfield) { - if ($hidecnt) $label = $v; - else $label = "{$v}_$aggfield"; - $sel .= $iif ? - "\n\t$aggfn(IIF($colfield=$vq,$aggfield,0)) AS \"$label\", " - : - "\n\t$aggfn(CASE WHEN $colfield=$vq THEN $aggfield ELSE 0 END) AS \"$label\", "; - } - } - } - if ($aggfield && $aggfield != '1'){ - $agg = "$aggfn($aggfield)"; - $sel .= "\n\t$agg as \"$sumlabel$aggfield\", "; - } - - if ($showcount) - $sel .= "\n\tSUM(1) as Total"; - else - $sel = substr($sel,0,strlen($sel)-2); - - - // Strip aliases - $rowfields = preg_replace('/ AS (\w+)/i', '', $rowfields); - - $sql = "SELECT $sel \nFROM $tables $where \nGROUP BY $rowfields"; - - return $sql; - } - -/* EXAMPLES USING MS NORTHWIND DATABASE */ -if (0) { - -# example1 -# -# Query the main "product" table -# Set the rows to CompanyName and QuantityPerUnit -# and the columns to the Categories -# and define the joins to link to lookup tables -# "categories" and "suppliers" -# - - $sql = PivotTableSQL( - $gDB, # adodb connection - 'products p ,categories c ,suppliers s', # tables - 'CompanyName,QuantityPerUnit', # row fields - 'CategoryName', # column fields - 'p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID' # joins/where -); - print "
$sql";
- $rs = $gDB->Execute($sql);
- rs2html($rs);
- 
-/*
-Generated SQL:
-
-SELECT CompanyName,QuantityPerUnit, 
-	SUM(CASE WHEN CategoryName='Beverages' THEN 1 ELSE 0 END) AS "Beverages", 
-	SUM(CASE WHEN CategoryName='Condiments' THEN 1 ELSE 0 END) AS "Condiments", 
-	SUM(CASE WHEN CategoryName='Confections' THEN 1 ELSE 0 END) AS "Confections", 
-	SUM(CASE WHEN CategoryName='Dairy Products' THEN 1 ELSE 0 END) AS "Dairy Products", 
-	SUM(CASE WHEN CategoryName='Grains/Cereals' THEN 1 ELSE 0 END) AS "Grains/Cereals", 
-	SUM(CASE WHEN CategoryName='Meat/Poultry' THEN 1 ELSE 0 END) AS "Meat/Poultry", 
-	SUM(CASE WHEN CategoryName='Produce' THEN 1 ELSE 0 END) AS "Produce", 
-	SUM(CASE WHEN CategoryName='Seafood' THEN 1 ELSE 0 END) AS "Seafood", 
-	SUM(1) as Total 
-FROM products p ,categories c ,suppliers s  WHERE p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID 
-GROUP BY CompanyName,QuantityPerUnit
-*/
-//=====================================================================
-
-# example2
-#
-# Query the main "product" table
-# Set the rows to CompanyName and QuantityPerUnit
-# and the columns to the UnitsInStock for diiferent ranges
-# and define the joins to link to lookup tables 
-# "categories" and "suppliers"
-#
- $sql = PivotTableSQL(
- 	$gDB,										# adodb connection
- 	'products p ,categories c ,suppliers s',	# tables
-	'CompanyName,QuantityPerUnit',				# row fields
-												# column ranges
-array(										
-' 0 ' => 'UnitsInStock <= 0',
-"1 to 5" => '0 < UnitsInStock and UnitsInStock <= 5',
-"6 to 10" => '5 < UnitsInStock and UnitsInStock <= 10',
-"11 to 15"  => '10 < UnitsInStock and UnitsInStock <= 15',
-"16+" =>'15 < UnitsInStock'
-),
-	' p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID', # joins/where
-	'UnitsInStock', 							# sum this field
-	'Sum'										# sum label prefix
-);
- print "
$sql";
- $rs = $gDB->Execute($sql);
- rs2html($rs);
- /*
- Generated SQL:
- 
-SELECT CompanyName,QuantityPerUnit, 
-	SUM(CASE WHEN UnitsInStock <= 0 THEN UnitsInStock ELSE 0 END) AS "Sum  0 ", 
-	SUM(CASE WHEN 0 < UnitsInStock and UnitsInStock <= 5 THEN UnitsInStock ELSE 0 END) AS "Sum 1 to 5", 
-	SUM(CASE WHEN 5 < UnitsInStock and UnitsInStock <= 10 THEN UnitsInStock ELSE 0 END) AS "Sum 6 to 10", 
-	SUM(CASE WHEN 10 < UnitsInStock and UnitsInStock <= 15 THEN UnitsInStock ELSE 0 END) AS "Sum 11 to 15", 
-	SUM(CASE WHEN 15 < UnitsInStock THEN UnitsInStock ELSE 0 END) AS "Sum 16+",
-	SUM(UnitsInStock) AS "Sum UnitsInStock", 
-	SUM(1) as Total 
-FROM products p ,categories c ,suppliers s  WHERE  p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID 
-GROUP BY CompanyName,QuantityPerUnit
- */
-}
+databaseType,'access') !== false; 
+		// note - vfp 6 still doesn' work even with IIF enabled || $db->databaseType == 'vfp';
+	
+	//$hidecnt = false;
+	
+ 	if ($where) $where = "\nWHERE $where";
+	if (!is_array($colfield)) $colarr = $db->GetCol("select distinct $colfield from $tables $where order by 1");
+	if (!$aggfield) $hidecnt = false;
+	
+	$sel = "$rowfields, ";
+	if (is_array($colfield)) {
+		foreach ($colfield as $k => $v) {
+			$k = trim($k);
+			if (!$hidecnt) {
+				$sel .= $iif ? 
+					"\n\t$aggfn(IIF($v,1,0)) AS \"$k\", "
+					:
+					"\n\t$aggfn(CASE WHEN $v THEN 1 ELSE 0 END) AS \"$k\", ";
+			}
+			if ($aggfield) {
+				$sel .= $iif ?
+					"\n\t$aggfn(IIF($v,$aggfield,0)) AS \"$sumlabel$k\", "
+					:
+					"\n\t$aggfn(CASE WHEN $v THEN $aggfield ELSE 0 END) AS \"$sumlabel$k\", ";
+			}
+		} 
+	} else {
+		foreach ($colarr as $v) {
+			if (!is_numeric($v)) $vq = $db->qstr($v);
+			else $vq = $v;
+			$v = trim($v);
+			if (strlen($v) == 0	) $v = 'null';
+			if (!$hidecnt) {
+				$sel .= $iif ?
+					"\n\t$aggfn(IIF($colfield=$vq,1,0)) AS \"$v\", "
+					:
+					"\n\t$aggfn(CASE WHEN $colfield=$vq THEN 1 ELSE 0 END) AS \"$v\", ";
+			}
+			if ($aggfield) {
+				if ($hidecnt) $label = $v;
+				else $label = "{$v}_$aggfield";
+				$sel .= $iif ?
+					"\n\t$aggfn(IIF($colfield=$vq,$aggfield,0)) AS \"$label\", "
+					:
+					"\n\t$aggfn(CASE WHEN $colfield=$vq THEN $aggfield ELSE 0 END) AS \"$label\", ";
+			}
+		}
+	}
+	if ($aggfield && $aggfield != '1'){
+		$agg = "$aggfn($aggfield)";
+		$sel .= "\n\t$agg as \"$sumlabel$aggfield\", ";		
+	}
+	
+	if ($showcount)
+		$sel .= "\n\tSUM(1) as Total";
+	else
+		$sel = substr($sel,0,strlen($sel)-2);
+	
+	
+	// Strip aliases
+	$rowfields = preg_replace('/ AS (\w+)/i', '', $rowfields);
+	
+	$sql = "SELECT $sel \nFROM $tables $where \nGROUP BY $rowfields";
+	
+	return $sql;
+ }
+
+/* EXAMPLES USING MS NORTHWIND DATABASE */
+if (0) {
+
+# example1
+#
+# Query the main "product" table
+# Set the rows to CompanyName and QuantityPerUnit
+# and the columns to the Categories
+# and define the joins to link to lookup tables 
+# "categories" and "suppliers"
+#
+
+ $sql = PivotTableSQL(
+ 	$gDB,  											# adodb connection
+ 	'products p ,categories c ,suppliers s',  		# tables
+	'CompanyName,QuantityPerUnit',					# row fields
+	'CategoryName',									# column fields 
+	'p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID' # joins/where
+);
+ print "
$sql";
+ $rs = $gDB->Execute($sql);
+ rs2html($rs);
+ 
+/*
+Generated SQL:
+
+SELECT CompanyName,QuantityPerUnit, 
+	SUM(CASE WHEN CategoryName='Beverages' THEN 1 ELSE 0 END) AS "Beverages", 
+	SUM(CASE WHEN CategoryName='Condiments' THEN 1 ELSE 0 END) AS "Condiments", 
+	SUM(CASE WHEN CategoryName='Confections' THEN 1 ELSE 0 END) AS "Confections", 
+	SUM(CASE WHEN CategoryName='Dairy Products' THEN 1 ELSE 0 END) AS "Dairy Products", 
+	SUM(CASE WHEN CategoryName='Grains/Cereals' THEN 1 ELSE 0 END) AS "Grains/Cereals", 
+	SUM(CASE WHEN CategoryName='Meat/Poultry' THEN 1 ELSE 0 END) AS "Meat/Poultry", 
+	SUM(CASE WHEN CategoryName='Produce' THEN 1 ELSE 0 END) AS "Produce", 
+	SUM(CASE WHEN CategoryName='Seafood' THEN 1 ELSE 0 END) AS "Seafood", 
+	SUM(1) as Total 
+FROM products p ,categories c ,suppliers s  WHERE p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID 
+GROUP BY CompanyName,QuantityPerUnit
+*/
+//=====================================================================
+
+# example2
+#
+# Query the main "product" table
+# Set the rows to CompanyName and QuantityPerUnit
+# and the columns to the UnitsInStock for diiferent ranges
+# and define the joins to link to lookup tables 
+# "categories" and "suppliers"
+#
+ $sql = PivotTableSQL(
+ 	$gDB,										# adodb connection
+ 	'products p ,categories c ,suppliers s',	# tables
+	'CompanyName,QuantityPerUnit',				# row fields
+												# column ranges
+array(										
+' 0 ' => 'UnitsInStock <= 0',
+"1 to 5" => '0 < UnitsInStock and UnitsInStock <= 5',
+"6 to 10" => '5 < UnitsInStock and UnitsInStock <= 10',
+"11 to 15"  => '10 < UnitsInStock and UnitsInStock <= 15',
+"16+" =>'15 < UnitsInStock'
+),
+	' p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID', # joins/where
+	'UnitsInStock', 							# sum this field
+	'Sum'										# sum label prefix
+);
+ print "
$sql";
+ $rs = $gDB->Execute($sql);
+ rs2html($rs);
+ /*
+ Generated SQL:
+ 
+SELECT CompanyName,QuantityPerUnit, 
+	SUM(CASE WHEN UnitsInStock <= 0 THEN UnitsInStock ELSE 0 END) AS "Sum  0 ", 
+	SUM(CASE WHEN 0 < UnitsInStock and UnitsInStock <= 5 THEN UnitsInStock ELSE 0 END) AS "Sum 1 to 5", 
+	SUM(CASE WHEN 5 < UnitsInStock and UnitsInStock <= 10 THEN UnitsInStock ELSE 0 END) AS "Sum 6 to 10", 
+	SUM(CASE WHEN 10 < UnitsInStock and UnitsInStock <= 15 THEN UnitsInStock ELSE 0 END) AS "Sum 11 to 15", 
+	SUM(CASE WHEN 15 < UnitsInStock THEN UnitsInStock ELSE 0 END) AS "Sum 16+",
+	SUM(UnitsInStock) AS "Sum UnitsInStock", 
+	SUM(1) as Total 
+FROM products p ,categories c ,suppliers s  WHERE  p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID 
+GROUP BY CompanyName,QuantityPerUnit
+ */
+}
 ?>
\ No newline at end of file
diff --git a/lib/adodb/readme_moodle.txt b/lib/adodb/readme_moodle.txt
index d9adc86e09..f4db42b3a8 100644
--- a/lib/adodb/readme_moodle.txt
+++ b/lib/adodb/readme_moodle.txt
@@ -1,4 +1,4 @@
-Description of ADODB v4.93 library import into Moodle
+Description of ADODB v4.94 library import into Moodle
 
 Removed:
  * contrib/
@@ -19,7 +19,7 @@ Our changes:
        working properly. Simplified logic (now that we are FETCH_ASSOC). Work in progress
        for the annoying http://tracker.moodle.org/browse/MDL-6877.
        Once fixed by adodb guys, we'll return to their official distro.
- * removed bogus "_connec" from first line of adodb-postgres64.inc.php
 
 skodak
-11 October 2006
+
+$Id$
diff --git a/lib/adodb/rsfilter.inc.php b/lib/adodb/rsfilter.inc.php
index b1106c0d36..29662a215e 100644
--- a/lib/adodb/rsfilter.inc.php
+++ b/lib/adodb/rsfilter.inc.php
@@ -1,61 +1,61 @@
- $v) {
-			$arr[$k] = ucwords($v);
-		}
-	}
-	$rs = RSFilter($rs,'do_ucwords');
- */
-function &RSFilter($rs,$fn)
-{
-	if ($rs->databaseType != 'array') {
-		if (!$rs->connection) return false;
-		
-		$rs = &$rs->connection->_rs2rs($rs);
-	}
-	$rows = $rs->RecordCount();
-	for ($i=0; $i < $rows; $i++) {
-		if (is_array ($fn)) {
-        	$obj = $fn[0];
-        	$method = $fn[1];
-        	$obj->$method ($rs->_array[$i],$rs);
-      } else {
-			$fn($rs->_array[$i],$rs);
-      }
-	  
-	}
-	if (!$rs->EOF) {
-		$rs->_currentRow = 0;
-		$rs->fields = $rs->_array[0];
-	}
-	
-	return $rs;
-}
+ $v) {
+			$arr[$k] = ucwords($v);
+		}
+	}
+	$rs = RSFilter($rs,'do_ucwords');
+ */
+function &RSFilter($rs,$fn)
+{
+	if ($rs->databaseType != 'array') {
+		if (!$rs->connection) return false;
+		
+		$rs = &$rs->connection->_rs2rs($rs);
+	}
+	$rows = $rs->RecordCount();
+	for ($i=0; $i < $rows; $i++) {
+		if (is_array ($fn)) {
+        	$obj = $fn[0];
+        	$method = $fn[1];
+        	$obj->$method ($rs->_array[$i],$rs);
+      } else {
+			$fn($rs->_array[$i],$rs);
+      }
+	  
+	}
+	if (!$rs->EOF) {
+		$rs->_currentRow = 0;
+		$rs->fields = $rs->_array[0];
+	}
+	
+	return $rs;
+}
 ?>
\ No newline at end of file
diff --git a/lib/adodb/session/adodb-compress-bzip2.php b/lib/adodb/session/adodb-compress-bzip2.php
index 2ecc46dd52..79c3823f7f 100644
--- a/lib/adodb/session/adodb-compress-bzip2.php
+++ b/lib/adodb/session/adodb-compress-bzip2.php
@@ -1,7 +1,7 @@
 qstr($key);
 			$rs2 =& $conn->UpdateBlob($table, 'sessdata', $val, " sesskey=$qkey", strtoupper($clob));
-			$rs = $conn->CompleteTrans();
+			$rs = @$conn->CompleteTrans();
 			
 			
 		}
diff --git a/lib/adodb/session/old/adodb-cryptsession.php b/lib/adodb/session/old/adodb-cryptsession.php
index d17f32cec2..40ce283be3 100644
--- a/lib/adodb/session/old/adodb-cryptsession.php
+++ b/lib/adodb/session/old/adodb-cryptsession.php
@@ -1,6 +1,6 @@
 ";
-	
-To force non-persistent connections, call adodb_session_open first before session_start():
-
-	include('adodb.inc.php');
-	include('adodb-session.php');
-	adodb_session_open(false,false,false);
-	session_start();
-	session_register('AVAR');
-	$_SESSION['AVAR'] += 1;
-	print "
--- \$_SESSION['AVAR']={$_SESSION['AVAR']}

"; - - - Installation - ============ - 1. Create this table in your database (syntax might vary depending on your db): - - create table sessions ( - SESSKEY char(32) not null, - EXPIRY int(11) unsigned not null, - EXPIREREF varchar(64), - DATA CLOB, - primary key (sesskey) - ); - - - 2. Then define the following parameters in this file: - $ADODB_SESSION_DRIVER='database driver, eg. mysql or ibase'; - $ADODB_SESSION_CONNECT='server to connect to'; - $ADODB_SESSION_USER ='user'; - $ADODB_SESSION_PWD ='password'; - $ADODB_SESSION_DB ='database'; - $ADODB_SESSION_TBL = 'sessions' - $ADODB_SESSION_USE_LOBS = false; (or, if you wanna use CLOBS (= 'CLOB') or ( = 'BLOB') - - 3. Recommended is PHP 4.1.0 or later. There are documented - session bugs in earlier versions of PHP. - - 4. If you want to receive notifications when a session expires, then - you can tag a session with an EXPIREREF, and before the session - record is deleted, we can call a function that will pass the EXPIREREF - as the first parameter, and the session key as the second parameter. - - To do this, define a notification function, say NotifyFn: - - function NotifyFn($expireref, $sesskey) - { - } - - Then you need to define a global variable $ADODB_SESSION_EXPIRE_NOTIFY. - This is an array with 2 elements, the first being the name of the variable - you would like to store in the EXPIREREF field, and the 2nd is the - notification function's name. - - In this example, we want to be notified when a user's session - has expired, so we store the user id in the global variable $USERID, - store this value in the EXPIREREF field: - - $ADODB_SESSION_EXPIRE_NOTIFY = array('USERID','NotifyFn'); - - Then when the NotifyFn is called, we are passed the $USERID as the first - parameter, eg. NotifyFn($userid, $sesskey). -*/ - -if (!defined('_ADODB_LAYER')) { - include (dirname(__FILE__).'/adodb.inc.php'); -} - -if (!defined('ADODB_SESSION')) { - - define('ADODB_SESSION',1); - - /* if database time and system time is difference is greater than this, then give warning */ - define('ADODB_SESSION_SYNCH_SECS',60); - -/****************************************************************************************\ - Global definitions -\****************************************************************************************/ -GLOBAL $ADODB_SESSION_CONNECT, - $ADODB_SESSION_DRIVER, - $ADODB_SESSION_USER, - $ADODB_SESSION_PWD, - $ADODB_SESSION_DB, - $ADODB_SESS_CONN, - $ADODB_SESS_LIFE, - $ADODB_SESS_DEBUG, - $ADODB_SESSION_EXPIRE_NOTIFY, - $ADODB_SESSION_CRC, - $ADODB_SESSION_USE_LOBS, - $ADODB_SESSION_TBL; - - if (!isset($ADODB_SESSION_USE_LOBS)) $ADODB_SESSION_USE_LOBS = 'CLOB'; - - $ADODB_SESS_LIFE = ini_get('session.gc_maxlifetime'); - if ($ADODB_SESS_LIFE <= 1) { - // bug in PHP 4.0.3 pl 1 -- how about other versions? - //print "

Session Error: PHP.INI setting session.gc_maxlifetimenot set: $ADODB_SESS_LIFE

"; - $ADODB_SESS_LIFE=1440; - } - $ADODB_SESSION_CRC = false; - //$ADODB_SESS_DEBUG = true; - - ////////////////////////////////// - /* SET THE FOLLOWING PARAMETERS */ - ////////////////////////////////// - - if (empty($ADODB_SESSION_DRIVER)) { - $ADODB_SESSION_DRIVER='mysql'; - $ADODB_SESSION_CONNECT='localhost'; - $ADODB_SESSION_USER ='root'; - $ADODB_SESSION_PWD =''; - $ADODB_SESSION_DB ='xphplens_2'; - } - - if (empty($ADODB_SESSION_EXPIRE_NOTIFY)) { - $ADODB_SESSION_EXPIRE_NOTIFY = false; - } - // Made table name configurable - by David Johnson djohnson@inpro.net - if (empty($ADODB_SESSION_TBL)){ - $ADODB_SESSION_TBL = 'sessions'; - } - - - // defaulting $ADODB_SESSION_USE_LOBS - if (!isset($ADODB_SESSION_USE_LOBS) || empty($ADODB_SESSION_USE_LOBS)) { - $ADODB_SESSION_USE_LOBS = false; - } - - /* - $ADODB_SESS['driver'] = $ADODB_SESSION_DRIVER; - $ADODB_SESS['connect'] = $ADODB_SESSION_CONNECT; - $ADODB_SESS['user'] = $ADODB_SESSION_USER; - $ADODB_SESS['pwd'] = $ADODB_SESSION_PWD; - $ADODB_SESS['db'] = $ADODB_SESSION_DB; - $ADODB_SESS['life'] = $ADODB_SESS_LIFE; - $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG; - - $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG; - $ADODB_SESS['table'] = $ADODB_SESS_TBL; - */ - -/****************************************************************************************\ - Create the connection to the database. - - If $ADODB_SESS_CONN already exists, reuse that connection -\****************************************************************************************/ -function adodb_sess_open($save_path, $session_name,$persist=true) -{ -GLOBAL $ADODB_SESS_CONN; - if (isset($ADODB_SESS_CONN)) return true; - -GLOBAL $ADODB_SESSION_CONNECT, - $ADODB_SESSION_DRIVER, - $ADODB_SESSION_USER, - $ADODB_SESSION_PWD, - $ADODB_SESSION_DB, - $ADODB_SESS_DEBUG; - - // cannot use & below - do not know why... - $ADODB_SESS_CONN = ADONewConnection($ADODB_SESSION_DRIVER); - if (!empty($ADODB_SESS_DEBUG)) { - $ADODB_SESS_CONN->debug = true; - ADOConnection::outp( " conn=$ADODB_SESSION_CONNECT user=$ADODB_SESSION_USER pwd=$ADODB_SESSION_PWD db=$ADODB_SESSION_DB "); - } - if ($persist) $ok = $ADODB_SESS_CONN->PConnect($ADODB_SESSION_CONNECT, - $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB); - else $ok = $ADODB_SESS_CONN->Connect($ADODB_SESSION_CONNECT, - $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB); - - if (!$ok) ADOConnection::outp( " --- Session: connection failed

",false); -} - -/****************************************************************************************\ - Close the connection -\****************************************************************************************/ -function adodb_sess_close() -{ -global $ADODB_SESS_CONN; - - if ($ADODB_SESS_CONN) $ADODB_SESS_CONN->Close(); - return true; -} - -/****************************************************************************************\ - Slurp in the session variables and return the serialized string -\****************************************************************************************/ -function adodb_sess_read($key) -{ -global $ADODB_SESS_CONN,$ADODB_SESSION_TBL,$ADODB_SESSION_CRC; - - $rs = $ADODB_SESS_CONN->Execute("SELECT data FROM $ADODB_SESSION_TBL WHERE sesskey = '$key' AND expiry >= " . time()); - if ($rs) { - if ($rs->EOF) { - $v = ''; - } else - $v = rawurldecode(reset($rs->fields)); - - $rs->Close(); - - // new optimization adodb 2.1 - $ADODB_SESSION_CRC = strlen($v).crc32($v); - - return $v; - } - - return ''; // thx to Jorma Tuomainen, webmaster#wizactive.com -} - -/****************************************************************************************\ - Write the serialized data to a database. - - If the data has not been modified since adodb_sess_read(), we do not write. -\****************************************************************************************/ -function adodb_sess_write($key, $val) -{ - global - $ADODB_SESS_CONN, - $ADODB_SESS_LIFE, - $ADODB_SESSION_TBL, - $ADODB_SESS_DEBUG, - $ADODB_SESSION_CRC, - $ADODB_SESSION_EXPIRE_NOTIFY, - $ADODB_SESSION_DRIVER, // added - $ADODB_SESSION_USE_LOBS; // added - - $expiry = time() + $ADODB_SESS_LIFE; - - // crc32 optimization since adodb 2.1 - // now we only update expiry date, thx to sebastian thom in adodb 2.32 - if ($ADODB_SESSION_CRC !== false && $ADODB_SESSION_CRC == strlen($val).crc32($val)) { - if ($ADODB_SESS_DEBUG) echo " --- Session: Only updating date - crc32 not changed

"; - $qry = "UPDATE $ADODB_SESSION_TBL SET expiry=$expiry WHERE sesskey='$key' AND expiry >= " . time(); - $rs = $ADODB_SESS_CONN->Execute($qry); - return true; - } - $val = rawurlencode($val); - - $arr = array('sesskey' => $key, 'expiry' => $expiry, 'data' => $val); - if ($ADODB_SESSION_EXPIRE_NOTIFY) { - $var = reset($ADODB_SESSION_EXPIRE_NOTIFY); - global $$var; - $arr['expireref'] = $$var; - } - - - if ($ADODB_SESSION_USE_LOBS === false) { // no lobs, simply use replace() - $rs = $ADODB_SESS_CONN->Replace($ADODB_SESSION_TBL,$arr, 'sesskey',$autoQuote = true); - if (!$rs) { - $err = $ADODB_SESS_CONN->ErrorMsg(); - } - } else { - // what value shall we insert/update for lob row? - switch ($ADODB_SESSION_DRIVER) { - // empty_clob or empty_lob for oracle dbs - case "oracle": - case "oci8": - case "oci8po": - case "oci805": - $lob_value = sprintf("empty_%s()", strtolower($ADODB_SESSION_USE_LOBS)); - break; - - // null for all other - default: - $lob_value = "null"; - break; - } - - // do we insert or update? => as for sesskey - $res = $ADODB_SESS_CONN->Execute("select count(*) as cnt from $ADODB_SESSION_TBL where sesskey = '$key'"); - if ($res && reset($res->fields) > 0) { - $qry = sprintf("update %s set expiry = %d, data = %s where sesskey = '%s'", $ADODB_SESSION_TBL, $expiry, $lob_value, $key); - } else { - // insert - $qry = sprintf("insert into %s (sesskey, expiry, data) values ('%s', %d, %s)", $ADODB_SESSION_TBL, $key, $expiry, $lob_value); - } - - $err = ""; - $rs1 = $ADODB_SESS_CONN->Execute($qry); - if (!$rs1) { - $err .= $ADODB_SESS_CONN->ErrorMsg()."\n"; - } - $rs2 = $ADODB_SESS_CONN->UpdateBlob($ADODB_SESSION_TBL, 'data', $val, "sesskey='$key'", strtoupper($ADODB_SESSION_USE_LOBS)); - if (!$rs2) { - $err .= $ADODB_SESS_CONN->ErrorMsg()."\n"; - } - $rs = ($rs1 && $rs2) ? true : false; - } - - if (!$rs) { - ADOConnection::outp( ' --- Session Replace: '.nl2br($err).'

',false); - } else { - // bug in access driver (could be odbc?) means that info is not commited - // properly unless select statement executed in Win2000 - if ($ADODB_SESS_CONN->databaseType == 'access') - $rs = $ADODB_SESS_CONN->Execute("select sesskey from $ADODB_SESSION_TBL WHERE sesskey='$key'"); - } - return !empty($rs); -} - -function adodb_sess_destroy($key) -{ - global $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY; - - if ($ADODB_SESSION_EXPIRE_NOTIFY) { - reset($ADODB_SESSION_EXPIRE_NOTIFY); - $fn = next($ADODB_SESSION_EXPIRE_NOTIFY); - $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM); - $rs = $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE sesskey='$key'"); - $ADODB_SESS_CONN->SetFetchMode($savem); - if ($rs) { - $ADODB_SESS_CONN->BeginTrans(); - while (!$rs->EOF) { - $ref = $rs->fields[0]; - $key = $rs->fields[1]; - $fn($ref,$key); - $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'"); - $rs->MoveNext(); - } - $ADODB_SESS_CONN->CommitTrans(); - } - } else { - $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE sesskey = '$key'"; - $rs = $ADODB_SESS_CONN->Execute($qry); - } - return $rs ? true : false; -} - -function adodb_sess_gc($maxlifetime) -{ - global $ADODB_SESS_DEBUG, $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY; - - if ($ADODB_SESSION_EXPIRE_NOTIFY) { - reset($ADODB_SESSION_EXPIRE_NOTIFY); - $fn = next($ADODB_SESSION_EXPIRE_NOTIFY); - $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM); - $t = time(); - $rs = $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE expiry < $t"); - $ADODB_SESS_CONN->SetFetchMode($savem); - if ($rs) { - $ADODB_SESS_CONN->BeginTrans(); - while (!$rs->EOF) { - $ref = $rs->fields[0]; - $key = $rs->fields[1]; - $fn($ref,$key); - $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'"); - $rs->MoveNext(); - } - $rs->Close(); - - //$ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE expiry < $t"); - $ADODB_SESS_CONN->CommitTrans(); - - } - } else { - $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE expiry < " . time()); - - if ($ADODB_SESS_DEBUG) ADOConnection::outp(" --- Garbage Collection: $qry

"); - } - // suggested by Cameron, "GaM3R" - if (defined('ADODB_SESSION_OPTIMIZE')) { - global $ADODB_SESSION_DRIVER; - - switch( $ADODB_SESSION_DRIVER ) { - case 'mysql': - case 'mysqlt': - $opt_qry = 'OPTIMIZE TABLE '.$ADODB_SESSION_TBL; - break; - case 'postgresql': - case 'postgresql7': - $opt_qry = 'VACUUM '.$ADODB_SESSION_TBL; - break; - } - if (!empty($opt_qry)) { - $ADODB_SESS_CONN->Execute($opt_qry); - } - } - if ($ADODB_SESS_CONN->dataProvider === 'oci8') $sql = 'select TO_CHAR('.($ADODB_SESS_CONN->sysTimeStamp).', \'RRRR-MM-DD HH24:MI:SS\') from '. $ADODB_SESSION_TBL; - else $sql = 'select '.$ADODB_SESS_CONN->sysTimeStamp.' from '. $ADODB_SESSION_TBL; - - $rs =& $ADODB_SESS_CONN->SelectLimit($sql,1); - if ($rs && !$rs->EOF) { - - $dbts = reset($rs->fields); - $rs->Close(); - $dbt = $ADODB_SESS_CONN->UnixTimeStamp($dbts); - $t = time(); - if (abs($dbt - $t) >= ADODB_SESSION_SYNCH_SECS) { - $msg = - __FILE__.": Server time for webserver {$_SERVER['HTTP_HOST']} not in synch with database: database=$dbt ($dbts), webserver=$t (diff=".(abs($dbt-$t)/3600)." hrs)"; - error_log($msg); - if ($ADODB_SESS_DEBUG) ADOConnection::outp(" --- $msg

"); - } - } - - return true; -} - -session_module_name('user'); -session_set_save_handler( - "adodb_sess_open", - "adodb_sess_close", - "adodb_sess_read", - "adodb_sess_write", - "adodb_sess_destroy", - "adodb_sess_gc"); -} - -/* TEST SCRIPT -- UNCOMMENT */ - -if (0) { - - session_start(); - session_register('AVAR'); - $_SESSION['AVAR'] += 1; - ADOConnection::outp( " --- \$_SESSION['AVAR']={$_SESSION['AVAR']}

",false); -} - -?> +"; + +To force non-persistent connections, call adodb_session_open first before session_start(): + + include('adodb.inc.php'); + include('adodb-session.php'); + adodb_session_open(false,false,false); + session_start(); + session_register('AVAR'); + $_SESSION['AVAR'] += 1; + print " +-- \$_SESSION['AVAR']={$_SESSION['AVAR']}

"; + + + Installation + ============ + 1. Create this table in your database (syntax might vary depending on your db): + + create table sessions ( + SESSKEY char(32) not null, + EXPIRY int(11) unsigned not null, + EXPIREREF varchar(64), + DATA CLOB, + primary key (sesskey) + ); + + + 2. Then define the following parameters in this file: + $ADODB_SESSION_DRIVER='database driver, eg. mysql or ibase'; + $ADODB_SESSION_CONNECT='server to connect to'; + $ADODB_SESSION_USER ='user'; + $ADODB_SESSION_PWD ='password'; + $ADODB_SESSION_DB ='database'; + $ADODB_SESSION_TBL = 'sessions' + $ADODB_SESSION_USE_LOBS = false; (or, if you wanna use CLOBS (= 'CLOB') or ( = 'BLOB') + + 3. Recommended is PHP 4.1.0 or later. There are documented + session bugs in earlier versions of PHP. + + 4. If you want to receive notifications when a session expires, then + you can tag a session with an EXPIREREF, and before the session + record is deleted, we can call a function that will pass the EXPIREREF + as the first parameter, and the session key as the second parameter. + + To do this, define a notification function, say NotifyFn: + + function NotifyFn($expireref, $sesskey) + { + } + + Then you need to define a global variable $ADODB_SESSION_EXPIRE_NOTIFY. + This is an array with 2 elements, the first being the name of the variable + you would like to store in the EXPIREREF field, and the 2nd is the + notification function's name. + + In this example, we want to be notified when a user's session + has expired, so we store the user id in the global variable $USERID, + store this value in the EXPIREREF field: + + $ADODB_SESSION_EXPIRE_NOTIFY = array('USERID','NotifyFn'); + + Then when the NotifyFn is called, we are passed the $USERID as the first + parameter, eg. NotifyFn($userid, $sesskey). +*/ + +if (!defined('_ADODB_LAYER')) { + include (dirname(__FILE__).'/adodb.inc.php'); +} + +if (!defined('ADODB_SESSION')) { + + define('ADODB_SESSION',1); + + /* if database time and system time is difference is greater than this, then give warning */ + define('ADODB_SESSION_SYNCH_SECS',60); + +/****************************************************************************************\ + Global definitions +\****************************************************************************************/ +GLOBAL $ADODB_SESSION_CONNECT, + $ADODB_SESSION_DRIVER, + $ADODB_SESSION_USER, + $ADODB_SESSION_PWD, + $ADODB_SESSION_DB, + $ADODB_SESS_CONN, + $ADODB_SESS_LIFE, + $ADODB_SESS_DEBUG, + $ADODB_SESSION_EXPIRE_NOTIFY, + $ADODB_SESSION_CRC, + $ADODB_SESSION_USE_LOBS, + $ADODB_SESSION_TBL; + + if (!isset($ADODB_SESSION_USE_LOBS)) $ADODB_SESSION_USE_LOBS = 'CLOB'; + + $ADODB_SESS_LIFE = ini_get('session.gc_maxlifetime'); + if ($ADODB_SESS_LIFE <= 1) { + // bug in PHP 4.0.3 pl 1 -- how about other versions? + //print "

Session Error: PHP.INI setting session.gc_maxlifetimenot set: $ADODB_SESS_LIFE

"; + $ADODB_SESS_LIFE=1440; + } + $ADODB_SESSION_CRC = false; + //$ADODB_SESS_DEBUG = true; + + ////////////////////////////////// + /* SET THE FOLLOWING PARAMETERS */ + ////////////////////////////////// + + if (empty($ADODB_SESSION_DRIVER)) { + $ADODB_SESSION_DRIVER='mysql'; + $ADODB_SESSION_CONNECT='localhost'; + $ADODB_SESSION_USER ='root'; + $ADODB_SESSION_PWD =''; + $ADODB_SESSION_DB ='xphplens_2'; + } + + if (empty($ADODB_SESSION_EXPIRE_NOTIFY)) { + $ADODB_SESSION_EXPIRE_NOTIFY = false; + } + // Made table name configurable - by David Johnson djohnson@inpro.net + if (empty($ADODB_SESSION_TBL)){ + $ADODB_SESSION_TBL = 'sessions'; + } + + + // defaulting $ADODB_SESSION_USE_LOBS + if (!isset($ADODB_SESSION_USE_LOBS) || empty($ADODB_SESSION_USE_LOBS)) { + $ADODB_SESSION_USE_LOBS = false; + } + + /* + $ADODB_SESS['driver'] = $ADODB_SESSION_DRIVER; + $ADODB_SESS['connect'] = $ADODB_SESSION_CONNECT; + $ADODB_SESS['user'] = $ADODB_SESSION_USER; + $ADODB_SESS['pwd'] = $ADODB_SESSION_PWD; + $ADODB_SESS['db'] = $ADODB_SESSION_DB; + $ADODB_SESS['life'] = $ADODB_SESS_LIFE; + $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG; + + $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG; + $ADODB_SESS['table'] = $ADODB_SESS_TBL; + */ + +/****************************************************************************************\ + Create the connection to the database. + + If $ADODB_SESS_CONN already exists, reuse that connection +\****************************************************************************************/ +function adodb_sess_open($save_path, $session_name,$persist=true) +{ +GLOBAL $ADODB_SESS_CONN; + if (isset($ADODB_SESS_CONN)) return true; + +GLOBAL $ADODB_SESSION_CONNECT, + $ADODB_SESSION_DRIVER, + $ADODB_SESSION_USER, + $ADODB_SESSION_PWD, + $ADODB_SESSION_DB, + $ADODB_SESS_DEBUG; + + // cannot use & below - do not know why... + $ADODB_SESS_CONN = ADONewConnection($ADODB_SESSION_DRIVER); + if (!empty($ADODB_SESS_DEBUG)) { + $ADODB_SESS_CONN->debug = true; + ADOConnection::outp( " conn=$ADODB_SESSION_CONNECT user=$ADODB_SESSION_USER pwd=$ADODB_SESSION_PWD db=$ADODB_SESSION_DB "); + } + if ($persist) $ok = $ADODB_SESS_CONN->PConnect($ADODB_SESSION_CONNECT, + $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB); + else $ok = $ADODB_SESS_CONN->Connect($ADODB_SESSION_CONNECT, + $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB); + + if (!$ok) ADOConnection::outp( " +-- Session: connection failed

",false); +} + +/****************************************************************************************\ + Close the connection +\****************************************************************************************/ +function adodb_sess_close() +{ +global $ADODB_SESS_CONN; + + if ($ADODB_SESS_CONN) $ADODB_SESS_CONN->Close(); + return true; +} + +/****************************************************************************************\ + Slurp in the session variables and return the serialized string +\****************************************************************************************/ +function adodb_sess_read($key) +{ +global $ADODB_SESS_CONN,$ADODB_SESSION_TBL,$ADODB_SESSION_CRC; + + $rs = $ADODB_SESS_CONN->Execute("SELECT data FROM $ADODB_SESSION_TBL WHERE sesskey = '$key' AND expiry >= " . time()); + if ($rs) { + if ($rs->EOF) { + $v = ''; + } else + $v = rawurldecode(reset($rs->fields)); + + $rs->Close(); + + // new optimization adodb 2.1 + $ADODB_SESSION_CRC = strlen($v).crc32($v); + + return $v; + } + + return ''; // thx to Jorma Tuomainen, webmaster#wizactive.com +} + +/****************************************************************************************\ + Write the serialized data to a database. + + If the data has not been modified since adodb_sess_read(), we do not write. +\****************************************************************************************/ +function adodb_sess_write($key, $val) +{ + global + $ADODB_SESS_CONN, + $ADODB_SESS_LIFE, + $ADODB_SESSION_TBL, + $ADODB_SESS_DEBUG, + $ADODB_SESSION_CRC, + $ADODB_SESSION_EXPIRE_NOTIFY, + $ADODB_SESSION_DRIVER, // added + $ADODB_SESSION_USE_LOBS; // added + + $expiry = time() + $ADODB_SESS_LIFE; + + // crc32 optimization since adodb 2.1 + // now we only update expiry date, thx to sebastian thom in adodb 2.32 + if ($ADODB_SESSION_CRC !== false && $ADODB_SESSION_CRC == strlen($val).crc32($val)) { + if ($ADODB_SESS_DEBUG) echo " +-- Session: Only updating date - crc32 not changed

"; + $qry = "UPDATE $ADODB_SESSION_TBL SET expiry=$expiry WHERE sesskey='$key' AND expiry >= " . time(); + $rs = $ADODB_SESS_CONN->Execute($qry); + return true; + } + $val = rawurlencode($val); + + $arr = array('sesskey' => $key, 'expiry' => $expiry, 'data' => $val); + if ($ADODB_SESSION_EXPIRE_NOTIFY) { + $var = reset($ADODB_SESSION_EXPIRE_NOTIFY); + global $$var; + $arr['expireref'] = $$var; + } + + + if ($ADODB_SESSION_USE_LOBS === false) { // no lobs, simply use replace() + $rs = $ADODB_SESS_CONN->Replace($ADODB_SESSION_TBL,$arr, 'sesskey',$autoQuote = true); + if (!$rs) { + $err = $ADODB_SESS_CONN->ErrorMsg(); + } + } else { + // what value shall we insert/update for lob row? + switch ($ADODB_SESSION_DRIVER) { + // empty_clob or empty_lob for oracle dbs + case "oracle": + case "oci8": + case "oci8po": + case "oci805": + $lob_value = sprintf("empty_%s()", strtolower($ADODB_SESSION_USE_LOBS)); + break; + + // null for all other + default: + $lob_value = "null"; + break; + } + + // do we insert or update? => as for sesskey + $res = $ADODB_SESS_CONN->Execute("select count(*) as cnt from $ADODB_SESSION_TBL where sesskey = '$key'"); + if ($res && reset($res->fields) > 0) { + $qry = sprintf("update %s set expiry = %d, data = %s where sesskey = '%s'", $ADODB_SESSION_TBL, $expiry, $lob_value, $key); + } else { + // insert + $qry = sprintf("insert into %s (sesskey, expiry, data) values ('%s', %d, %s)", $ADODB_SESSION_TBL, $key, $expiry, $lob_value); + } + + $err = ""; + $rs1 = $ADODB_SESS_CONN->Execute($qry); + if (!$rs1) { + $err .= $ADODB_SESS_CONN->ErrorMsg()."\n"; + } + $rs2 = $ADODB_SESS_CONN->UpdateBlob($ADODB_SESSION_TBL, 'data', $val, "sesskey='$key'", strtoupper($ADODB_SESSION_USE_LOBS)); + if (!$rs2) { + $err .= $ADODB_SESS_CONN->ErrorMsg()."\n"; + } + $rs = ($rs1 && $rs2) ? true : false; + } + + if (!$rs) { + ADOConnection::outp( ' +-- Session Replace: '.nl2br($err).'

',false); + } else { + // bug in access driver (could be odbc?) means that info is not commited + // properly unless select statement executed in Win2000 + if ($ADODB_SESS_CONN->databaseType == 'access') + $rs = $ADODB_SESS_CONN->Execute("select sesskey from $ADODB_SESSION_TBL WHERE sesskey='$key'"); + } + return !empty($rs); +} + +function adodb_sess_destroy($key) +{ + global $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY; + + if ($ADODB_SESSION_EXPIRE_NOTIFY) { + reset($ADODB_SESSION_EXPIRE_NOTIFY); + $fn = next($ADODB_SESSION_EXPIRE_NOTIFY); + $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM); + $rs = $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE sesskey='$key'"); + $ADODB_SESS_CONN->SetFetchMode($savem); + if ($rs) { + $ADODB_SESS_CONN->BeginTrans(); + while (!$rs->EOF) { + $ref = $rs->fields[0]; + $key = $rs->fields[1]; + $fn($ref,$key); + $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'"); + $rs->MoveNext(); + } + $ADODB_SESS_CONN->CommitTrans(); + } + } else { + $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE sesskey = '$key'"; + $rs = $ADODB_SESS_CONN->Execute($qry); + } + return $rs ? true : false; +} + +function adodb_sess_gc($maxlifetime) +{ + global $ADODB_SESS_DEBUG, $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY; + + if ($ADODB_SESSION_EXPIRE_NOTIFY) { + reset($ADODB_SESSION_EXPIRE_NOTIFY); + $fn = next($ADODB_SESSION_EXPIRE_NOTIFY); + $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM); + $t = time(); + $rs = $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE expiry < $t"); + $ADODB_SESS_CONN->SetFetchMode($savem); + if ($rs) { + $ADODB_SESS_CONN->BeginTrans(); + while (!$rs->EOF) { + $ref = $rs->fields[0]; + $key = $rs->fields[1]; + $fn($ref,$key); + $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'"); + $rs->MoveNext(); + } + $rs->Close(); + + //$ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE expiry < $t"); + $ADODB_SESS_CONN->CommitTrans(); + + } + } else { + $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE expiry < " . time()); + + if ($ADODB_SESS_DEBUG) ADOConnection::outp(" +-- Garbage Collection: $qry

"); + } + // suggested by Cameron, "GaM3R" + if (defined('ADODB_SESSION_OPTIMIZE')) { + global $ADODB_SESSION_DRIVER; + + switch( $ADODB_SESSION_DRIVER ) { + case 'mysql': + case 'mysqlt': + $opt_qry = 'OPTIMIZE TABLE '.$ADODB_SESSION_TBL; + break; + case 'postgresql': + case 'postgresql7': + $opt_qry = 'VACUUM '.$ADODB_SESSION_TBL; + break; + } + if (!empty($opt_qry)) { + $ADODB_SESS_CONN->Execute($opt_qry); + } + } + if ($ADODB_SESS_CONN->dataProvider === 'oci8') $sql = 'select TO_CHAR('.($ADODB_SESS_CONN->sysTimeStamp).', \'RRRR-MM-DD HH24:MI:SS\') from '. $ADODB_SESSION_TBL; + else $sql = 'select '.$ADODB_SESS_CONN->sysTimeStamp.' from '. $ADODB_SESSION_TBL; + + $rs =& $ADODB_SESS_CONN->SelectLimit($sql,1); + if ($rs && !$rs->EOF) { + + $dbts = reset($rs->fields); + $rs->Close(); + $dbt = $ADODB_SESS_CONN->UnixTimeStamp($dbts); + $t = time(); + if (abs($dbt - $t) >= ADODB_SESSION_SYNCH_SECS) { + $msg = + __FILE__.": Server time for webserver {$_SERVER['HTTP_HOST']} not in synch with database: database=$dbt ($dbts), webserver=$t (diff=".(abs($dbt-$t)/3600)." hrs)"; + error_log($msg); + if ($ADODB_SESS_DEBUG) ADOConnection::outp(" +-- $msg

"); + } + } + + return true; +} + +session_module_name('user'); +session_set_save_handler( + "adodb_sess_open", + "adodb_sess_close", + "adodb_sess_read", + "adodb_sess_write", + "adodb_sess_destroy", + "adodb_sess_gc"); +} + +/* TEST SCRIPT -- UNCOMMENT */ + +if (0) { + + session_start(); + session_register('AVAR'); + $_SESSION['AVAR'] += 1; + ADOConnection::outp( " +-- \$_SESSION['AVAR']={$_SESSION['AVAR']}

",false); +} + +?> diff --git a/lib/adodb/session/old/adodb-session.php b/lib/adodb/session/old/adodb-session.php index c4183dee94..6fc9b2fe05 100644 --- a/lib/adodb/session/old/adodb-session.php +++ b/lib/adodb/session/old/adodb-session.php @@ -1,439 +1,439 @@ -"; - -To force non-persistent connections, call adodb_session_open first before session_start(): - - include('adodb.inc.php'); - include('adodb-session.php'); - adodb_sess_open(false,false,false); - session_start(); - session_register('AVAR'); - $_SESSION['AVAR'] += 1; - print " --- \$_SESSION['AVAR']={$_SESSION['AVAR']}

"; - - - Installation - ============ - 1. Create this table in your database (syntax might vary depending on your db): - - create table sessions ( - SESSKEY char(32) not null, - EXPIRY int(11) unsigned not null, - EXPIREREF varchar(64), - DATA text not null, - primary key (sesskey) - ); - - For oracle: - create table sessions ( - SESSKEY char(32) not null, - EXPIRY DECIMAL(16) not null, - EXPIREREF varchar(64), - DATA varchar(4000) not null, - primary key (sesskey) - ); - - - 2. Then define the following parameters. You can either modify - this file, or define them before this file is included: - - $ADODB_SESSION_DRIVER='database driver, eg. mysql or ibase'; - $ADODB_SESSION_CONNECT='server to connect to'; - $ADODB_SESSION_USER ='user'; - $ADODB_SESSION_PWD ='password'; - $ADODB_SESSION_DB ='database'; - $ADODB_SESSION_TBL = 'sessions' - - 3. Recommended is PHP 4.1.0 or later. There are documented - session bugs in earlier versions of PHP. - - 4. If you want to receive notifications when a session expires, then - you can tag a session with an EXPIREREF, and before the session - record is deleted, we can call a function that will pass the EXPIREREF - as the first parameter, and the session key as the second parameter. - - To do this, define a notification function, say NotifyFn: - - function NotifyFn($expireref, $sesskey) - { - } - - Then you need to define a global variable $ADODB_SESSION_EXPIRE_NOTIFY. - This is an array with 2 elements, the first being the name of the variable - you would like to store in the EXPIREREF field, and the 2nd is the - notification function's name. - - In this example, we want to be notified when a user's session - has expired, so we store the user id in the global variable $USERID, - store this value in the EXPIREREF field: - - $ADODB_SESSION_EXPIRE_NOTIFY = array('USERID','NotifyFn'); - - Then when the NotifyFn is called, we are passed the $USERID as the first - parameter, eg. NotifyFn($userid, $sesskey). -*/ - -if (!defined('_ADODB_LAYER')) { - include (dirname(__FILE__).'/adodb.inc.php'); -} - -if (!defined('ADODB_SESSION')) { - - define('ADODB_SESSION',1); - - /* if database time and system time is difference is greater than this, then give warning */ - define('ADODB_SESSION_SYNCH_SECS',60); - - /* - Thanks Joe Li. See http://phplens.com/lens/lensforum/msgs.php?id=11487&x=1 -*/ -function adodb_session_regenerate_id() -{ - $conn =& ADODB_Session::_conn(); - if (!$conn) return false; - - $old_id = session_id(); - if (function_exists('session_regenerate_id')) { - session_regenerate_id(); - } else { - session_id(md5(uniqid(rand(), true))); - $ck = session_get_cookie_params(); - setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']); - //@session_start(); - } - $new_id = session_id(); - $ok =& $conn->Execute('UPDATE '. ADODB_Session::table(). ' SET sesskey='. $conn->qstr($new_id). ' WHERE sesskey='.$conn->qstr($old_id)); - - /* it is possible that the update statement fails due to a collision */ - if (!$ok) { - session_id($old_id); - if (empty($ck)) $ck = session_get_cookie_params(); - setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']); - return false; - } - - return true; -} - -/****************************************************************************************\ - Global definitions -\****************************************************************************************/ -GLOBAL $ADODB_SESSION_CONNECT, - $ADODB_SESSION_DRIVER, - $ADODB_SESSION_USER, - $ADODB_SESSION_PWD, - $ADODB_SESSION_DB, - $ADODB_SESS_CONN, - $ADODB_SESS_LIFE, - $ADODB_SESS_DEBUG, - $ADODB_SESSION_EXPIRE_NOTIFY, - $ADODB_SESSION_CRC, - $ADODB_SESSION_TBL; - - - $ADODB_SESS_LIFE = ini_get('session.gc_maxlifetime'); - if ($ADODB_SESS_LIFE <= 1) { - // bug in PHP 4.0.3 pl 1 -- how about other versions? - //print "

Session Error: PHP.INI setting session.gc_maxlifetimenot set: $ADODB_SESS_LIFE

"; - $ADODB_SESS_LIFE=1440; - } - $ADODB_SESSION_CRC = false; - //$ADODB_SESS_DEBUG = true; - - ////////////////////////////////// - /* SET THE FOLLOWING PARAMETERS */ - ////////////////////////////////// - - if (empty($ADODB_SESSION_DRIVER)) { - $ADODB_SESSION_DRIVER='mysql'; - $ADODB_SESSION_CONNECT='localhost'; - $ADODB_SESSION_USER ='root'; - $ADODB_SESSION_PWD =''; - $ADODB_SESSION_DB ='xphplens_2'; - } - - if (empty($ADODB_SESSION_EXPIRE_NOTIFY)) { - $ADODB_SESSION_EXPIRE_NOTIFY = false; - } - // Made table name configurable - by David Johnson djohnson@inpro.net - if (empty($ADODB_SESSION_TBL)){ - $ADODB_SESSION_TBL = 'sessions'; - } - - /* - $ADODB_SESS['driver'] = $ADODB_SESSION_DRIVER; - $ADODB_SESS['connect'] = $ADODB_SESSION_CONNECT; - $ADODB_SESS['user'] = $ADODB_SESSION_USER; - $ADODB_SESS['pwd'] = $ADODB_SESSION_PWD; - $ADODB_SESS['db'] = $ADODB_SESSION_DB; - $ADODB_SESS['life'] = $ADODB_SESS_LIFE; - $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG; - - $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG; - $ADODB_SESS['table'] = $ADODB_SESS_TBL; - */ - -/****************************************************************************************\ - Create the connection to the database. - - If $ADODB_SESS_CONN already exists, reuse that connection -\****************************************************************************************/ -function adodb_sess_open($save_path, $session_name,$persist=true) -{ -GLOBAL $ADODB_SESS_CONN; - if (isset($ADODB_SESS_CONN)) return true; - -GLOBAL $ADODB_SESSION_CONNECT, - $ADODB_SESSION_DRIVER, - $ADODB_SESSION_USER, - $ADODB_SESSION_PWD, - $ADODB_SESSION_DB, - $ADODB_SESS_DEBUG; - - // cannot use & below - do not know why... - $ADODB_SESS_CONN = ADONewConnection($ADODB_SESSION_DRIVER); - if (!empty($ADODB_SESS_DEBUG)) { - $ADODB_SESS_CONN->debug = true; - ADOConnection::outp( " conn=$ADODB_SESSION_CONNECT user=$ADODB_SESSION_USER pwd=$ADODB_SESSION_PWD db=$ADODB_SESSION_DB "); - } - if ($persist) $ok = $ADODB_SESS_CONN->PConnect($ADODB_SESSION_CONNECT, - $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB); - else $ok = $ADODB_SESS_CONN->Connect($ADODB_SESSION_CONNECT, - $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB); - - if (!$ok) ADOConnection::outp( " --- Session: connection failed

",false); -} - -/****************************************************************************************\ - Close the connection -\****************************************************************************************/ -function adodb_sess_close() -{ -global $ADODB_SESS_CONN; - - if ($ADODB_SESS_CONN) $ADODB_SESS_CONN->Close(); - return true; -} - -/****************************************************************************************\ - Slurp in the session variables and return the serialized string -\****************************************************************************************/ -function adodb_sess_read($key) -{ -global $ADODB_SESS_CONN,$ADODB_SESSION_TBL,$ADODB_SESSION_CRC; - - $rs = $ADODB_SESS_CONN->Execute("SELECT data FROM $ADODB_SESSION_TBL WHERE sesskey = '$key' AND expiry >= " . time()); - if ($rs) { - if ($rs->EOF) { - $v = ''; - } else - $v = rawurldecode(reset($rs->fields)); - - $rs->Close(); - - // new optimization adodb 2.1 - $ADODB_SESSION_CRC = strlen($v).crc32($v); - - return $v; - } - - return ''; // thx to Jorma Tuomainen, webmaster#wizactive.com -} - -/****************************************************************************************\ - Write the serialized data to a database. - - If the data has not been modified since adodb_sess_read(), we do not write. -\****************************************************************************************/ -function adodb_sess_write($key, $val) -{ - global - $ADODB_SESS_CONN, - $ADODB_SESS_LIFE, - $ADODB_SESSION_TBL, - $ADODB_SESS_DEBUG, - $ADODB_SESSION_CRC, - $ADODB_SESSION_EXPIRE_NOTIFY; - - $expiry = time() + $ADODB_SESS_LIFE; - - // crc32 optimization since adodb 2.1 - // now we only update expiry date, thx to sebastian thom in adodb 2.32 - if ($ADODB_SESSION_CRC !== false && $ADODB_SESSION_CRC == strlen($val).crc32($val)) { - if ($ADODB_SESS_DEBUG) echo " --- Session: Only updating date - crc32 not changed

"; - $qry = "UPDATE $ADODB_SESSION_TBL SET expiry=$expiry WHERE sesskey='$key' AND expiry >= " . time(); - $rs = $ADODB_SESS_CONN->Execute($qry); - return true; - } - $val = rawurlencode($val); - - $arr = array('sesskey' => $key, 'expiry' => $expiry, 'data' => $val); - if ($ADODB_SESSION_EXPIRE_NOTIFY) { - $var = reset($ADODB_SESSION_EXPIRE_NOTIFY); - global $$var; - $arr['expireref'] = $$var; - } - $rs = $ADODB_SESS_CONN->Replace($ADODB_SESSION_TBL,$arr, - 'sesskey',$autoQuote = true); - - if (!$rs) { - ADOConnection::outp( ' --- Session Replace: '.$ADODB_SESS_CONN->ErrorMsg().'

',false); - } else { - // bug in access driver (could be odbc?) means that info is not commited - // properly unless select statement executed in Win2000 - if ($ADODB_SESS_CONN->databaseType == 'access') - $rs = $ADODB_SESS_CONN->Execute("select sesskey from $ADODB_SESSION_TBL WHERE sesskey='$key'"); - } - return !empty($rs); -} - -function adodb_sess_destroy($key) -{ - global $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY; - - if ($ADODB_SESSION_EXPIRE_NOTIFY) { - reset($ADODB_SESSION_EXPIRE_NOTIFY); - $fn = next($ADODB_SESSION_EXPIRE_NOTIFY); - $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM); - $rs = $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE sesskey='$key'"); - $ADODB_SESS_CONN->SetFetchMode($savem); - if ($rs) { - $ADODB_SESS_CONN->BeginTrans(); - while (!$rs->EOF) { - $ref = $rs->fields[0]; - $key = $rs->fields[1]; - $fn($ref,$key); - $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'"); - $rs->MoveNext(); - } - $ADODB_SESS_CONN->CommitTrans(); - } - } else { - $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE sesskey = '$key'"; - $rs = $ADODB_SESS_CONN->Execute($qry); - } - return $rs ? true : false; -} - -function adodb_sess_gc($maxlifetime) -{ - global $ADODB_SESS_DEBUG, $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY; - - if ($ADODB_SESSION_EXPIRE_NOTIFY) { - reset($ADODB_SESSION_EXPIRE_NOTIFY); - $fn = next($ADODB_SESSION_EXPIRE_NOTIFY); - $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM); - $t = time(); - $rs =& $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE expiry < $t"); - $ADODB_SESS_CONN->SetFetchMode($savem); - if ($rs) { - $ADODB_SESS_CONN->BeginTrans(); - while (!$rs->EOF) { - $ref = $rs->fields[0]; - $key = $rs->fields[1]; - $fn($ref,$key); - $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'"); - $rs->MoveNext(); - } - $rs->Close(); - - $ADODB_SESS_CONN->CommitTrans(); - - } - } else { - $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE expiry < " . time(); - $ADODB_SESS_CONN->Execute($qry); - - if ($ADODB_SESS_DEBUG) ADOConnection::outp(" --- Garbage Collection: $qry

"); - } - // suggested by Cameron, "GaM3R" - if (defined('ADODB_SESSION_OPTIMIZE')) { - global $ADODB_SESSION_DRIVER; - - switch( $ADODB_SESSION_DRIVER ) { - case 'mysql': - case 'mysqlt': - $opt_qry = 'OPTIMIZE TABLE '.$ADODB_SESSION_TBL; - break; - case 'postgresql': - case 'postgresql7': - $opt_qry = 'VACUUM '.$ADODB_SESSION_TBL; - break; - } - if (!empty($opt_qry)) { - $ADODB_SESS_CONN->Execute($opt_qry); - } - } - if ($ADODB_SESS_CONN->dataProvider === 'oci8') $sql = 'select TO_CHAR('.($ADODB_SESS_CONN->sysTimeStamp).', \'RRRR-MM-DD HH24:MI:SS\') from '. $ADODB_SESSION_TBL; - else $sql = 'select '.$ADODB_SESS_CONN->sysTimeStamp.' from '. $ADODB_SESSION_TBL; - - $rs =& $ADODB_SESS_CONN->SelectLimit($sql,1); - if ($rs && !$rs->EOF) { - - $dbts = reset($rs->fields); - $rs->Close(); - $dbt = $ADODB_SESS_CONN->UnixTimeStamp($dbts); - $t = time(); - - if (abs($dbt - $t) >= ADODB_SESSION_SYNCH_SECS) { - - $msg = - __FILE__.": Server time for webserver {$_SERVER['HTTP_HOST']} not in synch with database: database=$dbt ($dbts), webserver=$t (diff=".(abs($dbt-$t)/3600)." hrs)"; - error_log($msg); - if ($ADODB_SESS_DEBUG) ADOConnection::outp(" --- $msg

"); - } - } - - return true; -} - -session_module_name('user'); -session_set_save_handler( - "adodb_sess_open", - "adodb_sess_close", - "adodb_sess_read", - "adodb_sess_write", - "adodb_sess_destroy", - "adodb_sess_gc"); -} - -/* TEST SCRIPT -- UNCOMMENT */ - -if (0) { - - session_start(); - session_register('AVAR'); - $_SESSION['AVAR'] += 1; - ADOConnection::outp( " --- \$_SESSION['AVAR']={$_SESSION['AVAR']}

",false); -} - +"; + +To force non-persistent connections, call adodb_session_open first before session_start(): + + include('adodb.inc.php'); + include('adodb-session.php'); + adodb_sess_open(false,false,false); + session_start(); + session_register('AVAR'); + $_SESSION['AVAR'] += 1; + print " +-- \$_SESSION['AVAR']={$_SESSION['AVAR']}

"; + + + Installation + ============ + 1. Create this table in your database (syntax might vary depending on your db): + + create table sessions ( + SESSKEY char(32) not null, + EXPIRY int(11) unsigned not null, + EXPIREREF varchar(64), + DATA text not null, + primary key (sesskey) + ); + + For oracle: + create table sessions ( + SESSKEY char(32) not null, + EXPIRY DECIMAL(16) not null, + EXPIREREF varchar(64), + DATA varchar(4000) not null, + primary key (sesskey) + ); + + + 2. Then define the following parameters. You can either modify + this file, or define them before this file is included: + + $ADODB_SESSION_DRIVER='database driver, eg. mysql or ibase'; + $ADODB_SESSION_CONNECT='server to connect to'; + $ADODB_SESSION_USER ='user'; + $ADODB_SESSION_PWD ='password'; + $ADODB_SESSION_DB ='database'; + $ADODB_SESSION_TBL = 'sessions' + + 3. Recommended is PHP 4.1.0 or later. There are documented + session bugs in earlier versions of PHP. + + 4. If you want to receive notifications when a session expires, then + you can tag a session with an EXPIREREF, and before the session + record is deleted, we can call a function that will pass the EXPIREREF + as the first parameter, and the session key as the second parameter. + + To do this, define a notification function, say NotifyFn: + + function NotifyFn($expireref, $sesskey) + { + } + + Then you need to define a global variable $ADODB_SESSION_EXPIRE_NOTIFY. + This is an array with 2 elements, the first being the name of the variable + you would like to store in the EXPIREREF field, and the 2nd is the + notification function's name. + + In this example, we want to be notified when a user's session + has expired, so we store the user id in the global variable $USERID, + store this value in the EXPIREREF field: + + $ADODB_SESSION_EXPIRE_NOTIFY = array('USERID','NotifyFn'); + + Then when the NotifyFn is called, we are passed the $USERID as the first + parameter, eg. NotifyFn($userid, $sesskey). +*/ + +if (!defined('_ADODB_LAYER')) { + include (dirname(__FILE__).'/adodb.inc.php'); +} + +if (!defined('ADODB_SESSION')) { + + define('ADODB_SESSION',1); + + /* if database time and system time is difference is greater than this, then give warning */ + define('ADODB_SESSION_SYNCH_SECS',60); + + /* + Thanks Joe Li. See http://phplens.com/lens/lensforum/msgs.php?id=11487&x=1 +*/ +function adodb_session_regenerate_id() +{ + $conn =& ADODB_Session::_conn(); + if (!$conn) return false; + + $old_id = session_id(); + if (function_exists('session_regenerate_id')) { + session_regenerate_id(); + } else { + session_id(md5(uniqid(rand(), true))); + $ck = session_get_cookie_params(); + setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']); + //@session_start(); + } + $new_id = session_id(); + $ok =& $conn->Execute('UPDATE '. ADODB_Session::table(). ' SET sesskey='. $conn->qstr($new_id). ' WHERE sesskey='.$conn->qstr($old_id)); + + /* it is possible that the update statement fails due to a collision */ + if (!$ok) { + session_id($old_id); + if (empty($ck)) $ck = session_get_cookie_params(); + setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']); + return false; + } + + return true; +} + +/****************************************************************************************\ + Global definitions +\****************************************************************************************/ +GLOBAL $ADODB_SESSION_CONNECT, + $ADODB_SESSION_DRIVER, + $ADODB_SESSION_USER, + $ADODB_SESSION_PWD, + $ADODB_SESSION_DB, + $ADODB_SESS_CONN, + $ADODB_SESS_LIFE, + $ADODB_SESS_DEBUG, + $ADODB_SESSION_EXPIRE_NOTIFY, + $ADODB_SESSION_CRC, + $ADODB_SESSION_TBL; + + + $ADODB_SESS_LIFE = ini_get('session.gc_maxlifetime'); + if ($ADODB_SESS_LIFE <= 1) { + // bug in PHP 4.0.3 pl 1 -- how about other versions? + //print "

Session Error: PHP.INI setting session.gc_maxlifetimenot set: $ADODB_SESS_LIFE

"; + $ADODB_SESS_LIFE=1440; + } + $ADODB_SESSION_CRC = false; + //$ADODB_SESS_DEBUG = true; + + ////////////////////////////////// + /* SET THE FOLLOWING PARAMETERS */ + ////////////////////////////////// + + if (empty($ADODB_SESSION_DRIVER)) { + $ADODB_SESSION_DRIVER='mysql'; + $ADODB_SESSION_CONNECT='localhost'; + $ADODB_SESSION_USER ='root'; + $ADODB_SESSION_PWD =''; + $ADODB_SESSION_DB ='xphplens_2'; + } + + if (empty($ADODB_SESSION_EXPIRE_NOTIFY)) { + $ADODB_SESSION_EXPIRE_NOTIFY = false; + } + // Made table name configurable - by David Johnson djohnson@inpro.net + if (empty($ADODB_SESSION_TBL)){ + $ADODB_SESSION_TBL = 'sessions'; + } + + /* + $ADODB_SESS['driver'] = $ADODB_SESSION_DRIVER; + $ADODB_SESS['connect'] = $ADODB_SESSION_CONNECT; + $ADODB_SESS['user'] = $ADODB_SESSION_USER; + $ADODB_SESS['pwd'] = $ADODB_SESSION_PWD; + $ADODB_SESS['db'] = $ADODB_SESSION_DB; + $ADODB_SESS['life'] = $ADODB_SESS_LIFE; + $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG; + + $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG; + $ADODB_SESS['table'] = $ADODB_SESS_TBL; + */ + +/****************************************************************************************\ + Create the connection to the database. + + If $ADODB_SESS_CONN already exists, reuse that connection +\****************************************************************************************/ +function adodb_sess_open($save_path, $session_name,$persist=true) +{ +GLOBAL $ADODB_SESS_CONN; + if (isset($ADODB_SESS_CONN)) return true; + +GLOBAL $ADODB_SESSION_CONNECT, + $ADODB_SESSION_DRIVER, + $ADODB_SESSION_USER, + $ADODB_SESSION_PWD, + $ADODB_SESSION_DB, + $ADODB_SESS_DEBUG; + + // cannot use & below - do not know why... + $ADODB_SESS_CONN = ADONewConnection($ADODB_SESSION_DRIVER); + if (!empty($ADODB_SESS_DEBUG)) { + $ADODB_SESS_CONN->debug = true; + ADOConnection::outp( " conn=$ADODB_SESSION_CONNECT user=$ADODB_SESSION_USER pwd=$ADODB_SESSION_PWD db=$ADODB_SESSION_DB "); + } + if ($persist) $ok = $ADODB_SESS_CONN->PConnect($ADODB_SESSION_CONNECT, + $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB); + else $ok = $ADODB_SESS_CONN->Connect($ADODB_SESSION_CONNECT, + $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB); + + if (!$ok) ADOConnection::outp( " +-- Session: connection failed

",false); +} + +/****************************************************************************************\ + Close the connection +\****************************************************************************************/ +function adodb_sess_close() +{ +global $ADODB_SESS_CONN; + + if ($ADODB_SESS_CONN) $ADODB_SESS_CONN->Close(); + return true; +} + +/****************************************************************************************\ + Slurp in the session variables and return the serialized string +\****************************************************************************************/ +function adodb_sess_read($key) +{ +global $ADODB_SESS_CONN,$ADODB_SESSION_TBL,$ADODB_SESSION_CRC; + + $rs = $ADODB_SESS_CONN->Execute("SELECT data FROM $ADODB_SESSION_TBL WHERE sesskey = '$key' AND expiry >= " . time()); + if ($rs) { + if ($rs->EOF) { + $v = ''; + } else + $v = rawurldecode(reset($rs->fields)); + + $rs->Close(); + + // new optimization adodb 2.1 + $ADODB_SESSION_CRC = strlen($v).crc32($v); + + return $v; + } + + return ''; // thx to Jorma Tuomainen, webmaster#wizactive.com +} + +/****************************************************************************************\ + Write the serialized data to a database. + + If the data has not been modified since adodb_sess_read(), we do not write. +\****************************************************************************************/ +function adodb_sess_write($key, $val) +{ + global + $ADODB_SESS_CONN, + $ADODB_SESS_LIFE, + $ADODB_SESSION_TBL, + $ADODB_SESS_DEBUG, + $ADODB_SESSION_CRC, + $ADODB_SESSION_EXPIRE_NOTIFY; + + $expiry = time() + $ADODB_SESS_LIFE; + + // crc32 optimization since adodb 2.1 + // now we only update expiry date, thx to sebastian thom in adodb 2.32 + if ($ADODB_SESSION_CRC !== false && $ADODB_SESSION_CRC == strlen($val).crc32($val)) { + if ($ADODB_SESS_DEBUG) echo " +-- Session: Only updating date - crc32 not changed

"; + $qry = "UPDATE $ADODB_SESSION_TBL SET expiry=$expiry WHERE sesskey='$key' AND expiry >= " . time(); + $rs = $ADODB_SESS_CONN->Execute($qry); + return true; + } + $val = rawurlencode($val); + + $arr = array('sesskey' => $key, 'expiry' => $expiry, 'data' => $val); + if ($ADODB_SESSION_EXPIRE_NOTIFY) { + $var = reset($ADODB_SESSION_EXPIRE_NOTIFY); + global $$var; + $arr['expireref'] = $$var; + } + $rs = $ADODB_SESS_CONN->Replace($ADODB_SESSION_TBL,$arr, + 'sesskey',$autoQuote = true); + + if (!$rs) { + ADOConnection::outp( ' +-- Session Replace: '.$ADODB_SESS_CONN->ErrorMsg().'

',false); + } else { + // bug in access driver (could be odbc?) means that info is not commited + // properly unless select statement executed in Win2000 + if ($ADODB_SESS_CONN->databaseType == 'access') + $rs = $ADODB_SESS_CONN->Execute("select sesskey from $ADODB_SESSION_TBL WHERE sesskey='$key'"); + } + return !empty($rs); +} + +function adodb_sess_destroy($key) +{ + global $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY; + + if ($ADODB_SESSION_EXPIRE_NOTIFY) { + reset($ADODB_SESSION_EXPIRE_NOTIFY); + $fn = next($ADODB_SESSION_EXPIRE_NOTIFY); + $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM); + $rs = $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE sesskey='$key'"); + $ADODB_SESS_CONN->SetFetchMode($savem); + if ($rs) { + $ADODB_SESS_CONN->BeginTrans(); + while (!$rs->EOF) { + $ref = $rs->fields[0]; + $key = $rs->fields[1]; + $fn($ref,$key); + $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'"); + $rs->MoveNext(); + } + $ADODB_SESS_CONN->CommitTrans(); + } + } else { + $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE sesskey = '$key'"; + $rs = $ADODB_SESS_CONN->Execute($qry); + } + return $rs ? true : false; +} + +function adodb_sess_gc($maxlifetime) +{ + global $ADODB_SESS_DEBUG, $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY; + + if ($ADODB_SESSION_EXPIRE_NOTIFY) { + reset($ADODB_SESSION_EXPIRE_NOTIFY); + $fn = next($ADODB_SESSION_EXPIRE_NOTIFY); + $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM); + $t = time(); + $rs =& $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE expiry < $t"); + $ADODB_SESS_CONN->SetFetchMode($savem); + if ($rs) { + $ADODB_SESS_CONN->BeginTrans(); + while (!$rs->EOF) { + $ref = $rs->fields[0]; + $key = $rs->fields[1]; + $fn($ref,$key); + $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'"); + $rs->MoveNext(); + } + $rs->Close(); + + $ADODB_SESS_CONN->CommitTrans(); + + } + } else { + $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE expiry < " . time(); + $ADODB_SESS_CONN->Execute($qry); + + if ($ADODB_SESS_DEBUG) ADOConnection::outp(" +-- Garbage Collection: $qry

"); + } + // suggested by Cameron, "GaM3R" + if (defined('ADODB_SESSION_OPTIMIZE')) { + global $ADODB_SESSION_DRIVER; + + switch( $ADODB_SESSION_DRIVER ) { + case 'mysql': + case 'mysqlt': + $opt_qry = 'OPTIMIZE TABLE '.$ADODB_SESSION_TBL; + break; + case 'postgresql': + case 'postgresql7': + $opt_qry = 'VACUUM '.$ADODB_SESSION_TBL; + break; + } + if (!empty($opt_qry)) { + $ADODB_SESS_CONN->Execute($opt_qry); + } + } + if ($ADODB_SESS_CONN->dataProvider === 'oci8') $sql = 'select TO_CHAR('.($ADODB_SESS_CONN->sysTimeStamp).', \'RRRR-MM-DD HH24:MI:SS\') from '. $ADODB_SESSION_TBL; + else $sql = 'select '.$ADODB_SESS_CONN->sysTimeStamp.' from '. $ADODB_SESSION_TBL; + + $rs =& $ADODB_SESS_CONN->SelectLimit($sql,1); + if ($rs && !$rs->EOF) { + + $dbts = reset($rs->fields); + $rs->Close(); + $dbt = $ADODB_SESS_CONN->UnixTimeStamp($dbts); + $t = time(); + + if (abs($dbt - $t) >= ADODB_SESSION_SYNCH_SECS) { + + $msg = + __FILE__.": Server time for webserver {$_SERVER['HTTP_HOST']} not in synch with database: database=$dbt ($dbts), webserver=$t (diff=".(abs($dbt-$t)/3600)." hrs)"; + error_log($msg); + if ($ADODB_SESS_DEBUG) ADOConnection::outp(" +-- $msg

"); + } + } + + return true; +} + +session_module_name('user'); +session_set_save_handler( + "adodb_sess_open", + "adodb_sess_close", + "adodb_sess_read", + "adodb_sess_write", + "adodb_sess_destroy", + "adodb_sess_gc"); +} + +/* TEST SCRIPT -- UNCOMMENT */ + +if (0) { + + session_start(); + session_register('AVAR'); + $_SESSION['AVAR'] += 1; + ADOConnection::outp( " +-- \$_SESSION['AVAR']={$_SESSION['AVAR']}

",false); +} + ?> \ No newline at end of file diff --git a/lib/adodb/toexport.inc.php b/lib/adodb/toexport.inc.php index 6e0f777d53..ba3f37a21c 100644 --- a/lib/adodb/toexport.inc.php +++ b/lib/adodb/toexport.inc.php @@ -1,133 +1,133 @@ -FieldTypesArray(); - reset($fieldTypes); - while(list(,$o) = each($fieldTypes)) { - - $v = $o->name; - if ($escquote) $v = str_replace($quote,$escquotequote,$v); - $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)))); - $elements[] = $v; - - } - $s .= implode($sep, $elements).$NEWLINE; - } - $hasNumIndex = isset($rs->fields[0]); - - $line = 0; - $max = $rs->FieldCount(); - - while (!$rs->EOF) { - $elements = array(); - $i = 0; - - if ($hasNumIndex) { - for ($j=0; $j < $max; $j++) { - $v = $rs->fields[$j]; - if (!is_object($v)) $v = trim($v); - else $v = 'Object'; - if ($escquote) $v = str_replace($quote,$escquotequote,$v); - $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)))); - - if (strpos($v,$sep) !== false || strpos($v,$quote) !== false) $elements[] = "$quote$v$quote"; - else $elements[] = $v; - } - } else { // ASSOCIATIVE ARRAY - foreach($rs->fields as $v) { - if ($escquote) $v = str_replace($quote,$escquotequote,trim($v)); - $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)))); - - if (strpos($v,$sep) !== false || strpos($v,$quote) !== false) $elements[] = "$quote$v$quote"; - else $elements[] = $v; - } - } - $s .= implode($sep, $elements).$NEWLINE; - $rs->MoveNext(); - $line += 1; - if ($fp && ($line % $BUFLINES) == 0) { - if ($fp === true) echo $s; - else fwrite($fp,$s); - $s = ''; - } - } - - if ($fp) { - if ($fp === true) echo $s; - else fwrite($fp,$s); - $s = ''; - } - - return $s; -} +FieldTypesArray(); + reset($fieldTypes); + while(list(,$o) = each($fieldTypes)) { + + $v = $o->name; + if ($escquote) $v = str_replace($quote,$escquotequote,$v); + $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)))); + $elements[] = $v; + + } + $s .= implode($sep, $elements).$NEWLINE; + } + $hasNumIndex = isset($rs->fields[0]); + + $line = 0; + $max = $rs->FieldCount(); + + while (!$rs->EOF) { + $elements = array(); + $i = 0; + + if ($hasNumIndex) { + for ($j=0; $j < $max; $j++) { + $v = $rs->fields[$j]; + if (!is_object($v)) $v = trim($v); + else $v = 'Object'; + if ($escquote) $v = str_replace($quote,$escquotequote,$v); + $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)))); + + if (strpos($v,$sep) !== false || strpos($v,$quote) !== false) $elements[] = "$quote$v$quote"; + else $elements[] = $v; + } + } else { // ASSOCIATIVE ARRAY + foreach($rs->fields as $v) { + if ($escquote) $v = str_replace($quote,$escquotequote,trim($v)); + $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v)))); + + if (strpos($v,$sep) !== false || strpos($v,$quote) !== false) $elements[] = "$quote$v$quote"; + else $elements[] = $v; + } + } + $s .= implode($sep, $elements).$NEWLINE; + $rs->MoveNext(); + $line += 1; + if ($fp && ($line % $BUFLINES) == 0) { + if ($fp === true) echo $s; + else fwrite($fp,$s); + $s = ''; + } + } + + if ($fp) { + if ($fp === true) echo $s; + else fwrite($fp,$s); + $s = ''; + } + + return $s; +} ?> \ No newline at end of file diff --git a/lib/adodb/tohtml.inc.php b/lib/adodb/tohtml.inc.php index 5f1071cc7d..b9bef03f57 100644 --- a/lib/adodb/tohtml.inc.php +++ b/lib/adodb/tohtml.inc.php @@ -1,195 +1,195 @@ - -*/ - -// specific code for tohtml -GLOBAL $gSQLMaxRows,$gSQLBlockRows,$ADODB_ROUND; - -$ADODB_ROUND=4; // rounding -$gSQLMaxRows = 1000; // max no of rows to download -$gSQLBlockRows=20; // max no of rows per table block - -// RecordSet to HTML Table -//------------------------------------------------------------ -// Convert a recordset to a html table. Multiple tables are generated -// if the number of rows is > $gSQLBlockRows. This is because -// web browsers normally require the whole table to be downloaded -// before it can be rendered, so we break the output into several -// smaller faster rendering tables. -// -// $rs: the recordset -// $ztabhtml: the table tag attributes (optional) -// $zheaderarray: contains the replacement strings for the headers (optional) -// -// USAGE: -// include('adodb.inc.php'); -// $db = ADONewConnection('mysql'); -// $db->Connect('mysql','userid','password','database'); -// $rs = $db->Execute('select col1,col2,col3 from table'); -// rs2html($rs, 'BORDER=2', array('Title1', 'Title2', 'Title3')); -// $rs->Close(); -// -// RETURNS: number of rows displayed - - -function rs2html(&$rs,$ztabhtml=false,$zheaderarray=false,$htmlspecialchars=true,$echo = true) -{ -$s ='';$rows=0;$docnt = false; -GLOBAL $gSQLMaxRows,$gSQLBlockRows,$ADODB_ROUND; - - if (!$rs) { - printf(ADODB_BAD_RS,'rs2html'); - return false; - } - - if (! $ztabhtml) $ztabhtml = "BORDER='1' WIDTH='98%'"; - //else $docnt = true; - $typearr = array(); - $ncols = $rs->FieldCount(); - $hdr = "\n\n"; - for ($i=0; $i < $ncols; $i++) { - $field = $rs->FetchField($i); - if ($field) { - if ($zheaderarray) $fname = $zheaderarray[$i]; - else $fname = htmlspecialchars($field->name); - $typearr[$i] = $rs->MetaType($field->type,$field->max_length); - //print " $field->name $field->type $typearr[$i] "; - } else { - $fname = 'Field '.($i+1); - $typearr[$i] = 'C'; - } - if (strlen($fname)==0) $fname = ' '; - $hdr .= ""; - } - $hdr .= "\n"; - if ($echo) print $hdr."\n\n"; - else $html = $hdr; - - // smart algorithm - handles ADODB_FETCH_MODE's correctly by probing... - $numoffset = isset($rs->fields[0]) ||isset($rs->fields[1]) || isset($rs->fields[2]); - while (!$rs->EOF) { - - $s .= "\n"; - - for ($i=0; $i < $ncols; $i++) { - if ($i===0) $v=($numoffset) ? $rs->fields[0] : reset($rs->fields); - else $v = ($numoffset) ? $rs->fields[$i] : next($rs->fields); - - $type = $typearr[$i]; - switch($type) { - case 'D': - if (empty($v)) $s .= "\n"; - else if (!strpos($v,':')) { - $s .= " \n"; - } - break; - case 'T': - if (empty($v)) $s .= "\n"; - else $s .= " \n"; - break; - - case 'N': - if (abs(abs($v) - round($v,0)) < 0.00000001) - $v = round($v); - else - $v = round($v,$ADODB_ROUND); - case 'I': - $s .= " \n"; - - break; - /* - case 'B': - if (substr($v,8,2)=="BM" ) $v = substr($v,8); - $mtime = substr(str_replace(' ','_',microtime()),2); - $tmpname = "tmp/".uniqid($mtime).getmypid(); - $fd = @fopen($tmpname,'a'); - @ftruncate($fd,0); - @fwrite($fd,$v); - @fclose($fd); - if (!function_exists ("mime_content_type")) { - function mime_content_type ($file) { - return exec("file -bi ".escapeshellarg($file)); - } - } - $t = mime_content_type($tmpname); - $s .= (substr($t,0,5)=="image") ? " \\n" : " \\n"; - break; - */ - - default: - if ($htmlspecialchars) $v = htmlspecialchars(trim($v)); - $v = trim($v); - if (strlen($v) == 0) $v = ' '; - $s .= " \n"; - - } - } // for - $s .= "\n\n"; - - $rows += 1; - if ($rows >= $gSQLMaxRows) { - $rows = "

Truncated at $gSQLMaxRows

"; - break; - } // switch - - $rs->MoveNext(); - - // additional EOF check to prevent a widow header - if (!$rs->EOF && $rows % $gSQLBlockRows == 0) { - - //if (connection_aborted()) break;// not needed as PHP aborts script, unlike ASP - if ($echo) print $s . "
$fname
  ".$rs->UserDate($v,"D d, M Y") ."    ".$rs->UserTimeStamp($v,"D d, M Y, h:i:s") ." ".stripslashes((trim($v))) ." $t$t". str_replace("\n",'
',stripslashes($v)) ."
\n\n"; - else $html .= $s ."\n\n"; - $s = $hdr; - } - } // while - - if ($echo) print $s."\n\n"; - else $html .= $s."\n\n"; - - if ($docnt) if ($echo) print "

".$rows." Rows

"; - - return ($echo) ? $rows : $html; - } - -// pass in 2 dimensional array -function arr2html(&$arr,$ztabhtml='',$zheaderarray='') -{ - if (!$ztabhtml) $ztabhtml = 'BORDER=1'; - - $s = "";//';print_r($arr); - - if ($zheaderarray) { - $s .= ''; - for ($i=0; $i\n"; - } else $s .= " \n"; - $s .= "\n\n"; - } - $s .= '
 
'; - print $s; -} - + +*/ + +// specific code for tohtml +GLOBAL $gSQLMaxRows,$gSQLBlockRows,$ADODB_ROUND; + +$ADODB_ROUND=4; // rounding +$gSQLMaxRows = 1000; // max no of rows to download +$gSQLBlockRows=20; // max no of rows per table block + +// RecordSet to HTML Table +//------------------------------------------------------------ +// Convert a recordset to a html table. Multiple tables are generated +// if the number of rows is > $gSQLBlockRows. This is because +// web browsers normally require the whole table to be downloaded +// before it can be rendered, so we break the output into several +// smaller faster rendering tables. +// +// $rs: the recordset +// $ztabhtml: the table tag attributes (optional) +// $zheaderarray: contains the replacement strings for the headers (optional) +// +// USAGE: +// include('adodb.inc.php'); +// $db = ADONewConnection('mysql'); +// $db->Connect('mysql','userid','password','database'); +// $rs = $db->Execute('select col1,col2,col3 from table'); +// rs2html($rs, 'BORDER=2', array('Title1', 'Title2', 'Title3')); +// $rs->Close(); +// +// RETURNS: number of rows displayed + + +function rs2html(&$rs,$ztabhtml=false,$zheaderarray=false,$htmlspecialchars=true,$echo = true) +{ +$s ='';$rows=0;$docnt = false; +GLOBAL $gSQLMaxRows,$gSQLBlockRows,$ADODB_ROUND; + + if (!$rs) { + printf(ADODB_BAD_RS,'rs2html'); + return false; + } + + if (! $ztabhtml) $ztabhtml = "BORDER='1' WIDTH='98%'"; + //else $docnt = true; + $typearr = array(); + $ncols = $rs->FieldCount(); + $hdr = "\n\n"; + for ($i=0; $i < $ncols; $i++) { + $field = $rs->FetchField($i); + if ($field) { + if ($zheaderarray) $fname = $zheaderarray[$i]; + else $fname = htmlspecialchars($field->name); + $typearr[$i] = $rs->MetaType($field->type,$field->max_length); + //print " $field->name $field->type $typearr[$i] "; + } else { + $fname = 'Field '.($i+1); + $typearr[$i] = 'C'; + } + if (strlen($fname)==0) $fname = ' '; + $hdr .= ""; + } + $hdr .= "\n"; + if ($echo) print $hdr."\n\n"; + else $html = $hdr; + + // smart algorithm - handles ADODB_FETCH_MODE's correctly by probing... + $numoffset = isset($rs->fields[0]) ||isset($rs->fields[1]) || isset($rs->fields[2]); + while (!$rs->EOF) { + + $s .= "\n"; + + for ($i=0; $i < $ncols; $i++) { + if ($i===0) $v=($numoffset) ? $rs->fields[0] : reset($rs->fields); + else $v = ($numoffset) ? $rs->fields[$i] : next($rs->fields); + + $type = $typearr[$i]; + switch($type) { + case 'D': + if (empty($v)) $s .= "\n"; + else if (!strpos($v,':')) { + $s .= " \n"; + } + break; + case 'T': + if (empty($v)) $s .= "\n"; + else $s .= " \n"; + break; + + case 'N': + if (abs(abs($v) - round($v,0)) < 0.00000001) + $v = round($v); + else + $v = round($v,$ADODB_ROUND); + case 'I': + $s .= " \n"; + + break; + /* + case 'B': + if (substr($v,8,2)=="BM" ) $v = substr($v,8); + $mtime = substr(str_replace(' ','_',microtime()),2); + $tmpname = "tmp/".uniqid($mtime).getmypid(); + $fd = @fopen($tmpname,'a'); + @ftruncate($fd,0); + @fwrite($fd,$v); + @fclose($fd); + if (!function_exists ("mime_content_type")) { + function mime_content_type ($file) { + return exec("file -bi ".escapeshellarg($file)); + } + } + $t = mime_content_type($tmpname); + $s .= (substr($t,0,5)=="image") ? " \\n" : " \\n"; + break; + */ + + default: + if ($htmlspecialchars) $v = htmlspecialchars(trim($v)); + $v = trim($v); + if (strlen($v) == 0) $v = ' '; + $s .= " \n"; + + } + } // for + $s .= "\n\n"; + + $rows += 1; + if ($rows >= $gSQLMaxRows) { + $rows = "

Truncated at $gSQLMaxRows

"; + break; + } // switch + + $rs->MoveNext(); + + // additional EOF check to prevent a widow header + if (!$rs->EOF && $rows % $gSQLBlockRows == 0) { + + //if (connection_aborted()) break;// not needed as PHP aborts script, unlike ASP + if ($echo) print $s . "
$fname
  ".$rs->UserDate($v,"D d, M Y") ."    ".$rs->UserTimeStamp($v,"D d, M Y, h:i:s") ." ".stripslashes((trim($v))) ." $t$t". str_replace("\n",'
',stripslashes($v)) ."
\n\n"; + else $html .= $s ."\n\n"; + $s = $hdr; + } + } // while + + if ($echo) print $s."\n\n"; + else $html .= $s."\n\n"; + + if ($docnt) if ($echo) print "

".$rows." Rows

"; + + return ($echo) ? $rows : $html; + } + +// pass in 2 dimensional array +function arr2html(&$arr,$ztabhtml='',$zheaderarray='') +{ + if (!$ztabhtml) $ztabhtml = 'BORDER=1'; + + $s = "";//';print_r($arr); + + if ($zheaderarray) { + $s .= ''; + for ($i=0; $i\n"; + } else $s .= " \n"; + $s .= "\n\n"; + } + $s .= '
 
'; + print $s; +} + ?> \ No newline at end of file