<?php
/*
-@version V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+@version V4.98 13 Feb 2008 (c) 2000-2008 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.08
+ Version 0.09
See http://www-128.ibm.com/developerworks/java/library/j-cb03076/?ca=dgr-lnxw01ActiveRecord
for info on Ruby on Rails Active Record implementation
global $_ADODB_ACTIVE_DBS;
global $ADODB_ACTIVE_CACHESECS; // set to true to enable caching of metadata such as field info
global $ACTIVE_RECORD_SAFETY; // set to false to disable safety checks
+global $ADODB_ACTIVE_DEFVALS; // use default values of table definition when creating new active record.
// array of ADODB_Active_DB's, indexed by ADODB_Active_Record->_dbat
$_ADODB_ACTIVE_DBS = array();
$ACTIVE_RECORD_SAFETY = true;
+$ADODB_ACTIVE_DEFVALS = false;
class ADODB_Active_DB {
var $db; // ADOConnection
var $_lasterr = false; // last error message
var $_original = false; // the original values loaded or inserted, refreshed on update
+ // should be static
+ function UseDefaultValues($bool=null)
+ {
+ global $ADODB_ACTIVE_DEFVALS;
+ if (isset($bool)) $ADODB_ACTIVE_DEFVALS = $bool;
+ return $ADODB_ACTIVE_DEFVALS;
+ }
+
// should be static
function SetDatabaseAdapter(&$db)
{
function UpdateActiveTable($pkeys=false,$forceUpdate=false)
{
global $ADODB_ASSOC_CASE,$_ADODB_ACTIVE_DBS , $ADODB_CACHE_DIR, $ADODB_ACTIVE_CACHESECS;
-
+ global $ADODB_ACTIVE_DEFVALS;
+
$activedb =& $_ADODB_ACTIVE_DBS[$this->_dbat];
$table = $this->_table;
$tableat = $this->_tableat;
if (!$forceUpdate && !empty($tables[$tableat])) {
$tobj =& $tables[$tableat];
- foreach($tobj->flds as $name => $fld)
- $this->$name = null;
+ foreach($tobj->flds as $name => $fld) {
+ if ($ADODB_ACTIVE_DEFVALS && isset($fld->default_value))
+ $this->$name = $fld->default_value;
+ else
+ $this->$name = null;
+ }
return;
}
case 0:
foreach($cols as $name => $fldobj) {
$name = strtolower($name);
- $this->$name = null;
+ if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value))
+ $this->$name = $fldobj->default_value;
+ else
+ $this->$name = null;
$attr[$name] = $fldobj;
}
foreach($pkeys as $k => $name) {
case 1:
foreach($cols as $name => $fldobj) {
$name = strtoupper($name);
- $this->$name = null;
+
+ if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value))
+ $this->$name = $fldobj->default_value;
+ else
+ $this->$name = null;
$attr[$name] = $fldobj;
}
default:
foreach($cols as $name => $fldobj) {
$name = ($fldobj->name);
- $this->$name = null;
+
+ if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value))
+ $this->$name = $fldobj->default_value;
+ else
+ $this->$name = null;
$attr[$name] = $fldobj;
}
foreach($pkeys as $k => $name) {
$table =& $this->TableInfo();
if ($ACTIVE_RECORD_SAFETY && sizeof($table->flds) != sizeof($row)) {
- $this->Error("Table structure of $this->_table has changed","Load");
- return false;
+ $bad_size = TRUE;
+ if (sizeof($row) == 2 * sizeof($table->flds)) {
+ // Only keep string keys
+ $keys = array_filter(array_keys($row), 'is_string');
+ if (sizeof($keys) == sizeof($table->flds))
+ $bad_size = FALSE;
+ }
+ if ($bad_size) {
+ $this->Error("Table structure of $this->_table has changed","Load");
+ return false;
+ }
}
-
- $keys = array_keys($row);
- $cnt = 0;
+ else
+ $keys = array_keys($row);
+
+ reset($keys);
+ $this->_original = array();
foreach($table->flds as $name=>$fld) {
- $this->$name = $row[$keys[$cnt]];
- $cnt += 1;
+ $value = $row[current($keys)];
+ $this->$name = $value;
+ $this->_original[] = $value;
+ next($keys);
}
- $this->_original = $row;
+ # </AP>
return true;
}
if ($ADODB_ASSOC_CASE == 0)
foreach($pkey as $k => $v)
$pkey[$k] = strtolower($v);
- elseif ($ADODB_ASSOC_CASE == 0)
+ elseif ($ADODB_ASSOC_CASE == 1)
foreach($pkey as $k => $v)
$pkey[$k] = strtoupper($v);
/*
- V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008 (c) 2000-2008 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.
/**
* Save a file $filename and its $contents (normally for caching) with file locking
+ * Returns true if ok, false if fopen/fwrite error, 0 if rename error (eg. file is locked)
*/
function adodb_write_file($filename, $contents,$debug=false)
{
$mtime = substr(str_replace(' ','_',microtime()),2);
// getmypid() actually returns 0 on Win98 - never mind!
$tmpname = $filename.uniqid($mtime).getmypid();
- if (!($fd = @fopen($tmpname,'a'))) return false;
- $ok = ftruncate($fd,0);
- if (!fwrite($fd,$contents)) $ok = false;
+ if (!($fd = @fopen($tmpname,'w'))) return false;
+ if (fwrite($fd,$contents)) $ok = true;
+ else $ok = false;
fclose($fd);
- chmod($tmpname,0644);
- // the tricky moment
- @unlink($filename);
- if (!@rename($tmpname,$filename)) {
- unlink($tmpname);
- $ok = false;
- }
- if (!$ok) {
- if ($debug) ADOConnection::outp( " Rename $tmpname ".($ok? 'ok' : 'failed'));
+
+ if ($ok) {
+ chmod($tmpname,0644);
+ // the tricky moment
+ @unlink($filename);
+ if (!@rename($tmpname,$filename)) {
+ unlink($tmpname);
+ $ok = 0;
+ }
+ if (!$ok) {
+ if ($debug) ADOConnection::outp( " Rename $tmpname ".($ok? 'ok' : 'failed'));
+ }
}
return $ok;
}
if (!($fd = @fopen($filename, 'a'))) return false;
if (flock($fd, LOCK_EX) && ftruncate($fd, 0)) {
- $ok = fwrite( $fd, $contents );
+ if (fwrite( $fd, $contents )) $ok = true;
+ else $ok = false;
fclose($fd);
chmod($filename,0644);
}else {
<?php
/**
- V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008 (c) 2000-2008 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.
$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)) {
- echo "<h3>$this->alterCol cannot be changed to $flds currently</h3>";
+ // $flds[1] holds the type, $flds[2] holds the size -postnuke addition
+ if ($flds && in_array(strtoupper(substr($flds[0][1],0,4)),$this->invalidResizeTypes4)
+ && (isset($flds[0][2]) && is_numeric($flds[0][2]))) {
+ if ($this->debug) ADOConnection::outp(sprintf("<h3>%s cannot be changed to %s currently</h3>", $flds[0][0], $flds[0][1]));
+ #echo "<h3>$this->alterCol cannot be changed to $flds currently</h3>";
continue;
}
$sql[] = $alter . $this->alterCol . ' ' . $v;
<?php
/**
- * @version V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * @version V4.98 13 Feb 2008 (c) 2000-2008 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 (is_numeric($errormsg)) return (integer) $errormsg;
static $error_regexps = array(
- '/(Table does not exist\.|Relation [\"\'].*[\"\'] does not exist|sequence does not exist|class ".+" not found)$/' => DB_ERROR_NOSUCHTABLE,
- '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*/' => DB_ERROR_ALREADY_EXISTS,
- '/divide by zero$/' => DB_ERROR_DIVZERO,
- '/pg_atoi: error in .*: can\'t parse /' => DB_ERROR_INVALID_NUMBER,
- '/ttribute [\"\'].*[\"\'] not found|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/' => DB_ERROR_NOSUCHFIELD,
- '/parser: parse error at or near \"/' => DB_ERROR_SYNTAX,
- '/referential integrity violation/' => DB_ERROR_CONSTRAINT,
- '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*|duplicate key violates unique constraint/'
+ '/(Table does not exist\.|Relation [\"\'].*[\"\'] does not exist|sequence does not exist|class ".+" not found)$/i' => DB_ERROR_NOSUCHTABLE,
+ '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*/i' => DB_ERROR_ALREADY_EXISTS,
+ '/divide by zero$/i' => DB_ERROR_DIVZERO,
+ '/pg_atoi: error in .*: can\'t parse /i' => DB_ERROR_INVALID_NUMBER,
+ '/ttribute [\"\'].*[\"\'] not found|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/i' => DB_ERROR_NOSUCHFIELD,
+ '/parser: parse error at or near \"/i' => DB_ERROR_SYNTAX,
+ '/referential integrity violation/i' => DB_ERROR_CONSTRAINT,
+ '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*|duplicate key violates unique constraint/i'
=> DB_ERROR_ALREADY_EXISTS
);
reset($error_regexps);
<?php
/**
- * @version V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * @version V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * @version V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * @version V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim\@natsoft.com.my). All rights reserved.
+ @version V4.98 13 Feb 2008 (c) 2000-2008 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.
} else
$rewritesql = "SELECT COUNT(*) FROM (".$rewritesql.")";
- } else if (strncmp($zthis->databaseType,'postgres',8) == 0) {
+ } else if (strncmp($zthis->databaseType,'postgres',8) == 0 || strncmp($zthis->databaseType,'mysql',5) == 0) {
$rewritesql = "SELECT COUNT(*) FROM ($rewritesql) _ADODB_ALIAS_";
+ } else {
+ $rewritesql = "SELECT COUNT(*) FROM ($rewritesql) ";
}
} else {
// now replace SELECT ... FROM with SELECT COUNT(*) FROM
return $rsreturn;
}
-// Iv�n Oliva version
+// Iván Oliva version
function &_adodb_pageexecute_no_last_page(&$zthis, $sql, $nrows, $page, $inputarr=false, $secs2cache=0)
{
case "D":
$val = $zthis->DBDate($arrFields[$fname]);
break;
-
- \r
- case "T":\r
+
+ case "T":
$val = $zthis->DBTimeStamp($arrFields[$fname]);
- break;
-
-// moodle change start - see readme_moodle.txt
- case "F": //Floating point number
- case "N": //Numeric or decimal number
- $val = (float)$arrFields[$fname];
break;
- case "L": //Integer field suitable for storing booleans (0 or 1)
+ case "F": //Floating point number // Moodle added
+ case "N":
+ $val = $arrFields[$fname];
+ if (!is_numeric($val)) $val = str_replace(',', '.', (float)$val);
+ break;
+
+ case "L": //Integer field suitable for storing booleans (0 or 1) // Moodle added
case "I":
case "R":
- $val = (int) $arrFields[$fname];
+ $val = $arrFields[$fname];
+ if (!is_numeric($val)) $val = (integer) $val;
break;
-// moodle change end
default:
$val = str_replace(array("'"," ","("),"",$arrFields[$fname]); // basic sql injection defence
}
*/
-?>
\ No newline at end of file
+?>
-<?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
+
+// security - hide paths
+if (!defined('ADODB_DIR')) die();
+
+global $ADODB_INCLUDED_MEMCACHE;
+$ADODB_INCLUDED_MEMCACHE = 1;
+
+/*
+
+ V4.90 8 June 2006 (c) 2000-2008 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
/*
- V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * @version V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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 (!defined('ADODB_DIR')) include_once(dirname(__FILE__).'/adodb.inc.php');
include_once(ADODB_DIR.'/tohtml.inc.php');
+global $ADODB_PERF_MIN;
+$ADODB_PERF_MIN = 0.05; // log only if >= minimum number of secs to run
+
define( 'ADODB_OPT_HIGH', 2);
define( 'ADODB_OPT_LOW', 1);
if ($dbT == 'db2') $arr['f'] = (float) $arr['f'];
$isql = "insert into $perf_table (created,sql0,sql1,params,tracer,timer) values( $d,?,?,?,?,?)";
}
- $ok = $conn->Execute($isql,$arr);
+ global $ADODB_PERF_MIN;
+ if ($errN != 0 || $time >= $ADODB_PERF_MIN) {
+ $ok = $conn->Execute($isql,$arr);
+ } else {
+ $ok = true;
+ }
$conn->debug = $saved;
if ($ok) {
else $form = "<td> </td>";
$allowsql = !defined('ADODB_PERF_NO_RUN_SQL');
+ global $ADODB_PERF_MIN;
+ $app .= " (Min sql timing \$ADODB_PERF_MIN=$ADODB_PERF_MIN secs)";
if (empty($_GET['hidem']))
echo "<table border=1 width=100% bgcolor=lightyellow><tr><td colspan=2>
<?php
/*
- V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008 (c) 2000-2008 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.
CHANGELOG
+
+- 11 Feb 2008 0.33
+* Bug in 0.32 fix for hour handling. Fixed.
+
+- 1 Feb 2008 0.32
+* Now adodb_mktime(0,0,0,12+$m,20,2040) works properly.
+
+- 10 Jan 2008 0.31
+* Now adodb_mktime(0,0,0,24,1,2037) works correctly.
+
- 15 July 2007 0.30
Added PHP 5.2.0 compatability fixes.
* gmtime behaviour for 1970 has changed. We use the actual date if it is between 1970 to 2038 to get the
/*
Version Number
*/
-define('ADODB_DATE_VERSION',0.30);
+define('ADODB_DATE_VERSION',0.33);
$ADODB_DATETIME_CLASS = (PHP_VERSION >= 5.2);
$t = adodb_mktime($h,0,0,$m,$d,$y1);
$rez = adodb_date('Y-n-j H:i:s',$t);
if ($h == 0) $h = '00';
- else if ($h < 10) $h = '0'.$h;
+ else if ($h < 10) $h = '0'.$h;
if ("$y1-$m-$d $h:00:00" != $rez) {
print "<b>$y1 error, expected=$y1-$m-$d $h:00:00, adodb=$rez</b><br>";
return false;
/**
Test Suite
-*/
+*/
function adodb_date_test()
{
+ for ($m=-24; $m<=24; $m++)
+ echo "$m :",adodb_date('d-m-Y',adodb_mktime(0,0,0,1+$m,20,2040)),"<br>";
+
error_reporting(E_ALL);
print "<h4>Testing adodb_date and adodb_mktime. version=".ADODB_DATE_VERSION.' PHP='.PHP_VERSION."</h4>";
@set_time_limit(0);
$m = $arr['mon'];
$d = $arr['mday'];
return adodb_get_gmt_diff($y,$m,$d);
-} else {
+ } else {
return adodb_get_gmt_diff(false,false,false);
}
}
return -$tzo->getOffset($dt);
} else {
- if (isset($TZ)) return $TZ;
- $y = date('Y');
- $TZ = mktime(0,0,0,12,2,$y,0) - gmmktime(0,0,0,12,2,$y,0);
+ if (isset($TZ)) return $TZ;
+ $y = date('Y');
+ $TZ = mktime(0,0,0,12,2,$y,0) - gmmktime(0,0,0,12,2,$y,0);
}
return $TZ;
$dates .= ' '.adodb_tz_offset($gmt,$isphp5);
break;
-
+
case 'Y': $dates .= $year; break;
case 'y': $dates .= substr($year,strlen($year)-2,2); break;
// MONTH
// for windows, we don't check 1970 because with timezone differences,
// 1 Jan 1970 could generate negative timestamp, which is illegal
- if (1971 < $year && $year < 2038
+ $usephpfns = (1971 < $year && $year < 2038
|| !defined('ADODB_NO_NEGATIVE_TS') && (1901 < $year && $year < 2038)
- ) {
+ );
+
+
+ if ($usephpfns && ($year + $mon/12+$day/365.25+$hr/(24*365.25) >= 2038)) $usephpfns = false;
+
+ if ($usephpfns) {
return $is_gmt ?
@gmmktime($hr,$min,$sec,$mon,$day,$year):
@mktime($hr,$min,$sec,$mon,$day,$year);
- }
+ }
}
$gmt_different = ($is_gmt) ? 0 : adodb_get_gmt_diff($year,$mon,$day);
$year = adodb_year_digit_check($year);
if ($mon > 12) {
- $y = floor($mon / 12);
+ $y = floor(($mon-1)/ 12);
$year += $y;
$mon -= $y*12;
} else if ($mon < 1) {
return $ret;
}
-
?>
\ No newline at end of file
*
* Last Editor: $Author$
* @author Richard Tango-Lowy & Dan Cech
- * @version $Id$
+ * @version $Revision$
*
* @package axmls
* @tutorial getting_started.pkg
* @tutorial getting_started.pkg
*
* @author Richard Tango-Lowy & Dan Cech
-* @version $Id$
+* @version $Revision$
*
* @package axmls
*/
*
* Last Editor: $Author$
* @author Richard Tango-Lowy & Dan Cech
- * @version $Id$
+ * @version $Revision$
*
* @package axmls
* @tutorial getting_started.pkg
* @tutorial getting_started.pkg
*
* @author Richard Tango-Lowy & Dan Cech
-* @version $Id$
+* @version $Revision$
*
* @package axmls
*/
-<?php
+<?php
/*
* Set tabs to 4 for best viewing.
*
/**
\mainpage
- @version V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ @version V4.98 13 Feb 2008 (c) 2000-2008 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 version as a string.
*/
- $ADODB_vers = 'V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved. Released BSD & LGPL.';
+ $ADODB_vers = 'V4.98 13 Feb 2008 (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved. Released BSD & LGPL.';
/**
* Determines whether recordset->RecordCount() is used.
function GetCol($sql, $inputarr = false, $trim = false)
{
- $rv = false;
+
$rs = &$this->Execute($sql, $inputarr);
if ($rs) {
$rv = array();
}
}
$rs->Close();
- }
+ } else
+ $rv = false;
return $rv;
}
function CacheGetCol($secs, $sql = false, $inputarr = false,$trim=false)
{
- $rv = false;
$rs = &$this->CacheExecute($secs, $sql, $inputarr);
if ($rs) {
+ $rv = array();
if ($trim) {
while (!$rs->EOF) {
$rv[] = trim(reset($rs->fields));
}
}
$rs->Close();
- }
- return $rv;
+ } else
+ $rv = false;
+
+ return $rv;
}
function &Transpose(&$rs,$addfieldnames=true)
{
$rs =& $this->CacheExecute($secs2cache,$sql,$inputarr);
if ($rs) {
- $arr = false;
+ $arr = array();
if (!$rs->EOF) $arr = $rs->fields;
$rs->Close();
return $arr;
if ($createdir && $notSafeMode && !file_exists($dir)) {
$oldu = umask(0);
- if (!mkdir($dir,0771))
- if ($this->debug) ADOConnection::outp( "Unable to mkdir $dir for $sql");
+ if (!@mkdir($dir,0771))
+ if(!is_dir($dir) && $this->debug) ADOConnection::outp( "Unable to mkdir $dir for $sql");
umask($oldu);
}
return $dir.'/adodb_'.$m.'.cache';
$fn($this->databaseType,'CacheExecute',-32000,"Cache write error",$md5file,$sql,$this);
if ($this->debug) ADOConnection::outp( " Cache write error");
}
- } else
- if ($rs) {
+ } else if ($rs) {
$eof = $rs->EOF;
$rs = &$this->_rs2rs($rs); // read entire recordset into memory immediately
$txt = _rs2serialize($rs,false,$sql); // serialize
- if (!adodb_write_file($md5file,$txt,$this->debug)) {
- if ($fn = $this->raiseErrorFn) {
- $fn($this->databaseType,'CacheExecute',-32000,"Cache write error",$md5file,$sql,$this);
+ $ok = adodb_write_file($md5file,$txt,$this->debug);
+ if (!$ok) {
+ if ($ok === false) {
+ $em = 'Cache write error';
+ $en = -32000;
+
+ if ($fn = $this->raiseErrorFn) {
+ $fn($this->databaseType,'CacheExecute', $en, $em, $md5file,$sql,$this);
+ }
+ } else {
+ $em = 'Cache file locked warning';
+ $en = -32001;
+ // do not call error handling for just a warning
}
- if ($this->debug) ADOConnection::outp( " Cache write error");
+
+ if ($this->debug) ADOConnection::outp( " ".$em);
}
if ($rs->EOF && !$eof) {
$rs->MoveFirst();
$mode = isset($this->adodbFetchMode) ? $this->adodbFetchMode : $this->fetchMode;
if ($mode & ADODB_FETCH_ASSOC) {
- if (!isset($this->fields[$colname])) $colname = strtolower($colname);
+ if (!isset($this->fields[$colname]) && !is_null($this->fields[$colname])) $colname = strtolower($colname);
return $this->fields[$colname];
}
if (!$this->bind) {
<?php
/**
- V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008 (c) 2000-2008 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 $sql;
}
+
+ function DropIndexSQL ($idxname, $tabname = NULL)
+ {
+ return array(sprintf($this->dropIndex, $this->TableName($idxname), $this->TableName($tabname)));
+ }
+
/**
* Change the definition of one column
*
-<?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
+<?php
+
+/**
+ V4.50 6 July 2004 (c) 2000-2008 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) . ')' );
+ }
+}
+
?>
\ No newline at end of file
<?php
/**
- V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2006 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008 (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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ @version V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+* @version V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim. All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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 ($type === false)
switch(gettype($var)) {
default:
- case 'string': $type = SQLCHAR; break;
+ case 'string': $type = SQLVARCHAR; break;
case 'double': $type = SQLFLT8; break;
case 'integer': $type = SQLINT4; break;
case 'boolean': $type = SQLINT1; break; # SQLBIT not supported in 4.1.0
// ADOdb - Database Abstraction Library for PHP //
// http://adodb.sourceforge.net/ //
// //
-// Copyright (C) 2000-2007 John Lim (jlim\@natsoft.com.my) //
+// Copyright (C) 2000-2008 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, //
<?php
/**
-* @version V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+* @version V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.
} else {
if ($this->debug)
ADOConnection::outp("Could't connect : " . $this->ErrorMsg());
+ $this->_connectionID = null;
return false;
}
}
$nrows = -1,
$offset = -1,
$inputarr = false,
- $arg3 = false,
$secs = 0)
{
$offsetStr = ($offset >= 0) ? "$offset," : '';
if ($nrows < 0) $nrows = '18446744073709551615';
if ($secs)
- $rs =& $this->CacheExecute($secs, $sql . " LIMIT $offsetStr$nrows" , $inputarr , $arg3);
+ $rs =& $this->CacheExecute($secs, $sql . " LIMIT $offsetStr$nrows" , $inputarr);
else
- $rs =& $this->Execute($sql . " LIMIT $offsetStr$nrows" , $inputarr , $arg3);
+ $rs =& $this->Execute($sql . " LIMIT $offsetStr$nrows" , $inputarr);
return $rs;
}
case 'SET':
case MYSQLI_TYPE_TINY_BLOB :
- case MYSQLI_TYPE_CHAR :
+ #case MYSQLI_TYPE_CHAR :
case MYSQLI_TYPE_STRING :
case MYSQLI_TYPE_ENUM :
case MYSQLI_TYPE_SET :
case 'SET':
case MYSQLI_TYPE_TINY_BLOB :
- case MYSQLI_TYPE_CHAR :
+ #case MYSQLI_TYPE_CHAR :
case MYSQLI_TYPE_STRING :
case MYSQLI_TYPE_ENUM :
case MYSQLI_TYPE_SET :
<?php
/*
-V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim. All rights reserved.
+ version V4.98 13 Feb 2008 (c) 2000-2008 John Lim. All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by
fetchField() is retrieved. */
- function &_FetchField($fieldOffset = -1)
+ function _FetchField($fieldOffset = -1)
{
$fld = new ADOFieldObject;
$fieldOffset += 1;
$fld->name =OCIcolumnname($this->_queryID, $fieldOffset);
$fld->type = OCIcolumntype($this->_queryID, $fieldOffset);
$fld->max_length = OCIcolumnsize($this->_queryID, $fieldOffset);
- if ($fld->type == 'NUMBER') {
+ switch($fld->type) {
+ case 'NUMBER':
$p = OCIColumnPrecision($this->_queryID, $fieldOffset);
$sc = OCIColumnScale($this->_queryID, $fieldOffset);
if ($p != 0 && $sc == 0) $fld->type = 'INT';
- //echo " $this->name ($p.$sc) ";
- }
+ break;
+
+ case 'CLOB':
+ case 'NCLOB':
+ case 'BLOB':
+ $fld->max_length = -1;
+ break;
+ }
return $fld;
}
<?php
/**
- * @version V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ * @version V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim. All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.
-class ADODB_pdo_base extends ADODB_pdo {
-
- var $sysDate = "'?'";
- var $sysTimeStamp = "'?'";
-
-
- function _init($parentDriver)
- {
- $parentDriver->_bindInputArray = true;
- #$parentDriver->_connectionID->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true);
- }
-
- function ServerInfo()
- {
- return ADOConnection::ServerInfo();
- }
-
- function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0)
- {
- $ret = ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
- return $ret;
- }
-
- function MetaTables()
- {
- return false;
- }
-
- function MetaColumns()
- {
- return false;
- }
-}
-
-
class ADODB_pdo extends ADOConnection {
var $databaseType = "pdo";
var $dataProvider = "pdo";
}
}
+
+
+class ADODB_pdo_base extends ADODB_pdo {
+
+ var $sysDate = "'?'";
+ var $sysTimeStamp = "'?'";
+
+
+ function _init($parentDriver)
+ {
+ $parentDriver->_bindInputArray = true;
+ #$parentDriver->_connectionID->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true);
+ }
+
+ function ServerInfo()
+ {
+ return ADOConnection::ServerInfo();
+ }
+
+ function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0)
+ {
+ $ret = ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
+ return $ret;
+ }
+
+ function MetaTables()
+ {
+ return false;
+ }
+
+ function MetaColumns()
+ {
+ return false;
+ }
+}
+
+
class ADOPDOStatement {
var $databaseType = "pdo";
/*
-V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.
var $metaColumnsSQL = "SHOW COLUMNS FROM `%s`";
var $sysDate = 'CURDATE()';
var $sysTimeStamp = 'NOW()';
+ var $hasGenID = true;
+ var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
+ var $_dropSeqSQL = "drop table %s";
+
var $nameQuote = '`';
function _init($parentDriver)
/*
-V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights
+version V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim. All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+ V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.
DB_ERROR_NOSUCHDB => 'áíÓ åäÇáß ÞÇÚÏÉ ÈíÇäÇÊ ÈåÐÇ ÇáÇÓã',
DB_ERROR_ACCESS_VIOLATION => 'ÓãÇÍíÇÊ ÛíÑ ßÇÝíÉ'
);
-?>
+?>
\ No newline at end of file
-<?php
+<?php
/*
Bulgarian language, v1.0, 25.03.2004, encoding by UTF-8 charset
contributed by Valentin Sheiretsky <valio#valio.eu.org>
DB_ERROR_NOSUCHDB => 'несъществуваща база данни',
DB_ERROR_ACCESS_VIOLATION => 'нямате достатъчно права'
);
-?>
+?>
\ No newline at end of file
-<?php\r
-// Catalan language\r
-// contributed by "Josep Lladonosa" jlladono#pie.xtec.es\r
-$ADODB_LANG_ARRAY = array (\r
- 'LANG' => 'ca',\r
- DB_ERROR => 'error desconegut',\r
- DB_ERROR_ALREADY_EXISTS => 'ja existeix',\r
- DB_ERROR_CANNOT_CREATE => 'no es pot crear',\r
- DB_ERROR_CANNOT_DELETE => 'no es pot esborrar',\r
- DB_ERROR_CANNOT_DROP => 'no es pot eliminar',\r
- DB_ERROR_CONSTRAINT => 'violació de constraint',\r
- DB_ERROR_DIVZERO => 'divisió per zero',\r
- DB_ERROR_INVALID => 'no és vàlid',\r
- DB_ERROR_INVALID_DATE => 'la data o l\'hora no són vàlides',\r
- DB_ERROR_INVALID_NUMBER => 'el nombre no és vàlid',\r
- DB_ERROR_MISMATCH => 'no hi ha coincidència',\r
- DB_ERROR_NODBSELECTED => 'cap base de dades seleccionada',\r
- DB_ERROR_NOSUCHFIELD => 'camp inexistent',\r
- DB_ERROR_NOSUCHTABLE => 'taula inexistent',\r
- DB_ERROR_NOT_CAPABLE => 'l\'execució secundària de DB no pot',\r
- DB_ERROR_NOT_FOUND => 'no trobat',\r
- DB_ERROR_NOT_LOCKED => 'no blocat',\r
- DB_ERROR_SYNTAX => 'error de sintaxi',\r
- DB_ERROR_UNSUPPORTED => 'no suportat',\r
- DB_ERROR_VALUE_COUNT_ON_ROW => 'el nombre de columnes no coincideix amb el nombre de valors en la fila',\r
- DB_ERROR_INVALID_DSN => 'el DSN no és vàlid',\r
- DB_ERROR_CONNECT_FAILED => 'connexió fallida',\r
- 0 => 'cap error', // DB_OK\r
- DB_ERROR_NEED_MORE_DATA => 'les dades subministrades són insuficients',\r
- DB_ERROR_EXTENSION_NOT_FOUND=> 'extensió no trobada',\r
- DB_ERROR_NOSUCHDB => 'base de dades inexistent',\r
- DB_ERROR_ACCESS_VIOLATION => 'permisos insuficients'\r
-);\r
-?>\r
-
\ No newline at end of file
+<?php
+// Catalan language
+// contributed by "Josep Lladonosa" jlladono#pie.xtec.es
+$ADODB_LANG_ARRAY = array (
+ 'LANG' => 'ca',
+ DB_ERROR => 'error desconegut',
+ DB_ERROR_ALREADY_EXISTS => 'ja existeix',
+ DB_ERROR_CANNOT_CREATE => 'no es pot crear',
+ DB_ERROR_CANNOT_DELETE => 'no es pot esborrar',
+ DB_ERROR_CANNOT_DROP => 'no es pot eliminar',
+ DB_ERROR_CONSTRAINT => 'violació de constraint',
+ DB_ERROR_DIVZERO => 'divisió per zero',
+ DB_ERROR_INVALID => 'no és vàlid',
+ DB_ERROR_INVALID_DATE => 'la data o l\'hora no són vàlides',
+ DB_ERROR_INVALID_NUMBER => 'el nombre no és vàlid',
+ DB_ERROR_MISMATCH => 'no hi ha coincidència',
+ DB_ERROR_NODBSELECTED => 'cap base de dades seleccionada',
+ DB_ERROR_NOSUCHFIELD => 'camp inexistent',
+ DB_ERROR_NOSUCHTABLE => 'taula inexistent',
+ DB_ERROR_NOT_CAPABLE => 'l\'execució secundària de DB no pot',
+ DB_ERROR_NOT_FOUND => 'no trobat',
+ DB_ERROR_NOT_LOCKED => 'no blocat',
+ DB_ERROR_SYNTAX => 'error de sintaxi',
+ DB_ERROR_UNSUPPORTED => 'no suportat',
+ DB_ERROR_VALUE_COUNT_ON_ROW => 'el nombre de columnes no coincideix amb el nombre de valors en la fila',
+ DB_ERROR_INVALID_DSN => 'el DSN no és vàlid',
+ DB_ERROR_CONNECT_FAILED => 'connexió fallida',
+ 0 => 'cap error', // DB_OK
+ DB_ERROR_NEED_MORE_DATA => 'les dades subministrades són insuficients',
+ DB_ERROR_EXTENSION_NOT_FOUND=> 'extensió no trobada',
+ DB_ERROR_NOSUCHDB => 'base de dades inexistent',
+ DB_ERROR_ACCESS_VIOLATION => 'permisos insuficients'
+);
+?>
\ No newline at end of file
-<?php\r
-// contributed by "Levi Fukumori" levi _AT_ fukumori _DOT_ com _DOT_ br\r
-// portugese (brazilian)\r
-$ADODB_LANG_ARRAY = array (\r
- 'LANG' => 'pt-br',\r
- DB_ERROR => 'erro desconhecido',\r
- DB_ERROR_ALREADY_EXISTS => 'já existe',\r
- DB_ERROR_CANNOT_CREATE => 'impossível criar',\r
- DB_ERROR_CANNOT_DELETE => 'impossível excluír',\r
- DB_ERROR_CANNOT_DROP => 'impossível remover',\r
- DB_ERROR_CONSTRAINT => 'violação do confinamente',\r
- DB_ERROR_DIVZERO => 'divisão por zero',\r
- DB_ERROR_INVALID => 'inválido',\r
- DB_ERROR_INVALID_DATE => 'data ou hora inválida',\r
- DB_ERROR_INVALID_NUMBER => 'número inválido',\r
- DB_ERROR_MISMATCH => 'erro',\r
- DB_ERROR_NODBSELECTED => 'nenhum banco de dados selecionado',\r
- DB_ERROR_NOSUCHFIELD => 'campo inválido',\r
- DB_ERROR_NOSUCHTABLE => 'tabela inexistente',\r
- DB_ERROR_NOT_CAPABLE => 'capacidade inválida para este BD',\r
- DB_ERROR_NOT_FOUND => 'não encontrado',\r
- DB_ERROR_NOT_LOCKED => 'não bloqueado',\r
- DB_ERROR_SYNTAX => 'erro de sintaxe',\r
- DB_ERROR_UNSUPPORTED => \r
-'não suportado',\r
- DB_ERROR_VALUE_COUNT_ON_ROW => 'a quantidade de colunas não corresponde ao de valores',\r
- DB_ERROR_INVALID_DSN => 'DSN inválido',\r
- DB_ERROR_CONNECT_FAILED => 'falha na conexão',\r
- 0 => 'sem erro', // DB_OK\r
- DB_ERROR_NEED_MORE_DATA => 'dados insuficientes',\r
- DB_ERROR_EXTENSION_NOT_FOUND=> 'extensão não encontrada',\r
- DB_ERROR_NOSUCHDB => 'banco de dados não encontrado',\r
- DB_ERROR_ACCESS_VIOLATION => 'permissão insuficiente'\r
-);\r
-?>\r
+<?php
+// contributed by "Levi Fukumori" levi _AT_ fukumori _DOT_ com _DOT_ br
+// portugese (brazilian)
+$ADODB_LANG_ARRAY = array (
+ 'LANG' => 'pt-br',
+ DB_ERROR => 'erro desconhecido',
+ DB_ERROR_ALREADY_EXISTS => 'já existe',
+ DB_ERROR_CANNOT_CREATE => 'impossível criar',
+ DB_ERROR_CANNOT_DELETE => 'impossível excluír',
+ DB_ERROR_CANNOT_DROP => 'impossível remover',
+ DB_ERROR_CONSTRAINT => 'violação do confinamente',
+ DB_ERROR_DIVZERO => 'divisão por zero',
+ DB_ERROR_INVALID => 'inválido',
+ DB_ERROR_INVALID_DATE => 'data ou hora inválida',
+ DB_ERROR_INVALID_NUMBER => 'número inválido',
+ DB_ERROR_MISMATCH => 'erro',
+ DB_ERROR_NODBSELECTED => 'nenhum banco de dados selecionado',
+ DB_ERROR_NOSUCHFIELD => 'campo inválido',
+ DB_ERROR_NOSUCHTABLE => 'tabela inexistente',
+ DB_ERROR_NOT_CAPABLE => 'capacidade inválida para este BD',
+ DB_ERROR_NOT_FOUND => 'não encontrado',
+ DB_ERROR_NOT_LOCKED => 'não bloqueado',
+ DB_ERROR_SYNTAX => 'erro de sintaxe',
+ DB_ERROR_UNSUPPORTED =>
+'não suportado',
+ DB_ERROR_VALUE_COUNT_ON_ROW => 'a quantidade de colunas não corresponde ao de valores',
+ DB_ERROR_INVALID_DSN => 'DSN inválido',
+ DB_ERROR_CONNECT_FAILED => 'falha na conexão',
+ 0 => 'sem erro', // DB_OK
+ DB_ERROR_NEED_MORE_DATA => 'dados insuficientes',
+ DB_ERROR_EXTENSION_NOT_FOUND=> 'extensão não encontrada',
+ DB_ERROR_NOSUCHDB => 'banco de dados não encontrado',
+ DB_ERROR_ACCESS_VIOLATION => 'permissão insuficiente'
+);
+?>
\ No newline at end of file
DB_ERROR_NOSUCHDB => 'nu exista baza de date',
DB_ERROR_ACCESS_VIOLATION => 'permisiuni insuficiente'
);
-?>
+?>
\ No newline at end of file
DB_ERROR_NOSUCHDB => 'íå ³ñíóº ÁÄ',
DB_ERROR_ACCESS_VIOLATION => 'íåäîñòàòíüî ïðàâ äîñòóïà'
);
-?>
+?>
\ No newline at end of file
DB_ERROR_NOSUCHDB => 'ไม่มีข้อมูลนี้',
DB_ERROR_ACCESS_VIOLATION => 'permissions ไม่พอ'
);
-?>
+?>
\ No newline at end of file
<?php
/*
-V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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\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
+<?php
+/**
+ * @version V4.93 10 Oct 2006 (c) 2000-2008 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
+ */
+}
?>
\ No newline at end of file
-Description of ADODB v4.96a library import into Moodle
+Description of ADODB v4.98 library import into Moodle
Removed:
* contrib/
* readme_moodle.txt - this file ;-)
Our changes:
- * adodb-lib.inc.php - forced conversion to proper numeric type in _adodb_column_sql()
+ * adodb-lib.inc.php - added support for "F" and "L" types in _adodb_column_sql()
* adodb-lib.inc.php - modify some debug output to be correct XHTML. MDL-12378.
Reported to ADOdb at: http://phplens.com/lens/lensforum/msgs.php?id=17133
Once fixed by adodb guys, we'll return to their official distro.
- * lang/adodb-ar.inc.php lang/adodb-bg.inc.php lang/adodb-bgutf8.inc.php
- lang/adodb-en.inc.php lang/adodb-pl.inc.php lang/adodb-ro.inc.php
- lang/adodb_th.inc.php - Removed leading white space outside PHP open/close tags
- (see http://tracker.moodle.org/browse/MDL-11632).
+
+skodak, iarenaza, moodler
-skodak, iarenaza
$Id$
-<?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
+<?php
+/**
+ * @version V4.93 10 Oct 2006 (c) 2000-2008 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;
+}
?>
\ No newline at end of file
<?php
/*
-V4.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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.96 24 Sept 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
+V4.98 13 Feb 2008 (c) 2000-2008 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\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-2008 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.\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
+<?php
+/*
+V4.93 10 Oct 2006 (c) 2000-2008 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);
+}
+
?>
\ No newline at end of file
-<?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
+<?php
+
+/**
+ * @version V4.93 10 Oct 2006 (c) 2000-2008 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;
+}
?>
\ No newline at end of file
-<?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
+<?php
+/*
+ V4.93 10 Oct 2006 (c) 2000-2008 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;
+}
+
?>
\ No newline at end of file