<?php
/*
-@version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+@version V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
Latest version is available at http://adodb.sourceforge.net
Released under both BSD license and Lesser GPL library license.
Active Record implementation. Superset of Zend Framework's.
- Version 0.04
+ Version 0.07
See http://www-128.ibm.com/developerworks/java/library/j-cb03076/?ca=dgr-lnxw01ActiveRecord
for info on Ruby on Rails Active Record implementation
foreach($_ADODB_ACTIVE_DBS as $k => $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;
}
}
break;
default:
foreach($cols as $name => $fldobj) {
- $name = ($fldobj->$name);
+ $name = ($fldobj->name);
$this->$name = null;
$attr[$name] = $fldobj;
}
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()
{
/*
- 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.
<?php
/**
- 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.
return $rez;
}
- /*
+ /**
Returns the actual type given a character code.
C: varchar
{
$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->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;
}
{
$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;
}
{
$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);
}
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;
}
$f1 = array();
foreach($f0 as $token) {
switch (strtoupper($token)) {
+ case 'INDEX':
+ $f1['INDEX'] = '';
+ // fall through intentionally
case 'CONSTRAINT':
case 'DEFAULT':
$hasparam = $token;
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;
}
$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;
$fconstraint = false;
$fnotnull = false;
$funsigned = false;
+ $findex = '';
+ $funiqueindex = false;
//-----------------
// Parse attributes
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;
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
// 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) {
} 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
return $sql;
}
- /*
+ /**
GENERATE TRIGGERS IF NEEDED
used when table has auto-incrementing field that is emulated using triggers
*/
return array();
}
- /*
+ /**
Sanitize options, so that array elements with no keys are promoted to keys
*/
function _Options($opts)
return $newopts;
}
- /*
+ /**
"Florian Buzin [ easywe ]" <florian.buzin#easywe.de>
This function changes/adds new fields to your table. You don't
// 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();
$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 "<h3>$this->alterCol cannot be changed to $flds currently</h3>";
+ continue;
+ }
$sql[] = $alter . $this->alterCol . ' ' . $v;
} else {
$sql[] = $alter . $this->addCol . ' ' . $v;
<?php
/**
- * @version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * @version 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.
<?php
/**
- * @version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * @version 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.
<?php
/**
- * @version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * @version 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.
<?php
/**
- * @version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * @version 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.
<?php
/*
- 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.
$ADODB_INCLUDED_LIB = 1;
/*
- @version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim\@natsoft.com.my). All rights reserved.
+ @version 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.
}
}
+
}
-function &adodb_transpose(&$arr, &$newarr, &$hdr)
+function adodb_transpose(&$arr, &$newarr, &$hdr, &$fobjs)
{
$oldX = sizeof(reset($arr));
$oldY = sizeof($arr);
if ($hdr) {
$startx = 1;
- $hdr = array();
+ $hdr = array('Fields');
for ($y = 0; $y < $oldY; $y++) {
$hdr[] = $arr[$y][0];
}
$startx = 0;
for ($x = $startx; $x < $oldX; $x++) {
- $newarr[] = array();
+ if ($fobjs) {
+ $o = $fobjs[$x];
+ $newarr[] = array($o->name);
+ } else
+ $newarr[] = array();
+
for ($y = 0; $y < $oldY; $y++) {
$newarr[$x-$startx][] = $arr[$y][$x];
}
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;
$type = 'C';
}
- if (strpos($upperfname,' ') !== false)
+ if ((strpos($upperfname,' ') !== false) || ($ADODB_QUOTE_FIELDNAMES))
$fnameq = $zthis->nameQuote.$upperfname.$zthis->nameQuote;
else
$fnameq = $upperfname;
static $cacheRS = false;
static $cacheSig = 0;
static $cacheCols;
+ global $ADODB_QUOTE_FIELDNAMES;
$tableName = '';
$values = '';
$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;
-<?php
-
-// security - hide paths
-if (!defined('ADODB_DIR')) die();
-
-global $ADODB_INCLUDED_MEMCACHE;
-$ADODB_INCLUDED_MEMCACHE = 1;
-
-/*
-
- V4.90 8 June 2006 (c) 2000-2006 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.
- Set tabs to 4 for best viewing.
-
- Latest version is available at http://adodb.sourceforge.net
-
-*/
-
- function &getmemcache($key,&$err, $timeout=0, $host, $port)
- {
- $false = false;
- $err = false;
-
- if (!function_exists('memcache_pconnect')) {
- $err = 'Memcache module PECL extension not found!';
- return $false;
- }
-
- $memcache = new Memcache;
- if (!@$memcache->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!<br>\n");
- return $false;
- }
-
- $memcache = new Memcache;
- if (!@$memcache->pconnect($host, $port)) {
- if ($debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port<br>\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!<br>\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!<br>\n");
- return;
- }
-
- $memcache = new Memcache;
- if (!@$memcache->pconnect($host, $port)) {
- if ($debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port<br>\n");
- return;
- }
-
- if ($key) {
- if (!$memcache->delete($key)) {
- if ($debug) ADOConnection::outp("CacheFlush: $key entery doesn't exist on memcached server!<br>\n");
- } else {
- if ($debug) ADOConnection::outp("CacheFlush: $key entery flushed from memcached server!<br>\n");
- }
- } else {
- if (!$memcache->flush()) {
- if ($debug) ADOConnection::outp("CacheFlush: Failure flushing all enteries from memcached server!<br>\n");
- } else {
- if ($debug) ADOConnection::outp("CacheFlush: All enteries flushed from memcached server!<br>\n");
- }
- }
- return;
- }
-?>
+<?php\r
+\r
+// security - hide paths\r
+if (!defined('ADODB_DIR')) die();\r
+\r
+global $ADODB_INCLUDED_MEMCACHE;\r
+$ADODB_INCLUDED_MEMCACHE = 1;\r
+\r
+/* \r
+\r
+ V4.90 8 June 2006 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.\r
+ Released under both BSD license and Lesser GPL library license. \r
+ Whenever there is any discrepancy between the two licenses, \r
+ the BSD license will take precedence. See License.txt. \r
+ Set tabs to 4 for best viewing.\r
+ \r
+ Latest version is available at http://adodb.sourceforge.net\r
+ \r
+*/\r
+\r
+ function &getmemcache($key,&$err, $timeout=0, $host, $port)\r
+ {\r
+ $false = false;\r
+ $err = false;\r
+\r
+ if (!function_exists('memcache_pconnect')) {\r
+ $err = 'Memcache module PECL extension not found!';\r
+ return $false;\r
+ }\r
+\r
+ $memcache = new Memcache;\r
+ if (!@$memcache->pconnect($host, $port)) {\r
+ $err = 'Can\'t connect to memcache server on: '.$host.':'.$port;\r
+ return $false;\r
+ }\r
+\r
+ $rs = $memcache->get($key);\r
+ if (!$rs) {\r
+ $err = 'Item with such key doesn\'t exists on the memcached server.';\r
+ return $false;\r
+ }\r
+\r
+ $tdiff = intval($rs->timeCreated+$timeout - time());\r
+ if ($tdiff <= 2) {\r
+ switch($tdiff) {\r
+ case 2: \r
+ if ((rand() & 15) == 0) {\r
+ $err = "Timeout 2";\r
+ return $false;\r
+ }\r
+ break;\r
+ case 1:\r
+ if ((rand() & 3) == 0) {\r
+ $err = "Timeout 1";\r
+ return $false;\r
+ }\r
+ break;\r
+ default: \r
+ $err = "Timeout 0";\r
+ return $false;\r
+ }\r
+ }\r
+ return $rs;\r
+ }\r
+\r
+ function putmemcache($key, $rs, $host, $port, $compress, $debug=false)\r
+ {\r
+ $false = false;\r
+ $true = true;\r
+\r
+ if (!function_exists('memcache_pconnect')) {\r
+ if ($debug) ADOConnection::outp(" Memcache module PECL extension not found!<br>\n");\r
+ return $false;\r
+ }\r
+\r
+ $memcache = new Memcache;\r
+ if (!@$memcache->pconnect($host, $port)) {\r
+ if ($debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port<br>\n");\r
+ return $false;\r
+ }\r
+\r
+ $rs->timeCreated = time();\r
+ if (!$memcache->set($key, $rs, $compress, 0)) {\r
+ if ($debug) ADOConnection::outp(" Failed to save data at the memcached server!<br>\n");\r
+ return $false;\r
+ }\r
+ return $true;\r
+ }\r
+\r
+ function flushmemcache($key=false, $host, $port, $debug=false)\r
+ {\r
+ if (!function_exists('memcache_pconnect')) {\r
+ if ($debug) ADOConnection::outp(" Memcache module PECL extension not found!<br>\n");\r
+ return;\r
+ }\r
+\r
+ $memcache = new Memcache;\r
+ if (!@$memcache->pconnect($host, $port)) {\r
+ if ($debug) ADOConnection::outp(" Can't connect to memcache server on: $host:$port<br>\n");\r
+ return;\r
+ }\r
+\r
+ if ($key) {\r
+ if (!$memcache->delete($key)) {\r
+ if ($debug) ADOConnection::outp("CacheFlush: $key entery doesn't exist on memcached server!<br>\n");\r
+ } else {\r
+ if ($debug) ADOConnection::outp("CacheFlush: $key entery flushed from memcached server!<br>\n");\r
+ }\r
+ } else {\r
+ if (!$memcache->flush()) {\r
+ if ($debug) ADOConnection::outp("CacheFlush: Failure flushing all enteries from memcached server!<br>\n");\r
+ } else {\r
+ if ($debug) ADOConnection::outp("CacheFlush: All enteries flushed from memcached server!<br>\n");\r
+ }\r
+ }\r
+ return;\r
+ }\r
+?>\r
<?php
/*
- 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.
<?php
/**
- * @version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * @version 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.
<?php
/*
-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.
<?php
/*
- 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.
* build a database on any ADOdb-supported platform using a simple
* XML schema.
*
- * Last Editor: $Author: skodak $
+ * Last Editor: $Author$
* @author Richard Tango-Lowy & Dan Cech
- * @version $Revision: 1.14 $
+ * @version $Revision$
*
* @package axmls
* @tutorial getting_started.pkg
* @tutorial getting_started.pkg
*
* @author Richard Tango-Lowy & Dan Cech
-* @version $Revision: 1.14 $
+* @version $Revision$
*
* @package axmls
*/
* build a database on any ADOdb-supported platform using a simple
* XML schema.
*
- * Last Editor: $Author: skodak $
+ * Last Editor: $Author$
* @author Richard Tango-Lowy & Dan Cech
- * @version $Revision: 1.4 $
+ * @version $Revision$
*
* @package axmls
* @tutorial getting_started.pkg
* @tutorial getting_started.pkg
*
* @author Richard Tango-Lowy & Dan Cech
-* @version $Revision: 1.4 $
+* @version $Revision$
*
* @package axmls
*/
/**
\mainpage
- @version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+ @version 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. You can choose which license
you prefer.
$ADODB_CACHE_DIR, // directory to cache recordsets
$ADODB_EXTENSION, // ADODB extension installed
$ADODB_COMPAT_FETCH, // If $ADODB_COUNTRECS and this is true, $rs->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
$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;
/**
* 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.
}
if ($this->_queryID === true) { // return simplified recordset for inserts/updates/deletes with lower overhead
- $rs =& new ADORecordSet_empty();
+ $rs = new ADORecordSet_empty();
return $rs;
}
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;
}
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);
$this->fmtTimeStamp = "'m-d-Y H:i:s'";
break;
+ case 'PT_BR':
case 'NL':
case 'FR':
case 'RO':
$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;
}
*
* @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 )
*
* @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;
}
/**
$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;
$f->type = $this->_types[$k];
$f->max_length = -1;
$this->_fieldobjects[] = $f;
-
}
$this->fields = reset($this->_array);
<?php
/**
- 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.
<?php
/**
- 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.
<?php
/**
- 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.
<?php
/**
- 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.
<?php
/**
- 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.
<?php
/**
- 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.
<?php
/**
- 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.
<?php
/**
- 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.
<?php
/**
- 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.
$seqname = $this->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'];}
<?php
/**
- 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.
-<?php
-
-/**
- V4.50 6 July 2004 (c) 2000-2006 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.
-
- Set tabs to 4 for best viewing.
-
- Modified from datadict-generic.inc.php for sapdb by RalfBecker-AT-outdoor-training.de
-*/
-
-// security - hide paths
-if (!defined('ADODB_DIR')) die();
-
-class ADODB2_sapdb extends ADODB_DataDict {
-
- var $databaseType = 'sapdb';
- var $seqField = false;
- var $renameColumn = 'RENAME COLUMN %s.%s TO %s';
-
- function ActualType($meta)
- {
- switch($meta) {
- case 'C': return 'VARCHAR';
- case 'XL':
- case 'X': return 'LONG';
-
- case 'C2': return 'VARCHAR UNICODE';
- case 'X2': return 'LONG UNICODE';
-
- case 'B': return 'LONG';
-
- case 'D': return 'DATE';
- case 'T': return 'TIMESTAMP';
-
- case 'L': return 'BOOLEAN';
- case 'I': return 'INTEGER';
- case 'I1': return 'FIXED(3)';
- case 'I2': return 'SMALLINT';
- case 'I4': return 'INTEGER';
- case 'I8': return 'FIXED(20)';
-
- case 'F': return 'FLOAT(38)';
- case 'N': return 'FIXED';
- default:
- return $meta;
- }
- }
-
- function MetaType($t,$len=-1,$fieldobj=false)
- {
- if (is_object($t)) {
- $fieldobj = $t;
- $t = $fieldobj->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) . ')' );
- }
-}
-
+<?php\r
+\r
+/**\r
+ V4.50 6 July 2004 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.\r
+ Released under both BSD license and Lesser GPL library license. \r
+ Whenever there is any discrepancy between the two licenses, \r
+ the BSD license will take precedence.\r
+ \r
+ Set tabs to 4 for best viewing.\r
+ \r
+ Modified from datadict-generic.inc.php for sapdb by RalfBecker-AT-outdoor-training.de\r
+*/\r
+\r
+// security - hide paths\r
+if (!defined('ADODB_DIR')) die();\r
+\r
+class ADODB2_sapdb extends ADODB_DataDict {\r
+ \r
+ var $databaseType = 'sapdb';\r
+ var $seqField = false; \r
+ var $renameColumn = 'RENAME COLUMN %s.%s TO %s';\r
+ \r
+ function ActualType($meta)\r
+ {\r
+ switch($meta) {\r
+ case 'C': return 'VARCHAR';\r
+ case 'XL':\r
+ case 'X': return 'LONG';\r
+ \r
+ case 'C2': return 'VARCHAR UNICODE';\r
+ case 'X2': return 'LONG UNICODE';\r
+ \r
+ case 'B': return 'LONG';\r
+ \r
+ case 'D': return 'DATE';\r
+ case 'T': return 'TIMESTAMP';\r
+ \r
+ case 'L': return 'BOOLEAN';\r
+ case 'I': return 'INTEGER';\r
+ case 'I1': return 'FIXED(3)';\r
+ case 'I2': return 'SMALLINT';\r
+ case 'I4': return 'INTEGER';\r
+ case 'I8': return 'FIXED(20)';\r
+ \r
+ case 'F': return 'FLOAT(38)';\r
+ case 'N': return 'FIXED';\r
+ default:\r
+ return $meta;\r
+ }\r
+ }\r
+ \r
+ function MetaType($t,$len=-1,$fieldobj=false)\r
+ {\r
+ if (is_object($t)) {\r
+ $fieldobj = $t;\r
+ $t = $fieldobj->type;\r
+ $len = $fieldobj->max_length;\r
+ }\r
+ static $maxdb_type2adodb = array(\r
+ 'VARCHAR' => 'C',\r
+ 'CHARACTER' => 'C',\r
+ 'LONG' => 'X', // no way to differ between 'X' and 'B' :-(\r
+ 'DATE' => 'D',\r
+ 'TIMESTAMP' => 'T',\r
+ 'BOOLEAN' => 'L',\r
+ 'INTEGER' => 'I4',\r
+ 'SMALLINT' => 'I2',\r
+ 'FLOAT' => 'F',\r
+ 'FIXED' => 'N',\r
+ );\r
+ $type = isset($maxdb_type2adodb[$t]) ? $maxdb_type2adodb[$t] : 'C';\r
+\r
+ // convert integer-types simulated with fixed back to integer\r
+ if ($t == 'FIXED' && !$fieldobj->scale && ($len == 20 || $len == 3)) {\r
+ $type = $len == 20 ? 'I8' : 'I1';\r
+ }\r
+ if ($fieldobj->auto_increment) $type = 'R';\r
+\r
+ return $type;\r
+ }\r
+ \r
+ // return string must begin with space\r
+ function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)\r
+ { \r
+ $suffix = '';\r
+ if ($funsigned) $suffix .= ' UNSIGNED';\r
+ if ($fnotnull) $suffix .= ' NOT NULL';\r
+ if ($fautoinc) $suffix .= ' DEFAULT SERIAL';\r
+ elseif (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";\r
+ if ($fconstraint) $suffix .= ' '.$fconstraint;\r
+ return $suffix;\r
+ }\r
+\r
+ function AddColumnSQL($tabname, $flds)\r
+ {\r
+ $tabname = $this->TableName ($tabname);\r
+ $sql = array();\r
+ list($lines,$pkey) = $this->_GenFields($flds);\r
+ return array( 'ALTER TABLE ' . $tabname . ' ADD (' . implode(', ',$lines) . ')' );\r
+ }\r
+ \r
+ function AlterColumnSQL($tabname, $flds)\r
+ {\r
+ $tabname = $this->TableName ($tabname);\r
+ $sql = array();\r
+ list($lines,$pkey) = $this->_GenFields($flds);\r
+ return array( 'ALTER TABLE ' . $tabname . ' MODIFY (' . implode(', ',$lines) . ')' );\r
+ }\r
+\r
+ function DropColumnSQL($tabname, $flds)\r
+ {\r
+ $tabname = $this->TableName ($tabname);\r
+ if (!is_array($flds)) $flds = explode(',',$flds);\r
+ foreach($flds as $k => $v) {\r
+ $flds[$k] = $this->NameQuote($v);\r
+ }\r
+ return array( 'ALTER TABLE ' . $tabname . ' DROP (' . implode(', ',$flds) . ')' );\r
+ } \r
+}\r
+\r
?>
\ No newline at end of file
<?php
/**
- 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.
<?php
/*
-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.
var $sysDate = "FORMAT(NOW,'yyyy-mm-dd')";
var $sysTimeStamp = 'NOW';
var $hasTransactions = false;
+ var $upperCase = 'ucase';
function ADODB_access()
{
<?php
/*
-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.
<?php
/*
-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.
<?php
/*
-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.
var $sysDate = "FORMAT(NOW,'yyyy-mm-dd')";
var $sysTimeStamp = 'NOW';
var $hasTransactions = false;
+ var $upperCase = 'ucase';
function ADODB_ado_access()
{
<?php
/*
-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.
$this->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);
<?php
/*
-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.
<?php
/*
-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.
<?php
/*
- V4.93 10 Oct 2006 (c) 2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.94 23 Jan 2007 (c) 2006 John Lim (jlim#natsoft.com.my). All rights reserved.
This is a version of the ADODB driver for DB2. It uses the 'ibm_db2' PECL extension
for PHP (http://pecl.php.net/package/ibm_db2), which in turn requires DB2 V8.2.2 or
<?php
/*
- @version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+ @version 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.
<?php
/*
-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.
<?php
/*
-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.
<?php
/**
-* @version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+* @version 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.
<?php
/*
-V4.93 10 Oct 2006 (c) 2000-2006 John Lim. All rights reserved.
+V4.94 23 Jan 2007 (c) 2000-2007 John Lim. 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.
<?php
/*
- 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.
<?php
/*
-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.
-<?php /// $Id $
-
-///////////////////////////////////////////////////////////////////////////
-// //
-// NOTICE OF COPYRIGHT //
-// //
-// ADOdb - Database Abstraction Library for PHP //
-// http://adodb.sourceforge.net/ //
-// //
-// Copyright (C) 2000-2006 John Lim (jlim\@natsoft.com.my) //
-// All rights reserved. //
-// Released under both BSD license and LGPL library license. //
-// Whenever there is any discrepancy between the two licenses, //
-// the BSD license will take precedence //
-// //
-// Moodle - Modular Object-Oriented Dynamic Learning Environment //
-// http://moodle.com //
-// //
-// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
-// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
-// //
-// This program is free software; you can redistribute it and/or modify //
-// it under the terms of the GNU General Public License as published by //
-// the Free Software Foundation; either version 2 of the License, or //
-// (at your option) any later version. //
-// //
-// This program is distributed in the hope that it will be useful, //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
-// GNU General Public License for more details: //
-// //
-// http://www.gnu.org/copyleft/gpl.html //
-// //
-///////////////////////////////////////////////////////////////////////////
-
-/**
-* MSSQL Driver with auto-prepended "N" for correct unicode storage
-* of SQL literal strings. Intended to be used with MSSQL drivers that
-* are sending UCS-2 data to MSSQL (FreeTDS and ODBTP) in order to get
-* true cross-db compatibility from the application point of view.
-*/
-
-// security - hide paths
-if (!defined('ADODB_DIR')) die();
-
-// one useful constant
-if (!defined('SINGLEQUOTE')) define('SINGLEQUOTE', "'");
-
-include_once(ADODB_DIR.'/drivers/adodb-mssql.inc.php');
-
-class ADODB_mssql_n extends ADODB_mssql {
- var $databaseType = "mssql_n";
-
- function ADODB_mssqlpo()
- {
- ADODB_mssql::ADODB_mssql();
- }
-
- function _query($sql,$inputarr)
- {
- $sql = $this->_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:<br>{$sql}<br>to<br>{$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);
- }
-}
-?>
+<?php \r
+\r
+/// $Id $\r
+\r
+///////////////////////////////////////////////////////////////////////////\r
+// //\r
+// NOTICE OF COPYRIGHT //\r
+// //\r
+// ADOdb - Database Abstraction Library for PHP //\r
+// http://adodb.sourceforge.net/ //\r
+// //\r
+// Copyright (C) 2000-2007 John Lim (jlim\@natsoft.com.my) //\r
+// All rights reserved. //\r
+// Released under both BSD license and LGPL library license. //\r
+// Whenever there is any discrepancy between the two licenses, //\r
+// the BSD license will take precedence //\r
+// //\r
+// Moodle - Modular Object-Oriented Dynamic Learning Environment //\r
+// http://moodle.com //\r
+// //\r
+// Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //\r
+// (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //\r
+// //\r
+// This program is free software; you can redistribute it and/or modify //\r
+// it under the terms of the GNU General Public License as published by //\r
+// the Free Software Foundation; either version 2 of the License, or //\r
+// (at your option) any later version. //\r
+// //\r
+// This program is distributed in the hope that it will be useful, //\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //\r
+// GNU General Public License for more details: //\r
+// //\r
+// http://www.gnu.org/copyleft/gpl.html //\r
+// //\r
+///////////////////////////////////////////////////////////////////////////\r
+\r
+/**\r
+* MSSQL Driver with auto-prepended "N" for correct unicode storage\r
+* of SQL literal strings. Intended to be used with MSSQL drivers that\r
+* are sending UCS-2 data to MSSQL (FreeTDS and ODBTP) in order to get\r
+* true cross-db compatibility from the application point of view.\r
+*/\r
+\r
+// security - hide paths\r
+if (!defined('ADODB_DIR')) die();\r
+\r
+// one useful constant\r
+if (!defined('SINGLEQUOTE')) define('SINGLEQUOTE', "'");\r
+\r
+include_once(ADODB_DIR.'/drivers/adodb-mssql.inc.php');\r
+\r
+class ADODB_mssql_n extends ADODB_mssql {\r
+ var $databaseType = "mssql_n";\r
+ \r
+ function ADODB_mssqlpo()\r
+ {\r
+ ADODB_mssql::ADODB_mssql();\r
+ }\r
+\r
+ function _query($sql,$inputarr)\r
+ {\r
+ $sql = $this->_appendN($sql);\r
+ return ADODB_mssql::_query($sql,$inputarr);\r
+ }\r
+\r
+ /**\r
+ * This function will intercept all the literals used in the SQL, prepending the "N" char to them\r
+ * in order to allow mssql to store properly data sent in the correct UCS-2 encoding (by freeTDS\r
+ * and ODBTP) keeping SQL compatibility at ADOdb level (instead of hacking every project to add\r
+ * the "N" notation when working against MSSQL.\r
+ *\r
+ * Note that this hack only must be used if ALL the char-based columns in your DB are of type nchar,\r
+ * nvarchar and ntext \r
+ */\r
+ function _appendN($sql) {\r
+\r
+ $result = $sql;\r
+\r
+ /// Check we have some single quote in the query. Exit ok.\r
+ if (strpos($sql, SINGLEQUOTE) === false) {\r
+ return $sql;\r
+ }\r
+\r
+ /// Check we haven't an odd number of single quotes (this can cause problems below\r
+ /// and should be considered one wrong SQL). Exit with debug info.\r
+ if ((substr_count($sql, SINGLEQUOTE) & 1)) {\r
+ if ($this->debug) {\r
+ ADOConnection::outp("{$this->databaseType} internal transformation: not converted. Wrong number of quotes (odd)");\r
+ }\r
+ return $sql;\r
+ }\r
+\r
+ /// Check we haven't any backslash + single quote combination. It should mean wrong\r
+ /// backslashes use (bad magic_quotes_sybase?). Exit with debug info.\r
+ $regexp = '/(\\\\' . SINGLEQUOTE . '[^' . SINGLEQUOTE . '])/';\r
+ if (preg_match($regexp, $sql)) {\r
+ if ($this->debug) {\r
+ ADOConnection::outp("{$this->databaseType} internal transformation: not converted. Found bad use of backslash + single quote");\r
+ }\r
+ return $sql;\r
+ }\r
+\r
+ /// Remove pairs of single-quotes\r
+ $pairs = array();\r
+ $regexp = '/(' . SINGLEQUOTE . SINGLEQUOTE . ')/';\r
+ preg_match_all($regexp, $result, $list_of_pairs);\r
+ if ($list_of_pairs) {\r
+ foreach (array_unique($list_of_pairs[0]) as $key=>$value) {\r
+ $pairs['<@#@#@PAIR-'.$key.'@#@#@>'] = $value;\r
+ }\r
+ if (!empty($pairs)) {\r
+ $result = str_replace($pairs, array_keys($pairs), $result);\r
+ }\r
+ }\r
+\r
+ /// Remove the rest of literals present in the query\r
+ $literals = array();\r
+ $regexp = '/(N?' . SINGLEQUOTE . '.*?' . SINGLEQUOTE . ')/is';\r
+ preg_match_all($regexp, $result, $list_of_literals);\r
+ if ($list_of_literals) {\r
+ foreach (array_unique($list_of_literals[0]) as $key=>$value) {\r
+ $literals['<#@#@#LITERAL-'.$key.'#@#@#>'] = $value;\r
+ }\r
+ if (!empty($literals)) {\r
+ $result = str_replace($literals, array_keys($literals), $result);\r
+ }\r
+ }\r
+\r
+ /// Analyse literals to prepend the N char to them if their contents aren't numeric\r
+ if (!empty($literals)) {\r
+ foreach ($literals as $key=>$value) {\r
+ if (!is_numeric(trim($value, SINGLEQUOTE))) {\r
+ /// Non numeric string, prepend our dear N\r
+ $literals[$key] = 'N' . trim($value, 'N'); //Trimming potentially existing previous "N"\r
+ }\r
+ }\r
+ }\r
+\r
+ /// Re-apply literals to the text\r
+ if (!empty($literals)) {\r
+ $result = str_replace(array_keys($literals), $literals, $result);\r
+ }\r
+\r
+ /// Re-apply pairs of single-quotes to the text\r
+ if (!empty($pairs)) {\r
+ $result = str_replace(array_keys($pairs), $pairs, $result);\r
+ }\r
+\r
+ /// Print transformation if debug = on\r
+ if ($result != $sql && $this->debug) {\r
+ ADOConnection::outp("{$this->databaseType} internal transformation:<br>{$sql}<br>to<br>{$result}");\r
+ }\r
+\r
+ return $result;\r
+ }\r
+}\r
+\r
+class ADORecordset_mssql_n extends ADORecordset_mssql {\r
+ var $databaseType = "mssql_n";\r
+ function ADORecordset_mssql_n($id,$mode=false)\r
+ {\r
+ $this->ADORecordset_mssql($id,$mode);\r
+ }\r
+}\r
+?>
\ No newline at end of file
<?php
/**
-* @version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+* @version 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.
<?php
/*
-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.
if ($fieldOffset != -1) {
$o = @mysql_fetch_field($this->_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
}
<?php
/*
-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.
return " IFNULL($field, $ifNull) "; // if MySQL
}
+ // do not use $ADODB_COUNTRECS
+ function GetOne($sql,$inputarr=false)
+ {
+ $ret = false;
+ $rs = &$this->Execute($sql,$inputarr);
+ if ($rs) {
+ if (!$rs->EOF) $ret = reset($rs->fields);
+ $rs->Close();
+ }
+ return $ret;
+ }
+
function ServerInfo()
{
$arr['description'] = $this->GetOne("select version()");
{
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;
}
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;
}
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;
}
<?php
/*
-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.
<?php
/*
- 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.
First cut at the Netezza Driver by Josh Eldridge joshuae74#hotmail.com
Based on the previous postgres drivers.
<?php
/*
- version V4.93 10 Oct 2006 (c) 2000-2006 John Lim. All rights reserved.
+ version V4.94 23 Jan 2007 (c) 2000-2007 John Lim. All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
//if ($argHostname) print "<p>Connect: 1st argument should be left blank for $this->databaseType</p>";
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) {
{
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'];
$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);
$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) {
<?php
/**
- * @version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * @version 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.
<?php
/*
-V4.93 10 Oct 2006 (c) 2000-2006 John Lim. All rights reserved.
+V4.94 23 Jan 2007 (c) 2000-2007 John Lim. 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.
<?php
/*
-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.
<?php
/*
-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.
<?php
/*
-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.
<?php
/*
-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.
<?php
/*
- 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.
//if uid & pwd can be separate
function _connect($HostOrInterface, $UserOrDSN='', $argPassword='', $argDatabase='')
{
- $this->_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);
$this->replaceQuote = "'+chr(39)+'";
$this->true = '.T.';
$this->false = '.F.';
+
break;
case 'oracle':
$this->databaseType = 'odbtp_oci8';
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;
}
$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;
return false;
}
} else {
- $stmtid = @odbtp_query($sql,$this->_connectionID);
+ $stmtid = odbtp_query($sql,$this->_connectionID);
}
$this->_lastAffectedRows = 0;
if ($stmtid) {
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);
}
<?php
/*
- 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.
<?php
/*
-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.
<?php
/*
-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.
$this->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);
}
/*
-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.
/*
-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.
/*
-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.
<?php
/*
-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.
<?php
/*
- 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.
<?php
/*
- 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.
}
$s = "PREPARE $plan ($params) AS ".substr($sql,0,strlen($sql)-2);
//adodb_pr($s);
- pg_exec($this->_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);
<?php
/*
- 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.
<?php
/*
- 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.
<?php
/*
-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.
<?php
/*
-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.
<?php
/*
-version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights
+version 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,
<?php
/*
-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.
<?php
/*
-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.
<?php
/*
-V4.93 10 Oct 2006 (c) 2000-2006 John Lim. All rights reserved.
+V4.94 23 Jan 2007 (c) 2000-2007 John Lim. 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.
<?php
/*
- 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.
<?php
/*
-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.
<?php
/*
-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.
<?php
/*
-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.
<?php
/*
-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.
<?php
/*
-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.
<?php
/*
-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.
<?php
/*
-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.
-<?php
-/**
- * @version V4.93 10 Oct 2006 (c) 2000-2006 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.
- *
- * Set tabs to 4 for best viewing.
- *
-*/
-
-/*
- * Concept from daniel.lucazeau@ajornet.com.
- *
- * @param db Adodb database connection
- * @param tables List of tables to join
- * @rowfields List of fields to display on each row
- * @colfield Pivot field to slice and display in columns, if we want to calculate
- * ranges, we pass in an array (see example2)
- * @where Where clause. Optional.
- * @aggfield This is the field to sum. Optional.
- * Since 2.3.1, if you can use your own aggregate function
- * instead of SUM, eg. $aggfield = 'fieldname'; $aggfn = 'AVG';
- * @sumlabel Prefix to display in sum columns. Optional.
- * @aggfn Aggregate function to use (could be AVG, SUM, COUNT)
- * @showcount Show count of records
- *
- * @returns Sql generated
- */
-
- function PivotTableSQL(&$db,$tables,$rowfields,$colfield, $where=false,
- $aggfield = false,$sumlabel='Sum ',$aggfn ='SUM', $showcount = true)
- {
- if ($aggfield) $hidecnt = true;
- else $hidecnt = false;
-
- $iif = strpos($db->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 "<pre>$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 "<pre>$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
- */
-}
+<?php\r
+/** \r
+ * @version V4.93 10 Oct 2006 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.\r
+ * Released under both BSD license and Lesser GPL library license. \r
+ * Whenever there is any discrepancy between the two licenses, \r
+ * the BSD license will take precedence. \r
+ *\r
+ * Set tabs to 4 for best viewing.\r
+ * \r
+*/\r
+\r
+/*\r
+ * Concept from daniel.lucazeau@ajornet.com. \r
+ *\r
+ * @param db Adodb database connection\r
+ * @param tables List of tables to join\r
+ * @rowfields List of fields to display on each row\r
+ * @colfield Pivot field to slice and display in columns, if we want to calculate\r
+ * ranges, we pass in an array (see example2)\r
+ * @where Where clause. Optional.\r
+ * @aggfield This is the field to sum. Optional. \r
+ * Since 2.3.1, if you can use your own aggregate function \r
+ * instead of SUM, eg. $aggfield = 'fieldname'; $aggfn = 'AVG';\r
+ * @sumlabel Prefix to display in sum columns. Optional.\r
+ * @aggfn Aggregate function to use (could be AVG, SUM, COUNT)\r
+ * @showcount Show count of records\r
+ *\r
+ * @returns Sql generated\r
+ */\r
+ \r
+ function PivotTableSQL(&$db,$tables,$rowfields,$colfield, $where=false,\r
+ $aggfield = false,$sumlabel='Sum ',$aggfn ='SUM', $showcount = true)\r
+ {\r
+ if ($aggfield) $hidecnt = true;\r
+ else $hidecnt = false;\r
+ \r
+ $iif = strpos($db->databaseType,'access') !== false; \r
+ // note - vfp 6 still doesn' work even with IIF enabled || $db->databaseType == 'vfp';\r
+ \r
+ //$hidecnt = false;\r
+ \r
+ if ($where) $where = "\nWHERE $where";\r
+ if (!is_array($colfield)) $colarr = $db->GetCol("select distinct $colfield from $tables $where order by 1");\r
+ if (!$aggfield) $hidecnt = false;\r
+ \r
+ $sel = "$rowfields, ";\r
+ if (is_array($colfield)) {\r
+ foreach ($colfield as $k => $v) {\r
+ $k = trim($k);\r
+ if (!$hidecnt) {\r
+ $sel .= $iif ? \r
+ "\n\t$aggfn(IIF($v,1,0)) AS \"$k\", "\r
+ :\r
+ "\n\t$aggfn(CASE WHEN $v THEN 1 ELSE 0 END) AS \"$k\", ";\r
+ }\r
+ if ($aggfield) {\r
+ $sel .= $iif ?\r
+ "\n\t$aggfn(IIF($v,$aggfield,0)) AS \"$sumlabel$k\", "\r
+ :\r
+ "\n\t$aggfn(CASE WHEN $v THEN $aggfield ELSE 0 END) AS \"$sumlabel$k\", ";\r
+ }\r
+ } \r
+ } else {\r
+ foreach ($colarr as $v) {\r
+ if (!is_numeric($v)) $vq = $db->qstr($v);\r
+ else $vq = $v;\r
+ $v = trim($v);\r
+ if (strlen($v) == 0 ) $v = 'null';\r
+ if (!$hidecnt) {\r
+ $sel .= $iif ?\r
+ "\n\t$aggfn(IIF($colfield=$vq,1,0)) AS \"$v\", "\r
+ :\r
+ "\n\t$aggfn(CASE WHEN $colfield=$vq THEN 1 ELSE 0 END) AS \"$v\", ";\r
+ }\r
+ if ($aggfield) {\r
+ if ($hidecnt) $label = $v;\r
+ else $label = "{$v}_$aggfield";\r
+ $sel .= $iif ?\r
+ "\n\t$aggfn(IIF($colfield=$vq,$aggfield,0)) AS \"$label\", "\r
+ :\r
+ "\n\t$aggfn(CASE WHEN $colfield=$vq THEN $aggfield ELSE 0 END) AS \"$label\", ";\r
+ }\r
+ }\r
+ }\r
+ if ($aggfield && $aggfield != '1'){\r
+ $agg = "$aggfn($aggfield)";\r
+ $sel .= "\n\t$agg as \"$sumlabel$aggfield\", "; \r
+ }\r
+ \r
+ if ($showcount)\r
+ $sel .= "\n\tSUM(1) as Total";\r
+ else\r
+ $sel = substr($sel,0,strlen($sel)-2);\r
+ \r
+ \r
+ // Strip aliases\r
+ $rowfields = preg_replace('/ AS (\w+)/i', '', $rowfields);\r
+ \r
+ $sql = "SELECT $sel \nFROM $tables $where \nGROUP BY $rowfields";\r
+ \r
+ return $sql;\r
+ }\r
+\r
+/* EXAMPLES USING MS NORTHWIND DATABASE */\r
+if (0) {\r
+\r
+# example1\r
+#\r
+# Query the main "product" table\r
+# Set the rows to CompanyName and QuantityPerUnit\r
+# and the columns to the Categories\r
+# and define the joins to link to lookup tables \r
+# "categories" and "suppliers"\r
+#\r
+\r
+ $sql = PivotTableSQL(\r
+ $gDB, # adodb connection\r
+ 'products p ,categories c ,suppliers s', # tables\r
+ 'CompanyName,QuantityPerUnit', # row fields\r
+ 'CategoryName', # column fields \r
+ 'p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID' # joins/where\r
+);\r
+ print "<pre>$sql";\r
+ $rs = $gDB->Execute($sql);\r
+ rs2html($rs);\r
+ \r
+/*\r
+Generated SQL:\r
+\r
+SELECT CompanyName,QuantityPerUnit, \r
+ SUM(CASE WHEN CategoryName='Beverages' THEN 1 ELSE 0 END) AS "Beverages", \r
+ SUM(CASE WHEN CategoryName='Condiments' THEN 1 ELSE 0 END) AS "Condiments", \r
+ SUM(CASE WHEN CategoryName='Confections' THEN 1 ELSE 0 END) AS "Confections", \r
+ SUM(CASE WHEN CategoryName='Dairy Products' THEN 1 ELSE 0 END) AS "Dairy Products", \r
+ SUM(CASE WHEN CategoryName='Grains/Cereals' THEN 1 ELSE 0 END) AS "Grains/Cereals", \r
+ SUM(CASE WHEN CategoryName='Meat/Poultry' THEN 1 ELSE 0 END) AS "Meat/Poultry", \r
+ SUM(CASE WHEN CategoryName='Produce' THEN 1 ELSE 0 END) AS "Produce", \r
+ SUM(CASE WHEN CategoryName='Seafood' THEN 1 ELSE 0 END) AS "Seafood", \r
+ SUM(1) as Total \r
+FROM products p ,categories c ,suppliers s WHERE p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID \r
+GROUP BY CompanyName,QuantityPerUnit\r
+*/\r
+//=====================================================================\r
+\r
+# example2\r
+#\r
+# Query the main "product" table\r
+# Set the rows to CompanyName and QuantityPerUnit\r
+# and the columns to the UnitsInStock for diiferent ranges\r
+# and define the joins to link to lookup tables \r
+# "categories" and "suppliers"\r
+#\r
+ $sql = PivotTableSQL(\r
+ $gDB, # adodb connection\r
+ 'products p ,categories c ,suppliers s', # tables\r
+ 'CompanyName,QuantityPerUnit', # row fields\r
+ # column ranges\r
+array( \r
+' 0 ' => 'UnitsInStock <= 0',\r
+"1 to 5" => '0 < UnitsInStock and UnitsInStock <= 5',\r
+"6 to 10" => '5 < UnitsInStock and UnitsInStock <= 10',\r
+"11 to 15" => '10 < UnitsInStock and UnitsInStock <= 15',\r
+"16+" =>'15 < UnitsInStock'\r
+),\r
+ ' p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID', # joins/where\r
+ 'UnitsInStock', # sum this field\r
+ 'Sum' # sum label prefix\r
+);\r
+ print "<pre>$sql";\r
+ $rs = $gDB->Execute($sql);\r
+ rs2html($rs);\r
+ /*\r
+ Generated SQL:\r
+ \r
+SELECT CompanyName,QuantityPerUnit, \r
+ SUM(CASE WHEN UnitsInStock <= 0 THEN UnitsInStock ELSE 0 END) AS "Sum 0 ", \r
+ SUM(CASE WHEN 0 < UnitsInStock and UnitsInStock <= 5 THEN UnitsInStock ELSE 0 END) AS "Sum 1 to 5", \r
+ SUM(CASE WHEN 5 < UnitsInStock and UnitsInStock <= 10 THEN UnitsInStock ELSE 0 END) AS "Sum 6 to 10", \r
+ SUM(CASE WHEN 10 < UnitsInStock and UnitsInStock <= 15 THEN UnitsInStock ELSE 0 END) AS "Sum 11 to 15", \r
+ SUM(CASE WHEN 15 < UnitsInStock THEN UnitsInStock ELSE 0 END) AS "Sum 16+",\r
+ SUM(UnitsInStock) AS "Sum UnitsInStock", \r
+ SUM(1) as Total \r
+FROM products p ,categories c ,suppliers s WHERE p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID \r
+GROUP BY CompanyName,QuantityPerUnit\r
+ */\r
+}\r
?>
\ No newline at end of file
-Description of ADODB v4.93 library import into Moodle
+Description of ADODB v4.94 library import into Moodle
Removed:
* contrib/
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$
-<?php
-/**
- * @version V4.93 10 Oct 2006 (c) 2000-2006 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.
- *
- * Set tabs to 4 for best viewing.
- *
- * Latest version is available at http://php.weblogs.com
- *
- * Requires PHP4.01pl2 or later because it uses include_once
-*/
-
-/*
- Filter all fields and all rows in a recordset and returns the
- processed recordset. We scroll to the beginning of the new recordset
- after processing.
-
- We pass a recordset and function name to RSFilter($rs,'rowfunc');
- and the function will be called multiple times, once
- for each row in the recordset. The function will be passed
- an array containing one row repeatedly.
-
- Example:
-
- // ucwords() every element in the recordset
- function do_ucwords(&$arr,$rs)
- {
- foreach($arr as $k => $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;
-}
+<?php\r
+/** \r
+ * @version V4.93 10 Oct 2006 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.\r
+ * Released under both BSD license and Lesser GPL library license. \r
+ * Whenever there is any discrepancy between the two licenses, \r
+ * the BSD license will take precedence. \r
+ *\r
+ * Set tabs to 4 for best viewing.\r
+ * \r
+ * Latest version is available at http://php.weblogs.com\r
+ *\r
+ * Requires PHP4.01pl2 or later because it uses include_once\r
+*/\r
+\r
+/*\r
+ Filter all fields and all rows in a recordset and returns the \r
+ processed recordset. We scroll to the beginning of the new recordset\r
+ after processing.\r
+ \r
+ We pass a recordset and function name to RSFilter($rs,'rowfunc');\r
+ and the function will be called multiple times, once\r
+ for each row in the recordset. The function will be passed\r
+ an array containing one row repeatedly.\r
+ \r
+ Example: \r
+ \r
+ // ucwords() every element in the recordset\r
+ function do_ucwords(&$arr,$rs)\r
+ {\r
+ foreach($arr as $k => $v) {\r
+ $arr[$k] = ucwords($v);\r
+ }\r
+ }\r
+ $rs = RSFilter($rs,'do_ucwords');\r
+ */\r
+function &RSFilter($rs,$fn)\r
+{\r
+ if ($rs->databaseType != 'array') {\r
+ if (!$rs->connection) return false;\r
+ \r
+ $rs = &$rs->connection->_rs2rs($rs);\r
+ }\r
+ $rows = $rs->RecordCount();\r
+ for ($i=0; $i < $rows; $i++) {\r
+ if (is_array ($fn)) {\r
+ $obj = $fn[0];\r
+ $method = $fn[1];\r
+ $obj->$method ($rs->_array[$i],$rs);\r
+ } else {\r
+ $fn($rs->_array[$i],$rs);\r
+ }\r
+ \r
+ }\r
+ if (!$rs->EOF) {\r
+ $rs->_currentRow = 0;\r
+ $rs->fields = $rs->_array[0];\r
+ }\r
+ \r
+ return $rs;\r
+}\r
?>
\ No newline at end of file
<?php
/*
-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.
Contributed by Ross Smith (adodb@netebb.com).
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
/*
-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.
Contributed by Ross Smith (adodb@netebb.com).
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
/*
-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.
Contributed by Ross Smith (adodb@netebb.com).
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
/*
-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.
Contributed by Ross Smith (adodb@netebb.com).
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
/*
-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.
Contributed by Ross Smith (adodb@netebb.com).
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
<?php
/*
-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.
Contributed by Ross Smith (adodb@netebb.com).
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
<?php
/*
-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.
Contributed by Ross Smith (adodb@netebb.com).
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
/*
-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.
Contributed by Ross Smith (adodb@netebb.com).
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
/*
-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.
Contributed by Ross Smith (adodb@netebb.com).
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
/*
-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.
Contributed by Ross Smith (adodb@netebb.com).
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
/*
-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.
Contributed by Ross Smith (adodb@netebb.com).
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
$qkey = $conn->qstr($key);
$rs2 =& $conn->UpdateBlob($table, 'sessdata', $val, " sesskey=$qkey", strtoupper($clob));
- $rs = $conn->CompleteTrans();
+ $rs = @$conn->CompleteTrans();
}
<?php
/*
-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.
-<?php
-/*
- V4.93 10 Oct 2006 (c) 2000-2006 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.
- Set tabs to 4 for best viewing.
-
- Latest version of ADODB is available at http://php.weblogs.com/adodb
- ======================================================================
-
- This file provides PHP4 session management using the ADODB database
- wrapper library, using Oracle CLOB's to store data. Contributed by achim.gosse@ddd.de.
-
- Example
- =======
-
- include('adodb.inc.php');
- include('adodb-session.php');
- session_start();
- session_register('AVAR');
- $_SESSION['AVAR'] += 1;
- print "
--- \$_SESSION['AVAR']={$_SESSION['AVAR']}</p>";
-
-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']}</p>";
-
-
- 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 "<h3>Session Error: PHP.INI setting <i>session.gc_maxlifetime</i>not set: $ADODB_SESS_LIFE</h3>";
- $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</p>",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</p>";
- $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).'</p>',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("
--- <b>Garbage Collection</b>: $qry</p>");
- }
- // suggested by Cameron, "GaM3R" <gamr@outworld.cx>
- 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</p>");
- }
- }
-
- 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']}</p>",false);
-}
-
-?>
+<?php\r
+/*\r
+ V4.93 10 Oct 2006 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.\r
+ Released under both BSD license and Lesser GPL library license. \r
+ Whenever there is any discrepancy between the two licenses, \r
+ the BSD license will take precedence.\r
+ Set tabs to 4 for best viewing.\r
+ \r
+ Latest version of ADODB is available at http://php.weblogs.com/adodb\r
+ ======================================================================\r
+ \r
+ This file provides PHP4 session management using the ADODB database\r
+ wrapper library, using Oracle CLOB's to store data. Contributed by achim.gosse@ddd.de.\r
+\r
+ Example\r
+ =======\r
+ \r
+ include('adodb.inc.php');\r
+ include('adodb-session.php');\r
+ session_start();\r
+ session_register('AVAR');\r
+ $_SESSION['AVAR'] += 1;\r
+ print "\r
+-- \$_SESSION['AVAR']={$_SESSION['AVAR']}</p>";\r
+ \r
+To force non-persistent connections, call adodb_session_open first before session_start():\r
+\r
+ include('adodb.inc.php');\r
+ include('adodb-session.php');\r
+ adodb_session_open(false,false,false);\r
+ session_start();\r
+ session_register('AVAR');\r
+ $_SESSION['AVAR'] += 1;\r
+ print "\r
+-- \$_SESSION['AVAR']={$_SESSION['AVAR']}</p>";\r
+\r
+ \r
+ Installation\r
+ ============\r
+ 1. Create this table in your database (syntax might vary depending on your db):\r
+ \r
+ create table sessions (\r
+ SESSKEY char(32) not null,\r
+ EXPIRY int(11) unsigned not null,\r
+ EXPIREREF varchar(64),\r
+ DATA CLOB,\r
+ primary key (sesskey)\r
+ );\r
+\r
+\r
+ 2. Then define the following parameters in this file:\r
+ $ADODB_SESSION_DRIVER='database driver, eg. mysql or ibase';\r
+ $ADODB_SESSION_CONNECT='server to connect to';\r
+ $ADODB_SESSION_USER ='user';\r
+ $ADODB_SESSION_PWD ='password';\r
+ $ADODB_SESSION_DB ='database';\r
+ $ADODB_SESSION_TBL = 'sessions'\r
+ $ADODB_SESSION_USE_LOBS = false; (or, if you wanna use CLOBS (= 'CLOB') or ( = 'BLOB')\r
+ \r
+ 3. Recommended is PHP 4.1.0 or later. There are documented\r
+ session bugs in earlier versions of PHP.\r
+\r
+ 4. If you want to receive notifications when a session expires, then\r
+ you can tag a session with an EXPIREREF, and before the session\r
+ record is deleted, we can call a function that will pass the EXPIREREF\r
+ as the first parameter, and the session key as the second parameter.\r
+ \r
+ To do this, define a notification function, say NotifyFn:\r
+ \r
+ function NotifyFn($expireref, $sesskey)\r
+ {\r
+ }\r
+ \r
+ Then you need to define a global variable $ADODB_SESSION_EXPIRE_NOTIFY.\r
+ This is an array with 2 elements, the first being the name of the variable\r
+ you would like to store in the EXPIREREF field, and the 2nd is the \r
+ notification function's name.\r
+ \r
+ In this example, we want to be notified when a user's session \r
+ has expired, so we store the user id in the global variable $USERID, \r
+ store this value in the EXPIREREF field:\r
+ \r
+ $ADODB_SESSION_EXPIRE_NOTIFY = array('USERID','NotifyFn');\r
+ \r
+ Then when the NotifyFn is called, we are passed the $USERID as the first\r
+ parameter, eg. NotifyFn($userid, $sesskey).\r
+*/\r
+\r
+if (!defined('_ADODB_LAYER')) {\r
+ include (dirname(__FILE__).'/adodb.inc.php');\r
+}\r
+\r
+if (!defined('ADODB_SESSION')) {\r
+\r
+ define('ADODB_SESSION',1);\r
+ \r
+ /* if database time and system time is difference is greater than this, then give warning */\r
+ define('ADODB_SESSION_SYNCH_SECS',60); \r
+\r
+/****************************************************************************************\\r
+ Global definitions\r
+\****************************************************************************************/\r
+GLOBAL $ADODB_SESSION_CONNECT, \r
+ $ADODB_SESSION_DRIVER,\r
+ $ADODB_SESSION_USER,\r
+ $ADODB_SESSION_PWD,\r
+ $ADODB_SESSION_DB,\r
+ $ADODB_SESS_CONN,\r
+ $ADODB_SESS_LIFE,\r
+ $ADODB_SESS_DEBUG,\r
+ $ADODB_SESSION_EXPIRE_NOTIFY,\r
+ $ADODB_SESSION_CRC,\r
+ $ADODB_SESSION_USE_LOBS,\r
+ $ADODB_SESSION_TBL;\r
+ \r
+ if (!isset($ADODB_SESSION_USE_LOBS)) $ADODB_SESSION_USE_LOBS = 'CLOB';\r
+ \r
+ $ADODB_SESS_LIFE = ini_get('session.gc_maxlifetime');\r
+ if ($ADODB_SESS_LIFE <= 1) {\r
+ // bug in PHP 4.0.3 pl 1 -- how about other versions?\r
+ //print "<h3>Session Error: PHP.INI setting <i>session.gc_maxlifetime</i>not set: $ADODB_SESS_LIFE</h3>";\r
+ $ADODB_SESS_LIFE=1440;\r
+ }\r
+ $ADODB_SESSION_CRC = false;\r
+ //$ADODB_SESS_DEBUG = true;\r
+ \r
+ //////////////////////////////////\r
+ /* SET THE FOLLOWING PARAMETERS */\r
+ //////////////////////////////////\r
+ \r
+ if (empty($ADODB_SESSION_DRIVER)) {\r
+ $ADODB_SESSION_DRIVER='mysql';\r
+ $ADODB_SESSION_CONNECT='localhost';\r
+ $ADODB_SESSION_USER ='root';\r
+ $ADODB_SESSION_PWD ='';\r
+ $ADODB_SESSION_DB ='xphplens_2';\r
+ }\r
+ \r
+ if (empty($ADODB_SESSION_EXPIRE_NOTIFY)) {\r
+ $ADODB_SESSION_EXPIRE_NOTIFY = false;\r
+ }\r
+ // Made table name configurable - by David Johnson djohnson@inpro.net\r
+ if (empty($ADODB_SESSION_TBL)){\r
+ $ADODB_SESSION_TBL = 'sessions';\r
+ }\r
+ \r
+\r
+ // defaulting $ADODB_SESSION_USE_LOBS\r
+ if (!isset($ADODB_SESSION_USE_LOBS) || empty($ADODB_SESSION_USE_LOBS)) {\r
+ $ADODB_SESSION_USE_LOBS = false;\r
+ }\r
+\r
+ /*\r
+ $ADODB_SESS['driver'] = $ADODB_SESSION_DRIVER;\r
+ $ADODB_SESS['connect'] = $ADODB_SESSION_CONNECT;\r
+ $ADODB_SESS['user'] = $ADODB_SESSION_USER;\r
+ $ADODB_SESS['pwd'] = $ADODB_SESSION_PWD;\r
+ $ADODB_SESS['db'] = $ADODB_SESSION_DB;\r
+ $ADODB_SESS['life'] = $ADODB_SESS_LIFE;\r
+ $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG;\r
+ \r
+ $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG;\r
+ $ADODB_SESS['table'] = $ADODB_SESS_TBL;\r
+ */\r
+ \r
+/****************************************************************************************\\r
+ Create the connection to the database. \r
+ \r
+ If $ADODB_SESS_CONN already exists, reuse that connection\r
+\****************************************************************************************/\r
+function adodb_sess_open($save_path, $session_name,$persist=true) \r
+{\r
+GLOBAL $ADODB_SESS_CONN;\r
+ if (isset($ADODB_SESS_CONN)) return true;\r
+ \r
+GLOBAL $ADODB_SESSION_CONNECT, \r
+ $ADODB_SESSION_DRIVER,\r
+ $ADODB_SESSION_USER,\r
+ $ADODB_SESSION_PWD,\r
+ $ADODB_SESSION_DB,\r
+ $ADODB_SESS_DEBUG;\r
+ \r
+ // cannot use & below - do not know why...\r
+ $ADODB_SESS_CONN = ADONewConnection($ADODB_SESSION_DRIVER);\r
+ if (!empty($ADODB_SESS_DEBUG)) {\r
+ $ADODB_SESS_CONN->debug = true;\r
+ ADOConnection::outp( " conn=$ADODB_SESSION_CONNECT user=$ADODB_SESSION_USER pwd=$ADODB_SESSION_PWD db=$ADODB_SESSION_DB ");\r
+ }\r
+ if ($persist) $ok = $ADODB_SESS_CONN->PConnect($ADODB_SESSION_CONNECT,\r
+ $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB);\r
+ else $ok = $ADODB_SESS_CONN->Connect($ADODB_SESSION_CONNECT,\r
+ $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB);\r
+ \r
+ if (!$ok) ADOConnection::outp( "\r
+-- Session: connection failed</p>",false);\r
+}\r
+\r
+/****************************************************************************************\\r
+ Close the connection\r
+\****************************************************************************************/\r
+function adodb_sess_close() \r
+{\r
+global $ADODB_SESS_CONN;\r
+\r
+ if ($ADODB_SESS_CONN) $ADODB_SESS_CONN->Close();\r
+ return true;\r
+}\r
+\r
+/****************************************************************************************\\r
+ Slurp in the session variables and return the serialized string\r
+\****************************************************************************************/\r
+function adodb_sess_read($key) \r
+{\r
+global $ADODB_SESS_CONN,$ADODB_SESSION_TBL,$ADODB_SESSION_CRC;\r
+\r
+ $rs = $ADODB_SESS_CONN->Execute("SELECT data FROM $ADODB_SESSION_TBL WHERE sesskey = '$key' AND expiry >= " . time());\r
+ if ($rs) {\r
+ if ($rs->EOF) {\r
+ $v = '';\r
+ } else \r
+ $v = rawurldecode(reset($rs->fields));\r
+ \r
+ $rs->Close();\r
+ \r
+ // new optimization adodb 2.1\r
+ $ADODB_SESSION_CRC = strlen($v).crc32($v);\r
+ \r
+ return $v;\r
+ }\r
+ \r
+ return ''; // thx to Jorma Tuomainen, webmaster#wizactive.com\r
+}\r
+\r
+/****************************************************************************************\\r
+ Write the serialized data to a database.\r
+ \r
+ If the data has not been modified since adodb_sess_read(), we do not write.\r
+\****************************************************************************************/\r
+function adodb_sess_write($key, $val) \r
+{\r
+ global\r
+ $ADODB_SESS_CONN, \r
+ $ADODB_SESS_LIFE, \r
+ $ADODB_SESSION_TBL,\r
+ $ADODB_SESS_DEBUG, \r
+ $ADODB_SESSION_CRC,\r
+ $ADODB_SESSION_EXPIRE_NOTIFY,\r
+ $ADODB_SESSION_DRIVER, // added\r
+ $ADODB_SESSION_USE_LOBS; // added\r
+\r
+ $expiry = time() + $ADODB_SESS_LIFE;\r
+ \r
+ // crc32 optimization since adodb 2.1\r
+ // now we only update expiry date, thx to sebastian thom in adodb 2.32\r
+ if ($ADODB_SESSION_CRC !== false && $ADODB_SESSION_CRC == strlen($val).crc32($val)) {\r
+ if ($ADODB_SESS_DEBUG) echo "\r
+-- Session: Only updating date - crc32 not changed</p>";\r
+ $qry = "UPDATE $ADODB_SESSION_TBL SET expiry=$expiry WHERE sesskey='$key' AND expiry >= " . time();\r
+ $rs = $ADODB_SESS_CONN->Execute($qry); \r
+ return true;\r
+ }\r
+ $val = rawurlencode($val);\r
+ \r
+ $arr = array('sesskey' => $key, 'expiry' => $expiry, 'data' => $val);\r
+ if ($ADODB_SESSION_EXPIRE_NOTIFY) {\r
+ $var = reset($ADODB_SESSION_EXPIRE_NOTIFY);\r
+ global $$var;\r
+ $arr['expireref'] = $$var;\r
+ }\r
+\r
+ \r
+ if ($ADODB_SESSION_USE_LOBS === false) { // no lobs, simply use replace()\r
+ $rs = $ADODB_SESS_CONN->Replace($ADODB_SESSION_TBL,$arr, 'sesskey',$autoQuote = true);\r
+ if (!$rs) {\r
+ $err = $ADODB_SESS_CONN->ErrorMsg();\r
+ }\r
+ } else {\r
+ // what value shall we insert/update for lob row?\r
+ switch ($ADODB_SESSION_DRIVER) {\r
+ // empty_clob or empty_lob for oracle dbs\r
+ case "oracle":\r
+ case "oci8":\r
+ case "oci8po":\r
+ case "oci805":\r
+ $lob_value = sprintf("empty_%s()", strtolower($ADODB_SESSION_USE_LOBS));\r
+ break;\r
+\r
+ // null for all other\r
+ default:\r
+ $lob_value = "null";\r
+ break;\r
+ }\r
+\r
+ // do we insert or update? => as for sesskey\r
+ $res = $ADODB_SESS_CONN->Execute("select count(*) as cnt from $ADODB_SESSION_TBL where sesskey = '$key'");\r
+ if ($res && reset($res->fields) > 0) {\r
+ $qry = sprintf("update %s set expiry = %d, data = %s where sesskey = '%s'", $ADODB_SESSION_TBL, $expiry, $lob_value, $key);\r
+ } else {\r
+ // insert\r
+ $qry = sprintf("insert into %s (sesskey, expiry, data) values ('%s', %d, %s)", $ADODB_SESSION_TBL, $key, $expiry, $lob_value);\r
+ }\r
+\r
+ $err = "";\r
+ $rs1 = $ADODB_SESS_CONN->Execute($qry);\r
+ if (!$rs1) {\r
+ $err .= $ADODB_SESS_CONN->ErrorMsg()."\n";\r
+ }\r
+ $rs2 = $ADODB_SESS_CONN->UpdateBlob($ADODB_SESSION_TBL, 'data', $val, "sesskey='$key'", strtoupper($ADODB_SESSION_USE_LOBS));\r
+ if (!$rs2) {\r
+ $err .= $ADODB_SESS_CONN->ErrorMsg()."\n";\r
+ }\r
+ $rs = ($rs1 && $rs2) ? true : false;\r
+ }\r
+\r
+ if (!$rs) {\r
+ ADOConnection::outp( '\r
+-- Session Replace: '.nl2br($err).'</p>',false);\r
+ } else {\r
+ // bug in access driver (could be odbc?) means that info is not commited\r
+ // properly unless select statement executed in Win2000\r
+ if ($ADODB_SESS_CONN->databaseType == 'access') \r
+ $rs = $ADODB_SESS_CONN->Execute("select sesskey from $ADODB_SESSION_TBL WHERE sesskey='$key'");\r
+ }\r
+ return !empty($rs);\r
+}\r
+\r
+function adodb_sess_destroy($key) \r
+{\r
+ global $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY;\r
+ \r
+ if ($ADODB_SESSION_EXPIRE_NOTIFY) {\r
+ reset($ADODB_SESSION_EXPIRE_NOTIFY);\r
+ $fn = next($ADODB_SESSION_EXPIRE_NOTIFY);\r
+ $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM);\r
+ $rs = $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE sesskey='$key'");\r
+ $ADODB_SESS_CONN->SetFetchMode($savem);\r
+ if ($rs) {\r
+ $ADODB_SESS_CONN->BeginTrans();\r
+ while (!$rs->EOF) {\r
+ $ref = $rs->fields[0];\r
+ $key = $rs->fields[1];\r
+ $fn($ref,$key);\r
+ $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'");\r
+ $rs->MoveNext();\r
+ }\r
+ $ADODB_SESS_CONN->CommitTrans();\r
+ }\r
+ } else {\r
+ $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE sesskey = '$key'";\r
+ $rs = $ADODB_SESS_CONN->Execute($qry);\r
+ }\r
+ return $rs ? true : false;\r
+}\r
+\r
+function adodb_sess_gc($maxlifetime) \r
+{\r
+ global $ADODB_SESS_DEBUG, $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY;\r
+ \r
+ if ($ADODB_SESSION_EXPIRE_NOTIFY) {\r
+ reset($ADODB_SESSION_EXPIRE_NOTIFY);\r
+ $fn = next($ADODB_SESSION_EXPIRE_NOTIFY);\r
+ $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM);\r
+ $t = time();\r
+ $rs = $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE expiry < $t");\r
+ $ADODB_SESS_CONN->SetFetchMode($savem);\r
+ if ($rs) {\r
+ $ADODB_SESS_CONN->BeginTrans();\r
+ while (!$rs->EOF) {\r
+ $ref = $rs->fields[0];\r
+ $key = $rs->fields[1];\r
+ $fn($ref,$key);\r
+ $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'");\r
+ $rs->MoveNext();\r
+ }\r
+ $rs->Close();\r
+ \r
+ //$ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE expiry < $t");\r
+ $ADODB_SESS_CONN->CommitTrans();\r
+ \r
+ }\r
+ } else {\r
+ $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE expiry < " . time());\r
+ \r
+ if ($ADODB_SESS_DEBUG) ADOConnection::outp("\r
+-- <b>Garbage Collection</b>: $qry</p>");\r
+ }\r
+ // suggested by Cameron, "GaM3R" <gamr@outworld.cx>\r
+ if (defined('ADODB_SESSION_OPTIMIZE')) {\r
+ global $ADODB_SESSION_DRIVER;\r
+ \r
+ switch( $ADODB_SESSION_DRIVER ) {\r
+ case 'mysql':\r
+ case 'mysqlt':\r
+ $opt_qry = 'OPTIMIZE TABLE '.$ADODB_SESSION_TBL;\r
+ break;\r
+ case 'postgresql':\r
+ case 'postgresql7':\r
+ $opt_qry = 'VACUUM '.$ADODB_SESSION_TBL; \r
+ break;\r
+ }\r
+ if (!empty($opt_qry)) {\r
+ $ADODB_SESS_CONN->Execute($opt_qry);\r
+ }\r
+ }\r
+ if ($ADODB_SESS_CONN->dataProvider === 'oci8') $sql = 'select TO_CHAR('.($ADODB_SESS_CONN->sysTimeStamp).', \'RRRR-MM-DD HH24:MI:SS\') from '. $ADODB_SESSION_TBL;\r
+ else $sql = 'select '.$ADODB_SESS_CONN->sysTimeStamp.' from '. $ADODB_SESSION_TBL;\r
+ \r
+ $rs =& $ADODB_SESS_CONN->SelectLimit($sql,1);\r
+ if ($rs && !$rs->EOF) {\r
+ \r
+ $dbts = reset($rs->fields);\r
+ $rs->Close();\r
+ $dbt = $ADODB_SESS_CONN->UnixTimeStamp($dbts);\r
+ $t = time();\r
+ if (abs($dbt - $t) >= ADODB_SESSION_SYNCH_SECS) {\r
+ $msg = \r
+ __FILE__.": Server time for webserver {$_SERVER['HTTP_HOST']} not in synch with database: database=$dbt ($dbts), webserver=$t (diff=".(abs($dbt-$t)/3600)." hrs)";\r
+ error_log($msg);\r
+ if ($ADODB_SESS_DEBUG) ADOConnection::outp("\r
+-- $msg</p>");\r
+ }\r
+ }\r
+ \r
+ return true;\r
+}\r
+\r
+session_module_name('user'); \r
+session_set_save_handler(\r
+ "adodb_sess_open",\r
+ "adodb_sess_close",\r
+ "adodb_sess_read",\r
+ "adodb_sess_write",\r
+ "adodb_sess_destroy",\r
+ "adodb_sess_gc");\r
+}\r
+\r
+/* TEST SCRIPT -- UNCOMMENT */\r
+\r
+if (0) {\r
+\r
+ session_start();\r
+ session_register('AVAR');\r
+ $_SESSION['AVAR'] += 1;\r
+ ADOConnection::outp( "\r
+-- \$_SESSION['AVAR']={$_SESSION['AVAR']}</p>",false);\r
+}\r
+\r
+?>\r
-<?php
-/*
-V4.93 10 Oct 2006 (c) 2000-2006 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.
- Set tabs to 4 for best viewing.
-
- Latest version of ADODB is available at http://php.weblogs.com/adodb
- ======================================================================
-
- This file provides PHP4 session management using the ADODB database
-wrapper library.
-
- Example
- =======
-
- include('adodb.inc.php');
- include('adodb-session.php');
- session_start();
- session_register('AVAR');
- $_SESSION['AVAR'] += 1;
- print "
--- \$_SESSION['AVAR']={$_SESSION['AVAR']}</p>";
-
-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']}</p>";
-
-
- 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 "<h3>Session Error: PHP.INI setting <i>session.gc_maxlifetime</i>not set: $ADODB_SESS_LIFE</h3>";
- $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</p>",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</p>";
- $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().'</p>',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("
--- <b>Garbage Collection</b>: $qry</p>");
- }
- // suggested by Cameron, "GaM3R" <gamr@outworld.cx>
- 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</p>");
- }
- }
-
- 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']}</p>",false);
-}
-
+<?php\r
+/*\r
+V4.93 10 Oct 2006 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.\r
+ Released under both BSD license and Lesser GPL library license. \r
+ Whenever there is any discrepancy between the two licenses, \r
+ the BSD license will take precedence.\r
+ Set tabs to 4 for best viewing.\r
+ \r
+ Latest version of ADODB is available at http://php.weblogs.com/adodb\r
+ ======================================================================\r
+ \r
+ This file provides PHP4 session management using the ADODB database\r
+wrapper library.\r
+ \r
+ Example\r
+ =======\r
+ \r
+ include('adodb.inc.php');\r
+ include('adodb-session.php');\r
+ session_start();\r
+ session_register('AVAR');\r
+ $_SESSION['AVAR'] += 1;\r
+ print "\r
+-- \$_SESSION['AVAR']={$_SESSION['AVAR']}</p>";\r
+ \r
+To force non-persistent connections, call adodb_session_open first before session_start():\r
+\r
+ include('adodb.inc.php');\r
+ include('adodb-session.php');\r
+ adodb_sess_open(false,false,false);\r
+ session_start();\r
+ session_register('AVAR');\r
+ $_SESSION['AVAR'] += 1;\r
+ print "\r
+-- \$_SESSION['AVAR']={$_SESSION['AVAR']}</p>";\r
+\r
+ \r
+ Installation\r
+ ============\r
+ 1. Create this table in your database (syntax might vary depending on your db):\r
+ \r
+ create table sessions (\r
+ SESSKEY char(32) not null,\r
+ EXPIRY int(11) unsigned not null,\r
+ EXPIREREF varchar(64),\r
+ DATA text not null,\r
+ primary key (sesskey)\r
+ );\r
+ \r
+ For oracle:\r
+ create table sessions (\r
+ SESSKEY char(32) not null,\r
+ EXPIRY DECIMAL(16) not null,\r
+ EXPIREREF varchar(64),\r
+ DATA varchar(4000) not null,\r
+ primary key (sesskey)\r
+ );\r
+\r
+\r
+ 2. Then define the following parameters. You can either modify\r
+ this file, or define them before this file is included:\r
+ \r
+ $ADODB_SESSION_DRIVER='database driver, eg. mysql or ibase';\r
+ $ADODB_SESSION_CONNECT='server to connect to';\r
+ $ADODB_SESSION_USER ='user';\r
+ $ADODB_SESSION_PWD ='password';\r
+ $ADODB_SESSION_DB ='database';\r
+ $ADODB_SESSION_TBL = 'sessions'\r
+ \r
+ 3. Recommended is PHP 4.1.0 or later. There are documented\r
+ session bugs in earlier versions of PHP.\r
+\r
+ 4. If you want to receive notifications when a session expires, then\r
+ you can tag a session with an EXPIREREF, and before the session\r
+ record is deleted, we can call a function that will pass the EXPIREREF\r
+ as the first parameter, and the session key as the second parameter.\r
+ \r
+ To do this, define a notification function, say NotifyFn:\r
+ \r
+ function NotifyFn($expireref, $sesskey)\r
+ {\r
+ }\r
+ \r
+ Then you need to define a global variable $ADODB_SESSION_EXPIRE_NOTIFY.\r
+ This is an array with 2 elements, the first being the name of the variable\r
+ you would like to store in the EXPIREREF field, and the 2nd is the \r
+ notification function's name.\r
+ \r
+ In this example, we want to be notified when a user's session \r
+ has expired, so we store the user id in the global variable $USERID, \r
+ store this value in the EXPIREREF field:\r
+ \r
+ $ADODB_SESSION_EXPIRE_NOTIFY = array('USERID','NotifyFn');\r
+ \r
+ Then when the NotifyFn is called, we are passed the $USERID as the first\r
+ parameter, eg. NotifyFn($userid, $sesskey).\r
+*/\r
+\r
+if (!defined('_ADODB_LAYER')) {\r
+ include (dirname(__FILE__).'/adodb.inc.php');\r
+}\r
+\r
+if (!defined('ADODB_SESSION')) {\r
+\r
+ define('ADODB_SESSION',1);\r
+ \r
+ /* if database time and system time is difference is greater than this, then give warning */\r
+ define('ADODB_SESSION_SYNCH_SECS',60); \r
+\r
+ /*\r
+ Thanks Joe Li. See http://phplens.com/lens/lensforum/msgs.php?id=11487&x=1\r
+*/\r
+function adodb_session_regenerate_id() \r
+{\r
+ $conn =& ADODB_Session::_conn();\r
+ if (!$conn) return false;\r
+\r
+ $old_id = session_id();\r
+ if (function_exists('session_regenerate_id')) {\r
+ session_regenerate_id();\r
+ } else {\r
+ session_id(md5(uniqid(rand(), true)));\r
+ $ck = session_get_cookie_params();\r
+ setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']);\r
+ //@session_start();\r
+ }\r
+ $new_id = session_id();\r
+ $ok =& $conn->Execute('UPDATE '. ADODB_Session::table(). ' SET sesskey='. $conn->qstr($new_id). ' WHERE sesskey='.$conn->qstr($old_id));\r
+ \r
+ /* it is possible that the update statement fails due to a collision */\r
+ if (!$ok) {\r
+ session_id($old_id);\r
+ if (empty($ck)) $ck = session_get_cookie_params();\r
+ setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']);\r
+ return false;\r
+ }\r
+ \r
+ return true;\r
+}\r
+\r
+/****************************************************************************************\\r
+ Global definitions\r
+\****************************************************************************************/\r
+GLOBAL $ADODB_SESSION_CONNECT, \r
+ $ADODB_SESSION_DRIVER,\r
+ $ADODB_SESSION_USER,\r
+ $ADODB_SESSION_PWD,\r
+ $ADODB_SESSION_DB,\r
+ $ADODB_SESS_CONN,\r
+ $ADODB_SESS_LIFE,\r
+ $ADODB_SESS_DEBUG,\r
+ $ADODB_SESSION_EXPIRE_NOTIFY,\r
+ $ADODB_SESSION_CRC,\r
+ $ADODB_SESSION_TBL;\r
+ \r
+ \r
+ $ADODB_SESS_LIFE = ini_get('session.gc_maxlifetime');\r
+ if ($ADODB_SESS_LIFE <= 1) {\r
+ // bug in PHP 4.0.3 pl 1 -- how about other versions?\r
+ //print "<h3>Session Error: PHP.INI setting <i>session.gc_maxlifetime</i>not set: $ADODB_SESS_LIFE</h3>";\r
+ $ADODB_SESS_LIFE=1440;\r
+ }\r
+ $ADODB_SESSION_CRC = false;\r
+ //$ADODB_SESS_DEBUG = true;\r
+ \r
+ //////////////////////////////////\r
+ /* SET THE FOLLOWING PARAMETERS */\r
+ //////////////////////////////////\r
+ \r
+ if (empty($ADODB_SESSION_DRIVER)) {\r
+ $ADODB_SESSION_DRIVER='mysql';\r
+ $ADODB_SESSION_CONNECT='localhost';\r
+ $ADODB_SESSION_USER ='root';\r
+ $ADODB_SESSION_PWD ='';\r
+ $ADODB_SESSION_DB ='xphplens_2';\r
+ }\r
+ \r
+ if (empty($ADODB_SESSION_EXPIRE_NOTIFY)) {\r
+ $ADODB_SESSION_EXPIRE_NOTIFY = false;\r
+ }\r
+ // Made table name configurable - by David Johnson djohnson@inpro.net\r
+ if (empty($ADODB_SESSION_TBL)){\r
+ $ADODB_SESSION_TBL = 'sessions';\r
+ }\r
+ \r
+ /*\r
+ $ADODB_SESS['driver'] = $ADODB_SESSION_DRIVER;\r
+ $ADODB_SESS['connect'] = $ADODB_SESSION_CONNECT;\r
+ $ADODB_SESS['user'] = $ADODB_SESSION_USER;\r
+ $ADODB_SESS['pwd'] = $ADODB_SESSION_PWD;\r
+ $ADODB_SESS['db'] = $ADODB_SESSION_DB;\r
+ $ADODB_SESS['life'] = $ADODB_SESS_LIFE;\r
+ $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG;\r
+ \r
+ $ADODB_SESS['debug'] = $ADODB_SESS_DEBUG;\r
+ $ADODB_SESS['table'] = $ADODB_SESS_TBL;\r
+ */\r
+ \r
+/****************************************************************************************\\r
+ Create the connection to the database. \r
+ \r
+ If $ADODB_SESS_CONN already exists, reuse that connection\r
+\****************************************************************************************/\r
+function adodb_sess_open($save_path, $session_name,$persist=true) \r
+{\r
+GLOBAL $ADODB_SESS_CONN;\r
+ if (isset($ADODB_SESS_CONN)) return true;\r
+ \r
+GLOBAL $ADODB_SESSION_CONNECT, \r
+ $ADODB_SESSION_DRIVER,\r
+ $ADODB_SESSION_USER,\r
+ $ADODB_SESSION_PWD,\r
+ $ADODB_SESSION_DB,\r
+ $ADODB_SESS_DEBUG;\r
+ \r
+ // cannot use & below - do not know why...\r
+ $ADODB_SESS_CONN = ADONewConnection($ADODB_SESSION_DRIVER);\r
+ if (!empty($ADODB_SESS_DEBUG)) {\r
+ $ADODB_SESS_CONN->debug = true;\r
+ ADOConnection::outp( " conn=$ADODB_SESSION_CONNECT user=$ADODB_SESSION_USER pwd=$ADODB_SESSION_PWD db=$ADODB_SESSION_DB ");\r
+ }\r
+ if ($persist) $ok = $ADODB_SESS_CONN->PConnect($ADODB_SESSION_CONNECT,\r
+ $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB);\r
+ else $ok = $ADODB_SESS_CONN->Connect($ADODB_SESSION_CONNECT,\r
+ $ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB);\r
+ \r
+ if (!$ok) ADOConnection::outp( "\r
+-- Session: connection failed</p>",false);\r
+}\r
+\r
+/****************************************************************************************\\r
+ Close the connection\r
+\****************************************************************************************/\r
+function adodb_sess_close() \r
+{\r
+global $ADODB_SESS_CONN;\r
+\r
+ if ($ADODB_SESS_CONN) $ADODB_SESS_CONN->Close();\r
+ return true;\r
+}\r
+\r
+/****************************************************************************************\\r
+ Slurp in the session variables and return the serialized string\r
+\****************************************************************************************/\r
+function adodb_sess_read($key) \r
+{\r
+global $ADODB_SESS_CONN,$ADODB_SESSION_TBL,$ADODB_SESSION_CRC;\r
+\r
+ $rs = $ADODB_SESS_CONN->Execute("SELECT data FROM $ADODB_SESSION_TBL WHERE sesskey = '$key' AND expiry >= " . time());\r
+ if ($rs) {\r
+ if ($rs->EOF) {\r
+ $v = '';\r
+ } else \r
+ $v = rawurldecode(reset($rs->fields));\r
+ \r
+ $rs->Close();\r
+ \r
+ // new optimization adodb 2.1\r
+ $ADODB_SESSION_CRC = strlen($v).crc32($v);\r
+ \r
+ return $v;\r
+ }\r
+ \r
+ return ''; // thx to Jorma Tuomainen, webmaster#wizactive.com\r
+}\r
+\r
+/****************************************************************************************\\r
+ Write the serialized data to a database.\r
+ \r
+ If the data has not been modified since adodb_sess_read(), we do not write.\r
+\****************************************************************************************/\r
+function adodb_sess_write($key, $val) \r
+{\r
+ global\r
+ $ADODB_SESS_CONN, \r
+ $ADODB_SESS_LIFE, \r
+ $ADODB_SESSION_TBL,\r
+ $ADODB_SESS_DEBUG, \r
+ $ADODB_SESSION_CRC,\r
+ $ADODB_SESSION_EXPIRE_NOTIFY;\r
+\r
+ $expiry = time() + $ADODB_SESS_LIFE;\r
+ \r
+ // crc32 optimization since adodb 2.1\r
+ // now we only update expiry date, thx to sebastian thom in adodb 2.32\r
+ if ($ADODB_SESSION_CRC !== false && $ADODB_SESSION_CRC == strlen($val).crc32($val)) {\r
+ if ($ADODB_SESS_DEBUG) echo "\r
+-- Session: Only updating date - crc32 not changed</p>";\r
+ $qry = "UPDATE $ADODB_SESSION_TBL SET expiry=$expiry WHERE sesskey='$key' AND expiry >= " . time();\r
+ $rs = $ADODB_SESS_CONN->Execute($qry); \r
+ return true;\r
+ }\r
+ $val = rawurlencode($val);\r
+ \r
+ $arr = array('sesskey' => $key, 'expiry' => $expiry, 'data' => $val);\r
+ if ($ADODB_SESSION_EXPIRE_NOTIFY) {\r
+ $var = reset($ADODB_SESSION_EXPIRE_NOTIFY);\r
+ global $$var;\r
+ $arr['expireref'] = $$var;\r
+ }\r
+ $rs = $ADODB_SESS_CONN->Replace($ADODB_SESSION_TBL,$arr,\r
+ 'sesskey',$autoQuote = true);\r
+ \r
+ if (!$rs) {\r
+ ADOConnection::outp( '\r
+-- Session Replace: '.$ADODB_SESS_CONN->ErrorMsg().'</p>',false);\r
+ } else {\r
+ // bug in access driver (could be odbc?) means that info is not commited\r
+ // properly unless select statement executed in Win2000\r
+ if ($ADODB_SESS_CONN->databaseType == 'access') \r
+ $rs = $ADODB_SESS_CONN->Execute("select sesskey from $ADODB_SESSION_TBL WHERE sesskey='$key'");\r
+ }\r
+ return !empty($rs);\r
+}\r
+\r
+function adodb_sess_destroy($key) \r
+{\r
+ global $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY;\r
+ \r
+ if ($ADODB_SESSION_EXPIRE_NOTIFY) {\r
+ reset($ADODB_SESSION_EXPIRE_NOTIFY);\r
+ $fn = next($ADODB_SESSION_EXPIRE_NOTIFY);\r
+ $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM);\r
+ $rs = $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE sesskey='$key'");\r
+ $ADODB_SESS_CONN->SetFetchMode($savem);\r
+ if ($rs) {\r
+ $ADODB_SESS_CONN->BeginTrans();\r
+ while (!$rs->EOF) {\r
+ $ref = $rs->fields[0];\r
+ $key = $rs->fields[1];\r
+ $fn($ref,$key);\r
+ $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'");\r
+ $rs->MoveNext();\r
+ }\r
+ $ADODB_SESS_CONN->CommitTrans();\r
+ }\r
+ } else {\r
+ $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE sesskey = '$key'";\r
+ $rs = $ADODB_SESS_CONN->Execute($qry);\r
+ }\r
+ return $rs ? true : false;\r
+}\r
+\r
+function adodb_sess_gc($maxlifetime) \r
+{\r
+ global $ADODB_SESS_DEBUG, $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY;\r
+ \r
+ if ($ADODB_SESSION_EXPIRE_NOTIFY) {\r
+ reset($ADODB_SESSION_EXPIRE_NOTIFY);\r
+ $fn = next($ADODB_SESSION_EXPIRE_NOTIFY);\r
+ $savem = $ADODB_SESS_CONN->SetFetchMode(ADODB_FETCH_NUM);\r
+ $t = time();\r
+ $rs =& $ADODB_SESS_CONN->Execute("SELECT expireref,sesskey FROM $ADODB_SESSION_TBL WHERE expiry < $t");\r
+ $ADODB_SESS_CONN->SetFetchMode($savem);\r
+ if ($rs) {\r
+ $ADODB_SESS_CONN->BeginTrans();\r
+ while (!$rs->EOF) {\r
+ $ref = $rs->fields[0];\r
+ $key = $rs->fields[1];\r
+ $fn($ref,$key);\r
+ $del = $ADODB_SESS_CONN->Execute("DELETE FROM $ADODB_SESSION_TBL WHERE sesskey='$key'");\r
+ $rs->MoveNext();\r
+ }\r
+ $rs->Close();\r
+ \r
+ $ADODB_SESS_CONN->CommitTrans();\r
+ \r
+ }\r
+ } else {\r
+ $qry = "DELETE FROM $ADODB_SESSION_TBL WHERE expiry < " . time();\r
+ $ADODB_SESS_CONN->Execute($qry);\r
+ \r
+ if ($ADODB_SESS_DEBUG) ADOConnection::outp("\r
+-- <b>Garbage Collection</b>: $qry</p>");\r
+ }\r
+ // suggested by Cameron, "GaM3R" <gamr@outworld.cx>\r
+ if (defined('ADODB_SESSION_OPTIMIZE')) {\r
+ global $ADODB_SESSION_DRIVER;\r
+ \r
+ switch( $ADODB_SESSION_DRIVER ) {\r
+ case 'mysql':\r
+ case 'mysqlt':\r
+ $opt_qry = 'OPTIMIZE TABLE '.$ADODB_SESSION_TBL;\r
+ break;\r
+ case 'postgresql':\r
+ case 'postgresql7':\r
+ $opt_qry = 'VACUUM '.$ADODB_SESSION_TBL; \r
+ break;\r
+ }\r
+ if (!empty($opt_qry)) {\r
+ $ADODB_SESS_CONN->Execute($opt_qry);\r
+ }\r
+ }\r
+ if ($ADODB_SESS_CONN->dataProvider === 'oci8') $sql = 'select TO_CHAR('.($ADODB_SESS_CONN->sysTimeStamp).', \'RRRR-MM-DD HH24:MI:SS\') from '. $ADODB_SESSION_TBL;\r
+ else $sql = 'select '.$ADODB_SESS_CONN->sysTimeStamp.' from '. $ADODB_SESSION_TBL;\r
+ \r
+ $rs =& $ADODB_SESS_CONN->SelectLimit($sql,1);\r
+ if ($rs && !$rs->EOF) {\r
+ \r
+ $dbts = reset($rs->fields);\r
+ $rs->Close();\r
+ $dbt = $ADODB_SESS_CONN->UnixTimeStamp($dbts);\r
+ $t = time();\r
+ \r
+ if (abs($dbt - $t) >= ADODB_SESSION_SYNCH_SECS) {\r
+ \r
+ $msg = \r
+ __FILE__.": Server time for webserver {$_SERVER['HTTP_HOST']} not in synch with database: database=$dbt ($dbts), webserver=$t (diff=".(abs($dbt-$t)/3600)." hrs)";\r
+ error_log($msg);\r
+ if ($ADODB_SESS_DEBUG) ADOConnection::outp("\r
+-- $msg</p>");\r
+ }\r
+ }\r
+ \r
+ return true;\r
+}\r
+\r
+session_module_name('user'); \r
+session_set_save_handler(\r
+ "adodb_sess_open",\r
+ "adodb_sess_close",\r
+ "adodb_sess_read",\r
+ "adodb_sess_write",\r
+ "adodb_sess_destroy",\r
+ "adodb_sess_gc");\r
+}\r
+\r
+/* TEST SCRIPT -- UNCOMMENT */\r
+\r
+if (0) {\r
+\r
+ session_start();\r
+ session_register('AVAR');\r
+ $_SESSION['AVAR'] += 1;\r
+ ADOConnection::outp( "\r
+-- \$_SESSION['AVAR']={$_SESSION['AVAR']}</p>",false);\r
+}\r
+\r
?>
\ No newline at end of file
-<?php
-
-/**
- * @version V4.93 10 Oct 2006 (c) 2000-2006 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.
- *
- * Code to export recordsets in several formats:
- *
- * AS VARIABLE
- * $s = rs2csv($rs); # comma-separated values
- * $s = rs2tab($rs); # tab delimited
- *
- * TO A FILE
- * $f = fopen($path,'w');
- * rs2csvfile($rs,$f);
- * fclose($f);
- *
- * TO STDOUT
- * rs2csvout($rs);
- */
-
-// returns a recordset as a csv string
-function rs2csv(&$rs,$addtitles=true)
-{
- return _adodb_export($rs,',',',',false,$addtitles);
-}
-
-// writes recordset to csv file
-function rs2csvfile(&$rs,$fp,$addtitles=true)
-{
- _adodb_export($rs,',',',',$fp,$addtitles);
-}
-
-// write recordset as csv string to stdout
-function rs2csvout(&$rs,$addtitles=true)
-{
- $fp = fopen('php://stdout','wb');
- _adodb_export($rs,',',',',true,$addtitles);
- fclose($fp);
-}
-
-function rs2tab(&$rs,$addtitles=true)
-{
- return _adodb_export($rs,"\t",',',false,$addtitles);
-}
-
-// to file pointer
-function rs2tabfile(&$rs,$fp,$addtitles=true)
-{
- _adodb_export($rs,"\t",',',$fp,$addtitles);
-}
-
-// to stdout
-function rs2tabout(&$rs,$addtitles=true)
-{
- $fp = fopen('php://stdout','wb');
- _adodb_export($rs,"\t",' ',true,$addtitles);
- if ($fp) fclose($fp);
-}
-
-function _adodb_export(&$rs,$sep,$sepreplace,$fp=false,$addtitles=true,$quote = '"',$escquote = '"',$replaceNewLine = ' ')
-{
- if (!$rs) return '';
- //----------
- // CONSTANTS
- $NEWLINE = "\r\n";
- $BUFLINES = 100;
- $escquotequote = $escquote.$quote;
- $s = '';
-
- if ($addtitles) {
- $fieldTypes = $rs->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;
-}
+<?php\r
+\r
+/** \r
+ * @version V4.93 10 Oct 2006 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.\r
+ * Released under both BSD license and Lesser GPL library license. \r
+ * Whenever there is any discrepancy between the two licenses, \r
+ * the BSD license will take precedence. \r
+ *\r
+ * Code to export recordsets in several formats:\r
+ *\r
+ * AS VARIABLE\r
+ * $s = rs2csv($rs); # comma-separated values\r
+ * $s = rs2tab($rs); # tab delimited\r
+ * \r
+ * TO A FILE\r
+ * $f = fopen($path,'w');\r
+ * rs2csvfile($rs,$f);\r
+ * fclose($f);\r
+ *\r
+ * TO STDOUT\r
+ * rs2csvout($rs);\r
+ */\r
+ \r
+// returns a recordset as a csv string\r
+function rs2csv(&$rs,$addtitles=true)\r
+{\r
+ return _adodb_export($rs,',',',',false,$addtitles);\r
+}\r
+\r
+// writes recordset to csv file \r
+function rs2csvfile(&$rs,$fp,$addtitles=true)\r
+{\r
+ _adodb_export($rs,',',',',$fp,$addtitles);\r
+}\r
+\r
+// write recordset as csv string to stdout\r
+function rs2csvout(&$rs,$addtitles=true)\r
+{\r
+ $fp = fopen('php://stdout','wb');\r
+ _adodb_export($rs,',',',',true,$addtitles);\r
+ fclose($fp);\r
+}\r
+\r
+function rs2tab(&$rs,$addtitles=true)\r
+{\r
+ return _adodb_export($rs,"\t",',',false,$addtitles);\r
+}\r
+\r
+// to file pointer\r
+function rs2tabfile(&$rs,$fp,$addtitles=true)\r
+{\r
+ _adodb_export($rs,"\t",',',$fp,$addtitles);\r
+}\r
+\r
+// to stdout\r
+function rs2tabout(&$rs,$addtitles=true)\r
+{\r
+ $fp = fopen('php://stdout','wb');\r
+ _adodb_export($rs,"\t",' ',true,$addtitles);\r
+ if ($fp) fclose($fp);\r
+}\r
+\r
+function _adodb_export(&$rs,$sep,$sepreplace,$fp=false,$addtitles=true,$quote = '"',$escquote = '"',$replaceNewLine = ' ')\r
+{\r
+ if (!$rs) return '';\r
+ //----------\r
+ // CONSTANTS\r
+ $NEWLINE = "\r\n";\r
+ $BUFLINES = 100;\r
+ $escquotequote = $escquote.$quote;\r
+ $s = '';\r
+ \r
+ if ($addtitles) {\r
+ $fieldTypes = $rs->FieldTypesArray();\r
+ reset($fieldTypes);\r
+ while(list(,$o) = each($fieldTypes)) {\r
+ \r
+ $v = $o->name;\r
+ if ($escquote) $v = str_replace($quote,$escquotequote,$v);\r
+ $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v))));\r
+ $elements[] = $v;\r
+ \r
+ }\r
+ $s .= implode($sep, $elements).$NEWLINE;\r
+ }\r
+ $hasNumIndex = isset($rs->fields[0]);\r
+ \r
+ $line = 0;\r
+ $max = $rs->FieldCount();\r
+ \r
+ while (!$rs->EOF) {\r
+ $elements = array();\r
+ $i = 0;\r
+ \r
+ if ($hasNumIndex) {\r
+ for ($j=0; $j < $max; $j++) {\r
+ $v = $rs->fields[$j];\r
+ if (!is_object($v)) $v = trim($v);\r
+ else $v = 'Object';\r
+ if ($escquote) $v = str_replace($quote,$escquotequote,$v);\r
+ $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v))));\r
+ \r
+ if (strpos($v,$sep) !== false || strpos($v,$quote) !== false) $elements[] = "$quote$v$quote";\r
+ else $elements[] = $v;\r
+ }\r
+ } else { // ASSOCIATIVE ARRAY\r
+ foreach($rs->fields as $v) {\r
+ if ($escquote) $v = str_replace($quote,$escquotequote,trim($v));\r
+ $v = strip_tags(str_replace("\n", $replaceNewLine, str_replace("\r\n",$replaceNewLine,str_replace($sep,$sepreplace,$v))));\r
+ \r
+ if (strpos($v,$sep) !== false || strpos($v,$quote) !== false) $elements[] = "$quote$v$quote";\r
+ else $elements[] = $v;\r
+ }\r
+ }\r
+ $s .= implode($sep, $elements).$NEWLINE;\r
+ $rs->MoveNext();\r
+ $line += 1;\r
+ if ($fp && ($line % $BUFLINES) == 0) {\r
+ if ($fp === true) echo $s;\r
+ else fwrite($fp,$s);\r
+ $s = '';\r
+ }\r
+ }\r
+ \r
+ if ($fp) {\r
+ if ($fp === true) echo $s;\r
+ else fwrite($fp,$s);\r
+ $s = '';\r
+ }\r
+ \r
+ return $s;\r
+}\r
?>
\ No newline at end of file
-<?php
-/*
- V4.93 10 Oct 2006 (c) 2000-2006 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.
-
- Some pretty-printing by Chris Oxenreider <oxenreid@state.net>
-*/
-
-// 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 = "<TABLE COLS=$ncols $ztabhtml><tr>\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 .= "<TH>$fname</TH>";
- }
- $hdr .= "\n</tr>";
- 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 .= "<TR valign=top>\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 .= "<TD> </TD>\n";
- else if (!strpos($v,':')) {
- $s .= " <TD>".$rs->UserDate($v,"D d, M Y") ." </TD>\n";
- }
- break;
- case 'T':
- if (empty($v)) $s .= "<TD> </TD>\n";
- else $s .= " <TD>".$rs->UserTimeStamp($v,"D d, M Y, h:i:s") ." </TD>\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 .= " <TD align=right>".stripslashes((trim($v))) ." </TD>\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") ? " <td><img src='$tmpname' alt='$t'></td>\\n" : " <td><a
- href='$tmpname'>$t</a></td>\\n";
- break;
- */
-
- default:
- if ($htmlspecialchars) $v = htmlspecialchars(trim($v));
- $v = trim($v);
- if (strlen($v) == 0) $v = ' ';
- $s .= " <TD>". str_replace("\n",'<br>',stripslashes($v)) ."</TD>\n";
-
- }
- } // for
- $s .= "</TR>\n\n";
-
- $rows += 1;
- if ($rows >= $gSQLMaxRows) {
- $rows = "<p>Truncated at $gSQLMaxRows</p>";
- 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 . "</TABLE>\n\n";
- else $html .= $s ."</TABLE>\n\n";
- $s = $hdr;
- }
- } // while
-
- if ($echo) print $s."</TABLE>\n\n";
- else $html .= $s."</TABLE>\n\n";
-
- if ($docnt) if ($echo) print "<H2>".$rows." Rows</H2>";
-
- return ($echo) ? $rows : $html;
- }
-
-// pass in 2 dimensional array
-function arr2html(&$arr,$ztabhtml='',$zheaderarray='')
-{
- if (!$ztabhtml) $ztabhtml = 'BORDER=1';
-
- $s = "<TABLE $ztabhtml>";//';print_r($arr);
-
- if ($zheaderarray) {
- $s .= '<TR>';
- for ($i=0; $i<sizeof($zheaderarray); $i++) {
- $s .= " <TH>{$zheaderarray[$i]}</TH>\n";
- }
- $s .= "\n</TR>";
- }
-
- for ($i=0; $i<sizeof($arr); $i++) {
- $s .= '<TR>';
- $a = &$arr[$i];
- if (is_array($a))
- for ($j=0; $j<sizeof($a); $j++) {
- $val = $a[$j];
- if (empty($val)) $val = ' ';
- $s .= " <TD>$val</TD>\n";
- }
- else if ($a) {
- $s .= ' <TD>'.$a."</TD>\n";
- } else $s .= " <TD> </TD>\n";
- $s .= "\n</TR>\n";
- }
- $s .= '</TABLE>';
- print $s;
-}
-
+<?php \r
+/*\r
+ V4.93 10 Oct 2006 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.\r
+ Released under both BSD license and Lesser GPL library license. \r
+ Whenever there is any discrepancy between the two licenses, \r
+ the BSD license will take precedence.\r
+ \r
+ Some pretty-printing by Chris Oxenreider <oxenreid@state.net>\r
+*/ \r
+ \r
+// specific code for tohtml\r
+GLOBAL $gSQLMaxRows,$gSQLBlockRows,$ADODB_ROUND;\r
+\r
+$ADODB_ROUND=4; // rounding\r
+$gSQLMaxRows = 1000; // max no of rows to download\r
+$gSQLBlockRows=20; // max no of rows per table block\r
+\r
+// RecordSet to HTML Table\r
+//------------------------------------------------------------\r
+// Convert a recordset to a html table. Multiple tables are generated\r
+// if the number of rows is > $gSQLBlockRows. This is because\r
+// web browsers normally require the whole table to be downloaded\r
+// before it can be rendered, so we break the output into several\r
+// smaller faster rendering tables.\r
+//\r
+// $rs: the recordset\r
+// $ztabhtml: the table tag attributes (optional)\r
+// $zheaderarray: contains the replacement strings for the headers (optional)\r
+//\r
+// USAGE:\r
+// include('adodb.inc.php');\r
+// $db = ADONewConnection('mysql');\r
+// $db->Connect('mysql','userid','password','database');\r
+// $rs = $db->Execute('select col1,col2,col3 from table');\r
+// rs2html($rs, 'BORDER=2', array('Title1', 'Title2', 'Title3'));\r
+// $rs->Close();\r
+//\r
+// RETURNS: number of rows displayed\r
+\r
+\r
+function rs2html(&$rs,$ztabhtml=false,$zheaderarray=false,$htmlspecialchars=true,$echo = true)\r
+{\r
+$s ='';$rows=0;$docnt = false;\r
+GLOBAL $gSQLMaxRows,$gSQLBlockRows,$ADODB_ROUND;\r
+\r
+ if (!$rs) {\r
+ printf(ADODB_BAD_RS,'rs2html');\r
+ return false;\r
+ }\r
+ \r
+ if (! $ztabhtml) $ztabhtml = "BORDER='1' WIDTH='98%'";\r
+ //else $docnt = true;\r
+ $typearr = array();\r
+ $ncols = $rs->FieldCount();\r
+ $hdr = "<TABLE COLS=$ncols $ztabhtml><tr>\n\n";\r
+ for ($i=0; $i < $ncols; $i++) { \r
+ $field = $rs->FetchField($i);\r
+ if ($field) {\r
+ if ($zheaderarray) $fname = $zheaderarray[$i];\r
+ else $fname = htmlspecialchars($field->name); \r
+ $typearr[$i] = $rs->MetaType($field->type,$field->max_length);\r
+ //print " $field->name $field->type $typearr[$i] ";\r
+ } else {\r
+ $fname = 'Field '.($i+1);\r
+ $typearr[$i] = 'C';\r
+ }\r
+ if (strlen($fname)==0) $fname = ' ';\r
+ $hdr .= "<TH>$fname</TH>";\r
+ }\r
+ $hdr .= "\n</tr>";\r
+ if ($echo) print $hdr."\n\n";\r
+ else $html = $hdr;\r
+ \r
+ // smart algorithm - handles ADODB_FETCH_MODE's correctly by probing...\r
+ $numoffset = isset($rs->fields[0]) ||isset($rs->fields[1]) || isset($rs->fields[2]);\r
+ while (!$rs->EOF) {\r
+ \r
+ $s .= "<TR valign=top>\n";\r
+ \r
+ for ($i=0; $i < $ncols; $i++) {\r
+ if ($i===0) $v=($numoffset) ? $rs->fields[0] : reset($rs->fields);\r
+ else $v = ($numoffset) ? $rs->fields[$i] : next($rs->fields);\r
+ \r
+ $type = $typearr[$i];\r
+ switch($type) {\r
+ case 'D':\r
+ if (empty($v)) $s .= "<TD> </TD>\n";\r
+ else if (!strpos($v,':')) {\r
+ $s .= " <TD>".$rs->UserDate($v,"D d, M Y") ." </TD>\n";\r
+ }\r
+ break;\r
+ case 'T':\r
+ if (empty($v)) $s .= "<TD> </TD>\n";\r
+ else $s .= " <TD>".$rs->UserTimeStamp($v,"D d, M Y, h:i:s") ." </TD>\n";\r
+ break;\r
+ \r
+ case 'N':\r
+ if (abs(abs($v) - round($v,0)) < 0.00000001)\r
+ $v = round($v);\r
+ else\r
+ $v = round($v,$ADODB_ROUND);\r
+ case 'I':\r
+ $s .= " <TD align=right>".stripslashes((trim($v))) ." </TD>\n";\r
+ \r
+ break;\r
+ /*\r
+ case 'B':\r
+ if (substr($v,8,2)=="BM" ) $v = substr($v,8);\r
+ $mtime = substr(str_replace(' ','_',microtime()),2);\r
+ $tmpname = "tmp/".uniqid($mtime).getmypid();\r
+ $fd = @fopen($tmpname,'a');\r
+ @ftruncate($fd,0);\r
+ @fwrite($fd,$v);\r
+ @fclose($fd);\r
+ if (!function_exists ("mime_content_type")) {\r
+ function mime_content_type ($file) {\r
+ return exec("file -bi ".escapeshellarg($file));\r
+ }\r
+ }\r
+ $t = mime_content_type($tmpname);\r
+ $s .= (substr($t,0,5)=="image") ? " <td><img src='$tmpname' alt='$t'></td>\\n" : " <td><a\r
+ href='$tmpname'>$t</a></td>\\n";\r
+ break;\r
+ */\r
+\r
+ default:\r
+ if ($htmlspecialchars) $v = htmlspecialchars(trim($v));\r
+ $v = trim($v);\r
+ if (strlen($v) == 0) $v = ' ';\r
+ $s .= " <TD>". str_replace("\n",'<br>',stripslashes($v)) ."</TD>\n";\r
+ \r
+ }\r
+ } // for\r
+ $s .= "</TR>\n\n";\r
+ \r
+ $rows += 1;\r
+ if ($rows >= $gSQLMaxRows) {\r
+ $rows = "<p>Truncated at $gSQLMaxRows</p>";\r
+ break;\r
+ } // switch\r
+\r
+ $rs->MoveNext();\r
+ \r
+ // additional EOF check to prevent a widow header\r
+ if (!$rs->EOF && $rows % $gSQLBlockRows == 0) {\r
+ \r
+ //if (connection_aborted()) break;// not needed as PHP aborts script, unlike ASP\r
+ if ($echo) print $s . "</TABLE>\n\n";\r
+ else $html .= $s ."</TABLE>\n\n";\r
+ $s = $hdr;\r
+ }\r
+ } // while\r
+\r
+ if ($echo) print $s."</TABLE>\n\n";\r
+ else $html .= $s."</TABLE>\n\n";\r
+ \r
+ if ($docnt) if ($echo) print "<H2>".$rows." Rows</H2>";\r
+ \r
+ return ($echo) ? $rows : $html;\r
+ }\r
+ \r
+// pass in 2 dimensional array\r
+function arr2html(&$arr,$ztabhtml='',$zheaderarray='')\r
+{\r
+ if (!$ztabhtml) $ztabhtml = 'BORDER=1';\r
+ \r
+ $s = "<TABLE $ztabhtml>";//';print_r($arr);\r
+\r
+ if ($zheaderarray) {\r
+ $s .= '<TR>';\r
+ for ($i=0; $i<sizeof($zheaderarray); $i++) {\r
+ $s .= " <TH>{$zheaderarray[$i]}</TH>\n";\r
+ }\r
+ $s .= "\n</TR>";\r
+ }\r
+ \r
+ for ($i=0; $i<sizeof($arr); $i++) {\r
+ $s .= '<TR>';\r
+ $a = &$arr[$i];\r
+ if (is_array($a)) \r
+ for ($j=0; $j<sizeof($a); $j++) {\r
+ $val = $a[$j];\r
+ if (empty($val)) $val = ' ';\r
+ $s .= " <TD>$val</TD>\n";\r
+ }\r
+ else if ($a) {\r
+ $s .= ' <TD>'.$a."</TD>\n";\r
+ } else $s .= " <TD> </TD>\n";\r
+ $s .= "\n</TR>\n";\r
+ }\r
+ $s .= '</TABLE>';\r
+ print $s;\r
+}\r
+\r
?>
\ No newline at end of file