import of ADODB v4.91 and general cleanup, removed some unused files - see readme_moodle.txt; new session2 code needs a new table, I am going to use the new database functions for that later, for now we are using the old table and old database session code.

This commit is contained in:
skodak
2006-08-21 06:54:00 +00:00
parent 0894b9271e
commit efc7316caa
111 changed files with 7869 additions and 531 deletions
+602
View File
@@ -0,0 +1,602 @@
<?php
/*
@version V4.91 2 Aug 2006 (c) 2000-2006 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.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
Active Record implementation. Superset of Zend Framework's.
Version 0.04
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
// array of ADODB_Active_DB's, indexed by ADODB_Active_Record->_dbat
$_ADODB_ACTIVE_DBS = array();
class ADODB_Active_DB {
var $db; // ADOConnection
var $tables; // assoc array of ADODB_Active_Table objects, indexed by tablename
}
class ADODB_Active_Table {
var $name; // table name
var $flds; // assoc array of adofieldobjs, indexed by fieldname
var $keys; // assoc array of primary keys, indexed by fieldname
var $_created; // only used when stored as a cached file
}
// returns index into $_ADODB_ACTIVE_DBS
function ADODB_SetDatabaseAdapter(&$db)
{
global $_ADODB_ACTIVE_DBS;
foreach($_ADODB_ACTIVE_DBS as $k => $d) {
if ($d->db == $db) return $k;
}
$obj = new ADODB_Active_DB();
$obj->db =& $db;
$obj->tables = array();
$_ADODB_ACTIVE_DBS[] = $obj;
return sizeof($_ADODB_ACTIVE_DBS)-1;
}
class ADODB_Active_Record {
var $_dbat; // associative index pointing to ADODB_Active_DB eg. $ADODB_Active_DBS[_dbat]
var $_table; // tablename, if set in class definition then use it as table name
var $_tableat; // associative index pointing to ADODB_Active_Table, eg $ADODB_Active_DBS[_dbat]->tables[$this->_tableat]
var $_where; // where clause set in Load()
var $_saved = false; // indicates whether data is already inserted.
var $_lasterr = false; // last error message
var $_original = false; // the original values loaded or inserted, refreshed on update
// should be static
function SetDatabaseAdapter(&$db)
{
return ADODB_SetDatabaseAdapter($db);
}
// php4 constructor
function ADODB_Active_Record($table = false, $pkeyarr=false, $db=false)
{
ADODB_Active_Record::__construct($table,$pkeyarr,$db);
}
// php5 constructor
function __construct($table = false, $pkeyarr=false, $db=false)
{
global $ADODB_ASSOC_CASE,$_ADODB_ACTIVE_DBS;
if ($db == false && is_object($pkeyarr)) {
$db = $pkeyarr;
$pkeyarr = false;
}
if (!$table) {
if (!empty($this->_table)) $table = $this->_table;
else $table = $this->_pluralize(get_class($this));
}
if ($db) {
$this->_dbat = ADODB_Active_Record::SetDatabaseAdapter($db);
} else
$this->_dbat = sizeof($_ADODB_ACTIVE_DBS)-1;
if ($this->_dbat < 0) $this->Error("No database connection set; use ADOdb_Active_Record::SetDatabaseAdapter(\$db)",'ADODB_Active_Record::__constructor');
$this->_table = $table;
$this->_tableat = $table; # reserved for setting the assoc value to a non-table name, eg. the sql string in future
$this->UpdateActiveTable($pkeyarr);
}
function _pluralize($table)
{
$ut = strtoupper($table);
$len = strlen($table);
$lastc = $ut[$len-1];
$lastc2 = substr($ut,$len-2);
switch ($lastc) {
case 'S':
return $table.'es';
case 'Y':
return substr($table,0,$len-1).'ies';
case 'X':
return $table.'es';
case 'H':
if ($lastc2 == 'CH' || $lastc2 == 'SH')
return $table.'es';
default:
return $table.'s';
}
}
//////////////////////////////////
// update metadata
function UpdateActiveTable($pkeys=false,$forceUpdate=false)
{
global $ADODB_ASSOC_CASE,$_ADODB_ACTIVE_DBS , $ADODB_CACHE_DIR, $ADODB_ACTIVE_CACHESECS;
$activedb =& $_ADODB_ACTIVE_DBS[$this->_dbat];
$table = $this->_table;
$tables = $activedb->tables;
$tableat = $this->_tableat;
if (!$forceUpdate && !empty($tables[$tableat])) {
$tobj =& $tables[$tableat];
foreach($tobj->flds as $name => $fld)
$this->$name = null;
return;
}
$db =& $activedb->db;
$fname = $ADODB_CACHE_DIR . '/adodb_' . $db->databaseType . '_active_'. $table . '.cache';
if (!$forceUpdate && $ADODB_ACTIVE_CACHESECS && $ADODB_CACHE_DIR && file_exists($fname)) {
$fp = fopen($fname,'r');
@flock($fp, LOCK_SH);
$acttab = unserialize(fread($fp,100000));
fclose($fp);
if ($acttab->_created + $ADODB_ACTIVE_CACHESECS - (abs(rand()) % 16) > time()) {
// abs(rand()) randomizes deletion, reducing contention to delete/refresh file
// ideally, you should cache at least 32 secs
$activedb->tables[$table] = $acttab;
//if ($db->debug) ADOConnection::outp("Reading cached active record file: $fname");
return;
} else if ($db->debug) {
ADOConnection::outp("Refreshing cached active record file: $fname");
}
}
$activetab = new ADODB_Active_Table();
$activetab->name = $table;
$cols = $db->MetaColumns($table);
if (!$cols) {
$this->Error("Invalid table name: $table",'UpdateActiveTable');
return false;
}
$fld = reset($cols);
if (!$pkeys) {
if (isset($fld->primary_key)) {
$pkeys = array();
foreach($cols as $name => $fld) {
if (!empty($fld->primary_key)) $pkeys[] = $name;
}
} else
$pkeys = $this->GetPrimaryKeys($db, $table);
}
if (empty($pkeys)) {
$this->Error("No primary key found for table $table",'UpdateActiveTable');
return false;
}
$attr = array();
$keys = array();
switch($ADODB_ASSOC_CASE) {
case 0:
foreach($cols as $name => $fldobj) {
$name = strtolower($name);
$this->$name = null;
$attr[$name] = $fldobj;
}
foreach($pkeys as $k => $name) {
$keys[strtolower($name)] = strtolower($name);
}
break;
case 1:
foreach($cols as $name => $fldobj) {
$name = strtoupper($name);
$this->$name = null;
$attr[$name] = $fldobj;
}
foreach($pkeys as $k => $name) {
$keys[strtoupper($name)] = strtoupper($name);
}
break;
default:
foreach($cols as $name => $fldobj) {
$name = ($name);
$this->$name = null;
$attr[$name] = $fldobj;
}
foreach($pkeys as $k => $name) {
$keys[$name] = ($name);
}
break;
}
$activetab->keys = $keys;
$activetab->flds = $attr;
if ($ADODB_ACTIVE_CACHESECS && $ADODB_CACHE_DIR) {
$activetab->_created = time();
$s = serialize($activetab);
if (!function_exists('adodb_write_file')) include(ADODB_DIR.'/adodb-csvlib.inc.php');
adodb_write_file($fname,$s);
}
$activedb->tables[$table] = $activetab;
}
function GetPrimaryKeys(&$db, $table)
{
return $db->MetaPrimaryKeys($table);
}
// error handler for both PHP4+5.
function Error($err,$fn)
{
global $_ADODB_ACTIVE_DBS;
$fn = get_class($this).'::'.$fn;
$this->_lasterr = $fn.': '.$err;
if ($this->_dbat < 0) $db = false;
else {
$activedb = $_ADODB_ACTIVE_DBS[$this->_dbat];
$db =& $activedb->db;
}
if (function_exists('adodb_throw')) {
if (!$db) adodb_throw('ADOdb_Active_Record', $fn, -1, $err, 0, 0, false);
else adodb_throw($db->databaseType, $fn, -1, $err, 0, 0, $db);
} else
if (!$db || $db->debug) ADOConnection::outp($this->_lasterr);
}
// return last error message
function ErrorMsg()
{
if (!function_exists('adodb_throw')) {
if ($this->_dbat < 0) $db = false;
else $db = $this->DB();
// last error could be database error too
if ($db && $db->ErrorMsg()) return $db->ErrorMsg();
}
return $this->_lasterr;
}
// retrieve ADOConnection from _ADODB_Active_DBs
function &DB()
{
global $_ADODB_ACTIVE_DBS;
if ($this->_dbat < 0) {
$false = false;
$this->Error("No database connection set: use ADOdb_Active_Record::SetDatabaseAdaptor(\$db)", "DB");
return $false;
}
$activedb = $_ADODB_ACTIVE_DBS[$this->_dbat];
$db =& $activedb->db;
return $db;
}
// retrieve ADODB_Active_Table
function &TableInfo()
{
global $_ADODB_ACTIVE_DBS;
$activedb = $_ADODB_ACTIVE_DBS[$this->_dbat];
$table =& $activedb->tables[$this->_tableat];
return $table;
}
// set a numeric array (using natural table field ordering) as object properties
function Set(&$row)
{
$db =& $this->DB();
if (!$row) {
$this->_saved = false;
return false;
}
$this->_saved = true;
$table =& $this->TableInfo();
if (sizeof($table->flds) != sizeof($row)) {
$this->Error("Table structure of $this->_table has changed","Load");
return false;
}
$cnt = 0;
foreach($table->flds as $name=>$fld) {
$this->$name = $row[$cnt];
$cnt += 1;
}
$this->_original = $row;
return true;
}
// get last inserted id for INSERT
function LastInsertID(&$db,$fieldname)
{
if ($db->hasInsertID)
$val = $db->Insert_ID($this->_table,$fieldname);
else
$val = false;
if (is_null($val) || $val === false) {
// this might not work reliably in multi-user environment
return $db->GetOne("select max(".$fieldname.") from ".$this->_table);
}
return $val;
}
// quote data in where clause
function doquote(&$db, $val,$t)
{
switch($t) {
case 'D':
case 'T':
if (empty($val)) return 'null';
case 'C':
case 'X':
if (is_null($val)) return 'null';
if (strncmp($val,"'",1) != 0 && substr($val,strlen($val)-1,1) != "'") {
return $db->qstr($val);
break;
}
default:
return $val;
break;
}
}
// generate where clause for an UPDATE/SELECT
function GenWhere(&$db, &$table)
{
$keys = $table->keys;
$parr = array();
foreach($keys as $k) {
$f = $table->flds[$k];
if ($f) {
$parr[] = $k.' = '.$this->doquote($db,$this->$k,$db->MetaType($f->type));
}
}
return implode(' and ', $parr);
}
//------------------------------------------------------------ Public functions below
function Load($where,$bindarr=false)
{
$db =& $this->DB(); if (!$db) return false;
$this->_where = $where;
$save = $db->SetFetchMode(ADODB_FETCH_NUM);
$row = $db->GetRow("select * from ".$this->_table.' WHERE '.$where,$bindarr);
$db->SetFetchMode($save);
return $this->Set($row);
}
// false on error
function Save()
{
if ($this->_saved) $ok = $this->Update();
else $ok = $this->Insert();
return $ok;
}
// false on error
function Insert()
{
$db =& $this->DB(); if (!$db) return false;
$cnt = 0;
$table =& $this->TableInfo();
$valarr = array();
$names = array();
$valstr = array();
foreach($table->flds as $name=>$fld) {
$val = $this->$name;
if(!is_null($val) || !array_key_exists($name, $table->keys)) {
$valarr[] = $val;
$names[] = $name;
$valstr[] = $db->Param($cnt);
$cnt += 1;
}
}
if (empty($names)){
foreach($table->flds as $name=>$fld) {
$valarr[] = null;
$names[] = $name;
$valstr[] = $db->Param($cnt);
$cnt += 1;
}
}
$sql = 'INSERT INTO '.$this->_table."(".implode(',',$names).') VALUES ('.implode(',',$valstr).')';
$ok = $db->Execute($sql,$valarr);
if ($ok) {
$this->_saved = true;
$autoinc = false;
foreach($table->keys as $k) {
if (is_null($this->$k)) {
$autoinc = true;
break;
}
}
if ($autoinc && sizeof($table->keys) == 1) {
$k = reset($table->keys);
$this->$k = $this->LastInsertID($db,$k);
}
}
$this->_original = $valarr;
return !empty($ok);
}
function Delete()
{
$db =& $this->DB(); if (!$db) return false;
$table =& $this->TableInfo();
$where = $this->GenWhere($db,$table);
$sql = 'DELETE FROM '.$this->_table.' WHERE '.$where;
$ok = $db->Execute($sql);
return $ok ? true : false;
}
// returns an array of active record objects
function &Find($whereOrderBy,$bindarr=false,$pkeysArr=false)
{
$db =& $this->DB(); if (!$db || empty($this->_table)) return false;
$arr =& $db->GetActiveRecordsClass(get_class($this),$this->_table, $whereOrderBy,$bindarr,$pkeysArr);
return $arr;
}
// returns 0 on error, 1 on update, 2 on insert
function Replace()
{
global $ADODB_ASSOC_CASE;
$db =& $this->DB(); if (!$db) return false;
$table =& $this->TableInfo();
$pkey = $table->keys;
foreach($table->flds as $name=>$fld) {
$val = $this->$name;
/*
if (is_null($val)) {
if (isset($fld->not_null) && $fld->not_null) {
if (isset($fld->default_value) && strlen($fld->default_value)) continue;
else {
$this->Error("Cannot update null into $name","Replace");
return false;
}
}
}*/
if (is_null($val) && !empty($fld->auto_increment)) {
continue;
}
$t = $db->MetaType($fld->type);
$arr[$name] = $this->doquote($db,$val,$t);
$valarr[] = $val;
}
if (!is_array($pkey)) $pkey = array($pkey);
if ($ADODB_ASSOC_CASE == 0)
foreach($pkey as $k => $v)
$pkey[$k] = strtolower($v);
elseif ($ADODB_ASSOC_CASE == 0)
foreach($pkey as $k => $v)
$pkey[$k] = strtoupper($v);
$ok = $db->Replace($this->_table,$arr,$pkey);
if ($ok) {
$this->_saved = true; // 1= update 2=insert
if ($ok == 2) {
$autoinc = false;
foreach($table->keys as $k) {
if (is_null($this->$k)) {
$autoinc = true;
break;
}
}
if ($autoinc && sizeof($table->keys) == 1) {
$k = reset($table->keys);
$this->$k = $this->LastInsertID($db,$k);
}
}
$this->_original =& $valarr;
}
return $ok;
}
// returns 0 on error, 1 on update, -1 if no change in data (no update)
function Update()
{
$db =& $this->DB(); if (!$db) return false;
$table =& $this->TableInfo();
$where = $this->GenWhere($db, $table);
if (!$where) {
$this->error("Where missing for table $table", "Update");
return false;
}
$valarr = array();
$neworig = array();
$pairs = array();
$i = -1;
$cnt = 0;
foreach($table->flds as $name=>$fld) {
$i += 1;
$val = $this->$name;
$neworig[] = $val;
if (isset($table->keys[$name])) {
continue;
}
if (is_null($val)) {
if (isset($fld->not_null) && $fld->not_null) {
if (isset($fld->default_value) && strlen($fld->default_value)) continue;
else {
$this->Error("Cannot set field $name to NULL","Update");
return false;
}
}
}
if (isset($this->_original[$i]) && $val == $this->_original[$i]) {
continue;
}
$valarr[] = $val;
$pairs[] = $name.'='.$db->Param($cnt);
$cnt += 1;
}
if (!$cnt) return -1;
$sql = 'UPDATE '.$this->_table." SET ".implode(",",$pairs)." WHERE ".$where;
$ok = $db->Execute($sql,$valarr);
if ($ok) {
$this->_original =& $neworig;
return 1;
}
return 0;
}
function GetAttributeNames()
{
$table =& $this->TableInfo();
if (!$table) return false;
return array_keys($table->flds);
}
};
?>
+1 -1
View File
@@ -8,7 +8,7 @@ $ADODB_INCLUDED_CSV = 1;
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence. See License.txt.
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
/**
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/**
* @version V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
* @version V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
* Released under both BSD license and Lesser GPL library license.
* Whenever there is any discrepancy between the two licenses,
* the BSD license will take precedence.
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/**
* @version V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
* @version V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
* Released under both BSD license and Lesser GPL library license.
* Whenever there is any discrepancy between the two licenses,
* the BSD license will take precedence.
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/**
* @version V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
* @version V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
* Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+5 -3
View File
@@ -1,7 +1,7 @@
<?php
/**
* @version V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
* @version V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
* Released under both BSD license and Lesser GPL library license.
* Whenever there is any discrepancy between the two licenses,
* the BSD license will take precedence.
@@ -45,8 +45,10 @@ var $database = '';
}
$this->dbms = $dbms;
$this->host = $thisConnection->host;
$this->database = $thisConnection->database;
if ($thisConnection) {
$this->host = $thisConnection->host;
$this->database = $thisConnection->database;
}
$this->fn = $fn;
$this->msg = $errmsg;
+2 -1
View File
@@ -1,7 +1,7 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
@@ -81,4 +81,5 @@ class ADODB_BASE_RS implements IteratorAggregate {
}
}
?>
+59 -5
View File
@@ -7,7 +7,7 @@ global $ADODB_INCLUDED_LIB;
$ADODB_INCLUDED_LIB = 1;
/*
@version V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim\@natsoft.com.my). All rights reserved.
@version V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim\@natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence. See License.txt.
@@ -156,7 +156,7 @@ function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=f
if ($fieldsize > 2) {
$group = rtrim($zthis->fields[2]);
}
/*
if ($optgroup != $group) {
$optgroup = $group;
if ($firstgroup) {
@@ -167,7 +167,7 @@ function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=f
$s .="\n<optgroup label='". htmlspecialchars($group) ."'>";
}
}
*/
if ($hasvalue)
$value = " value='".htmlspecialchars($zval2)."'";
@@ -283,7 +283,7 @@ function _adodb_getmenu_gp(&$zthis, $name,$defstr='',$blank1stItem=true,$multipl
/*
Count the number of records this sql statement will return by using
query rewriting techniques...
query rewriting heuristics...
Does not work with UNIONs, except with postgresql and oracle.
@@ -325,12 +325,22 @@ function _adodb_getcount(&$zthis, $sql,$inputarr=false,$secs2cache=0)
$rewritesql = preg_replace(
'/^\s*SELECT\s.*\s+FROM\s/Uis','SELECT COUNT(*) FROM ',$sql);
// fix by alexander zhukov, alex#unipack.ru, because count(*) and 'order by' fails
// with mssql, access and postgresql. Also a good speedup optimization - skips sorting!
$rewritesql = preg_replace('/(\sORDER\s+BY\s[^)]*)/is','',$rewritesql);
// also see http://phplens.com/lens/lensforum/msgs.php?id=12752
if (preg_match('/\sORDER\s+BY\s*\(/i',$rewritesql))
$rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$rewritesql);
else
$rewritesql = preg_replace('/(\sORDER\s+BY\s[^)]*)/is','',$rewritesql);
}
if (isset($rewritesql) && $rewritesql != $sql) {
if (preg_match('/\sLIMIT\s+[0-9]+/i',$sql,$limitarr)) $rewritesql .= $limitarr[1];
if ($secs2cache) {
// we only use half the time of secs2cache because the count can quickly
// become inaccurate if new records are added
@@ -349,6 +359,8 @@ function _adodb_getcount(&$zthis, $sql,$inputarr=false,$secs2cache=0)
if (preg_match('/\s*UNION\s*/is', $sql)) $rewritesql = $sql;
else $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$sql);
if (preg_match('/\sLIMIT\s+[0-9]+/i',$sql,$limitarr)) $rewritesql .= $limitarr[0];
$rstest = &$zthis->Execute($rewritesql,$inputarr);
if (!$rstest) $rstest = $zthis->Execute($sql,$inputarr);
@@ -1012,5 +1024,47 @@ function _adodb_backtrace($printOrArr=true,$levels=9999,$skippy=0)
return $s;
}
/*
function _adodb_find_from($sql)
{
$sql = str_replace(array("\n","\r"), ' ', $sql);
$charCount = strlen($sql);
$inString = false;
$quote = '';
$parentheseCount = 0;
$prevChars = '';
$nextChars = '';
for($i = 0; $i < $charCount; $i++) {
$char = substr($sql,$i,1);
$prevChars = substr($sql,0,$i);
$nextChars = substr($sql,$i+1);
if((($char == "'" || $char == '"' || $char == '`') && substr($prevChars,-1,1) != '\\') && $inString === false) {
$quote = $char;
$inString = true;
}
elseif((($char == "'" || $char == '"' || $char == '`') && substr($prevChars,-1,1) != '\\') && $inString === true && $quote == $char) {
$quote = "";
$inString = false;
}
elseif($char == "(" && $inString === false)
$parentheseCount++;
elseif($char == ")" && $inString === false && $parentheseCount > 0)
$parentheseCount--;
elseif($parentheseCount <= 0 && $inString === false && $char == " " && strtoupper(substr($prevChars,-5,5)) == " FROM")
return $i;
}
}
*/
?>
+3 -3
View File
@@ -1,7 +1,7 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
@@ -60,7 +60,7 @@ class ADODB_Pager {
global $PHP_SELF;
$curr_page = $id.'_curr_page';
if (empty($PHP_SELF)) $PHP_SELF = $_SERVER['PHP_SELF'];
if (empty($PHP_SELF)) $PHP_SELF = htmlspecialchars($_SERVER['PHP_SELF']); // htmlspecialchars() to prevent XSS attacks
$this->sql = $sql;
$this->id = $id;
@@ -70,7 +70,7 @@ class ADODB_Pager {
$next_page = $id.'_next_page';
if (isset($_GET[$next_page])) {
$_SESSION[$curr_page] = $_GET[$next_page];
$_SESSION[$curr_page] = (integer) $_GET[$next_page];
}
if (empty($_SESSION[$curr_page])) $_SESSION[$curr_page] = 1; ## at first page
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/**
* @version V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
* @version V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
* Released under both BSD license and Lesser GPL library license.
* Whenever there is any discrepancy between the two licenses,
* the BSD license will take precedence.
+6 -3
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence. See License.txt.
@@ -71,7 +71,7 @@ function& adodb_log_sql(&$conn,$sql,$inputarr)
$rs =& $conn->Execute($sql,$inputarr);
$t1 = microtime();
if (!empty($conn->_logsql)) {
if (!empty($conn->_logsql) && (empty($conn->_logsqlErrors) || !$rs)) {
$conn->_logsql = false; // disable logsql error simulation
$dbT = $conn->databaseType;
@@ -149,6 +149,7 @@ function& adodb_log_sql(&$conn,$sql,$inputarr)
if ($dbT == 'informix') $isql = str_replace(chr(10),' ',$isql);
$arr = false;
} else {
if ($dbT == 'db2') $arr['f'] = (float) $arr['f'];
$isql = "insert into $perf_table (created,sql0,sql1,params,tracer,timer) values( $d,?,?,?,?,?)";
}
@@ -860,8 +861,10 @@ Committed_AS: 348732 kB
{
if (!$this->createTableSQL) return false;
$table = $this->table();
$sql = str_replace('adodb_logsql',$table,$this->createTableSQL);
$savelog = $this->conn->LogSQL(false);
$ok = $this->conn->Execute($this->createTableSQL);
$ok = $this->conn->Execute($sql);
$this->conn->LogSQL($savelog);
return ($ok) ? true : false;
}
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+30 -5
View File
@@ -108,7 +108,7 @@ The format fields that adodb_date supports:
n - month without leading zeros; i.e. "1" to "12"
O - Difference to Greenwich time in hours; e.g. "+0200"
Q - Quarter, as in 1, 2, 3, 4
r - RFC 822 formatted date; e.g. "Thu, 21 Dec 2000 16:01:07 +0200"
r - RFC 2822 formatted date; e.g. "Thu, 21 Dec 2000 16:01:07 +0200"
s - seconds; i.e. "00" to "59"
S - English ordinal suffix for the day of the month, 2 characters;
i.e. "st", "nd", "rd" or "th"
@@ -241,6 +241,13 @@ b. Implement daylight savings, which looks awfully complicated, see
CHANGELOG
- 19 March 2006 0.24
Changed strftime() locale detection, because some locales prepend the day of week to the date when %c is used.
- 10 Feb 2006 0.23
PHP5 compat: when we detect PHP5, the RFC2822 format for gmt 0000hrs is changed from -0000 to +0000.
In PHP4, we will still use -0000 for 100% compat with PHP4.
- 08 Sept 2005 0.22
In adodb_date2(), $is_gmt not supported properly. Fixed.
@@ -361,7 +368,7 @@ First implementation.
/*
Version Number
*/
define('ADODB_DATE_VERSION',0.22);
define('ADODB_DATE_VERSION',0.24);
/*
This code was originally for windows. But apparently this problem happens
@@ -473,7 +480,7 @@ function adodb_date_test()
// Test string formating
print "<p>Testing date formating</p>";
$fmt = '\d\a\t\e T Y-m-d H:i:s a A d D F g G h H i j l L m M n O \R\F\C822 r s t U w y Y z Z 2003';
$fmt = '\d\a\t\e T Y-m-d H:i:s a A d D F g G h H i j l L m M n O \R\F\C2822 r s t U w y Y z Z 2003';
$s1 = date($fmt,0);
$s2 = adodb_date($fmt,0);
if ($s1 != $s2) {
@@ -977,6 +984,8 @@ static $daylight;
$max = strlen($fmt);
$dates = '';
$isphp5 = PHP_VERSION >= 5;
/*
at this point, we have the following integer vars to manipulate:
$year, $month, $day, $hour, $min, $secs
@@ -1000,7 +1009,11 @@ static $daylight;
if ($secs < 10) $dates .= ':0'.$secs; else $dates .= ':'.$secs;
$gmt = adodb_get_gmt_diff();
$dates .= sprintf(' %s%04d',($gmt<0)?'+':'-',abs($gmt)/36); break;
if ($isphp5)
$dates .= sprintf(' %s%04d',($gmt<=0)?'+':'-',abs($gmt)/36);
else
$dates .= sprintf(' %s%04d',($gmt<0)?'+':'-',abs($gmt)/36);
break;
case 'Y': $dates .= $year; break;
case 'y': $dates .= substr($year,strlen($year)-2,2); break;
@@ -1031,7 +1044,12 @@ static $daylight;
$dates .= ($is_gmt) ? 0 : -adodb_get_gmt_diff(); break;
case 'O':
$gmt = ($is_gmt) ? 0 : adodb_get_gmt_diff();
$dates .= sprintf('%s%04d',($gmt<0)?'+':'-',abs($gmt)/36); break;
if ($isphp5)
$dates .= sprintf('%s%04d',($gmt<=0)?'+':'-',abs($gmt)/36);
else
$dates .= sprintf('%s%04d',($gmt<0)?'+':'-',abs($gmt)/36);
break;
case 'H':
if ($hour < 10) $dates .= '0'.$hour;
@@ -1224,9 +1242,16 @@ global $ADODB_DATE_LOCALE;
}
if (empty($ADODB_DATE_LOCALE)) {
/*
$tstr = strtoupper(gmstrftime('%c',31366800)); // 30 Dec 1970, 1 am
$sep = substr($tstr,2,1);
$hasAM = strrpos($tstr,'M') !== false;
*/
# see http://phplens.com/lens/lensforum/msgs.php?id=14865 for reasoning, and changelog for version 0.24
$dstr = gmstrftime('%x',31366800); // 30 Dec 1970, 1 am
$sep = substr($dstr,2,1);
$tstr = strtoupper(gmstrftime('%X',31366800)); // 30 Dec 1970, 1 am
$hasAM = strrpos($tstr,'M') !== false;
$ADODB_DATE_LOCALE = array();
$ADODB_DATE_LOCALE[] = strncmp($tstr,'30',2) == 0 ? 'd'.$sep.'m'.$sep.'y' : 'm'.$sep.'d'.$sep.'y';
File diff suppressed because it is too large Load Diff
+187 -42
View File
@@ -14,7 +14,7 @@
/**
\mainpage
@version V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
@version V4.91 2 Aug 2006 (c) 2000-2006 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.
@@ -171,7 +171,7 @@
/**
* ADODB version as a string.
*/
$ADODB_vers = 'V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved. Released BSD & LGPL.';
$ADODB_vers = 'V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved. Released BSD & LGPL.';
/**
* Determines whether recordset->RecordCount() is used.
@@ -314,7 +314,7 @@
var $_evalAll = false;
var $_affected = false;
var $_logsql = false;
var $_transmode = ''; // transaction mode
/**
* Constructor
@@ -554,6 +554,7 @@
function q(&$s)
{
#if (!empty($this->qNull)) if ($s == 'null') return $s;
$s = $this->qstr($s,false);
}
@@ -801,6 +802,8 @@
$element0 = reset($inputarr);
# is_object check because oci8 descriptors can be passed in
$array_2d = is_array($element0) && !is_object(reset($element0));
//remove extra memory copy of input -mikefedyk
unset($element0);
if (!is_array($sql) && !$this->_bindInputArray) {
$sqlarr = explode('?',$sql);
@@ -808,18 +811,23 @@
if (!$array_2d) $inputarr = array($inputarr);
foreach($inputarr as $arr) {
$sql = ''; $i = 0;
foreach($arr as $v) {
//Use each() instead of foreach to reduce memory usage -mikefedyk
while(list(, $v) = each($arr)) {
$sql .= $sqlarr[$i];
// from Ron Baldwin <ron.baldwin#sourceprose.com>
// Only quote string types
$typ = gettype($v);
if ($typ == 'string')
//New memory copy of input created here -mikefedyk
$sql .= $this->qstr($v);
else if ($typ == 'double')
$sql .= str_replace(',','.',$v); // locales fix so 1.1 does not get converted to 1,1
else if ($typ == 'boolean')
$sql .= $v ? $this->true : $this->false;
else if ($v === null)
else if ($typ == 'object') {
if (method_exists($v, '__toString')) $sql .= $this->qstr($v->__toString());
else $sql .= $this->qstr((string) $v);
} else if ($v === null)
$sql .= 'NULL';
else
$sql .= $v;
@@ -861,7 +869,7 @@
{
if ($this->debug) {
global $ADODB_INCLUDED_LIB;
if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php');
if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
$this->_queryID = _adodb_debug_execute($this, $sql,$inputarr);
} else {
$this->_queryID = @$this->_query($sql,$inputarr);
@@ -1107,7 +1115,7 @@
$sql = preg_replace(
'/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop.' '.((integer)$nrows).' ',$sql);
if ($secs2cache>0) {
if ($secs2cache >= 0) {
$ret =& $this->CacheExecute($secs2cache, $sql,$inputarr);
} else {
$ret =& $this->Execute($sql,$inputarr);
@@ -1140,10 +1148,10 @@
$ADODB_COUNTRECS = false;
if ($offset>0){
if ($secs2cache>0) $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr);
if ($secs2cache >= 0) $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr);
else $rs = &$this->Execute($sql,$inputarr);
} else {
if ($secs2cache>0) $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr);
if ($secs2cache >= 0) $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr);
else $rs = &$this->Execute($sql,$inputarr);
}
$ADODB_COUNTRECS = $savec;
@@ -1340,7 +1348,6 @@
return '('.$date.'+'.$dayFraction.')';
}
/**
*
* @param sql SQL statement
@@ -1458,7 +1465,7 @@
function Replace($table, $fieldArray, $keyCol, $autoQuote=false, $has_autoinc=false)
{
global $ADODB_INCLUDED_LIB;
if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php');
if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
return _adodb_replace($this, $table, $fieldArray, $keyCol, $autoQuote, $has_autoinc);
}
@@ -1506,11 +1513,11 @@
* Flush cached recordsets that match a particular $sql statement.
* If $sql == false, then we purge all files in the cache.
*/
function CacheFlush($sql=false,$inputarr=false)
{
global $ADODB_CACHE_DIR;
if (strlen($ADODB_CACHE_DIR) > 1 && !$sql) {
function CacheFlush($sql=false,$inputarr=false)
{
global $ADODB_CACHE_DIR;
if (strlen($ADODB_CACHE_DIR) > 1 && !$sql) {
/*if (strncmp(PHP_OS,'WIN',3) === 0)
$dir = str_replace('/', '\\', $ADODB_CACHE_DIR);
else */
@@ -1525,7 +1532,7 @@
}
global $ADODB_INCLUDED_CSV;
if (empty($ADODB_INCLUDED_CSV)) include_once(ADODB_DIR.'/adodb-csvlib.inc.php');
if (empty($ADODB_INCLUDED_CSV)) include(ADODB_DIR.'/adodb-csvlib.inc.php');
$f = $this->_gencachename($sql.serialize($inputarr),false);
adodb_write_file($f,''); // is adodb_write_file needed?
@@ -1577,7 +1584,7 @@
}
global $ADODB_INCLUDED_CSV;
if (empty($ADODB_INCLUDED_CSV)) include_once(ADODB_DIR.'/adodb-csvlib.inc.php');
if (empty($ADODB_INCLUDED_CSV)) include(ADODB_DIR.'/adodb-csvlib.inc.php');
$f = $this->_gencachename($sql.serialize($inputarr),false);
adodb_write_file($f,''); // is adodb_write_file needed?
@@ -1652,7 +1659,7 @@
$sqlparam = $sql;
global $ADODB_INCLUDED_CSV;
if (empty($ADODB_INCLUDED_CSV)) include_once(ADODB_DIR.'/adodb-csvlib.inc.php');
if (empty($ADODB_INCLUDED_CSV)) include(ADODB_DIR.'/adodb-csvlib.inc.php');
$md5file = $this->_gencachename($sql.serialize($inputarr),true);
$err = '';
@@ -1728,15 +1735,16 @@
*/
function& AutoExecute($table, $fields_values, $mode = 'INSERT', $where = FALSE, $forceUpdate=true, $magicq=false)
{
$false = false;
$sql = 'SELECT * FROM '.$table;
if ($where!==FALSE) $sql .= ' WHERE '.$where;
else if ($mode == 'UPDATE' || $mode == 2 /* DB_AUTOQUERY_UPDATE */) {
ADOConnection::outp('AutoExecute: Illegal mode=UPDATE with empty WHERE clause');
return false;
return $false;
}
$rs =& $this->SelectLimit($sql,1);
if (!$rs) return false; // table does not exist
if (!$rs) return $false; // table does not exist
$rs->tableName = $table;
switch((string) $mode) {
@@ -1750,7 +1758,7 @@
break;
default:
ADOConnection::outp("AutoExecute: Unknown mode=$mode");
return false;
return $false;
}
$ret = false;
if ($sql) $ret = $this->Execute($sql);
@@ -1783,13 +1791,10 @@
}
//********************************************************//
if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php');
if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
return _adodb_getupdatesql($this,$rs,$arrFields,$forceUpdate,$magicq,$force);
}
/**
* Generates an Insert Query based on an existing recordset.
* $arrFields is an associative array of fields with the value
@@ -1806,7 +1811,7 @@
$force = $ADODB_FORCE_TYPE;
}
if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php');
if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
return _adodb_getinsertsql($this,$rs,$arrFields,$magicq,$force);
}
@@ -1911,8 +1916,8 @@
if (empty($this->_metars)) {
$rsclass = $this->rsPrefix.$this->databaseType;
$this->_metars =& new $rsclass(false,$this->fetchMode);
$this->_metars->connection =& $this;
}
return $this->_metars->MetaType($t,$len,$fieldobj);
}
@@ -1956,6 +1961,48 @@
}
}
function &GetActiveRecordsClass($class, $table,$whereOrderBy=false,$bindarr=false, $primkeyArr=false)
{
global $_ADODB_ACTIVE_DBS;
$save = $this->SetFetchMode(ADODB_FETCH_NUM);
if (empty($whereOrderBy)) $whereOrderBy = '1=1';
$rows = $this->GetAll("select * from ".$table.' WHERE '.$whereOrderBy,$bindarr);
$this->SetFetchMode($save);
$false = false;
if ($rows === false) {
return $false;
}
if (!isset($_ADODB_ACTIVE_DBS)) {
include(ADODB_DIR.'/adodb-active-record.inc.php');
}
if (!class_exists($class)) {
ADOConnection::outp("Unknown class $class in GetActiveRcordsClass()");
return $false;
}
$arr = array();
foreach($rows as $row) {
$obj =& new $class($table,$primkeyArr,$this);
if ($obj->ErrorMsg()){
$this->_errorMsg = $obj->ErrorMsg();
return $false;
}
$obj->Set($row);
$arr[] =& $obj;
}
return $arr;
}
function &GetActiveRecords($table,$where=false,$bindarr=false,$primkeyArr=false)
{
$arr =& $this->GetActiveRecordsClass('ADODB_Active_Record', $table, $where, $bindarr, $primkeyArr);
return $arr;
}
/**
* Close Connection
@@ -1974,6 +2021,57 @@
*/
function BeginTrans() {return false;}
/* set transaction mode */
function SetTransactionMode( $transaction_mode )
{
$transaction_mode = $this->MetaTransaction($transaction_mode, $this->dataProvider);
$this->_transmode = $transaction_mode;
}
/*
http://msdn2.microsoft.com/en-US/ms173763.aspx
http://dev.mysql.com/doc/refman/5.0/en/innodb-transaction-isolation.html
http://www.postgresql.org/docs/8.1/interactive/sql-set-transaction.html
http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_10005.htm
*/
function MetaTransaction($mode,$db)
{
$mode = strtoupper($mode);
$mode = str_replace('ISOLATION LEVEL ','',$mode);
switch($mode) {
case 'READ UNCOMMITTED':
switch($db) {
case 'oci8':
case 'oracle':
return 'ISOLATION LEVEL READ COMMITTED';
default:
return 'ISOLATION LEVEL READ UNCOMMITTED';
}
break;
case 'READ COMMITTED':
return 'ISOLATION LEVEL READ COMMITTED';
break;
case 'REPEATABLE READ':
switch($db) {
case 'oci8':
case 'oracle':
return 'ISOLATION LEVEL SERIALIZABLE';
default:
return 'ISOLATION LEVEL REPEATABLE READ';
}
break;
case 'SERIALIZABLE':
return 'ISOLATION LEVEL SERIALIZABLE';
break;
default:
return $mode;
}
}
/**
* If database does not support transactions, always return true as data always commited
@@ -2020,6 +2118,7 @@
return false;
}
/**
* @param ttype can either be 'VIEW' or 'TABLE' or false.
@@ -2164,7 +2263,7 @@
*
* @return array of column names for current table.
*/
function &MetaColumnNames($table, $numIndexes=false)
function &MetaColumnNames($table, $numIndexes=false,$useattnum=false /* only for postgres */)
{
$objarr =& $this->MetaColumns($table);
if (!is_array($objarr)) {
@@ -2174,7 +2273,12 @@
$arr = array();
if ($numIndexes) {
$i = 0;
foreach($objarr as $v) $arr[$i++] = $v->name;
if ($useattnum) {
foreach($objarr as $v)
$arr[$v->attnum] = $v->name;
} else
foreach($objarr as $v) $arr[$i++] = $v->name;
} else
foreach($objarr as $v) $arr[strtoupper($v->name)] = $v->name;
@@ -2218,6 +2322,22 @@
return adodb_date($this->fmtDate,$d);
}
function BindDate($d)
{
$d = $this->DBDate($d);
if (strncmp($d,"'",1)) return $d;
return substr($d,1,strlen($d)-2);
}
function BindTimeStamp($d)
{
$d = $this->DBTimeStamp($d);
if (strncmp($d,"'",1)) return $d;
return substr($d,1,strlen($d)-2);
}
/**
* Converts a timestamp "ts" to a string that the database can understand.
@@ -2420,7 +2540,7 @@
function &PageExecute($sql, $nrows, $page, $inputarr=false, $secs2cache=0)
{
global $ADODB_INCLUDED_LIB;
if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php');
if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
if ($this->pageExecuteCountRows) $rs =& _adodb_pageexecute_all_rows($this, $sql, $nrows, $page, $inputarr, $secs2cache);
else $rs =& _adodb_pageexecute_no_last_page($this, $sql, $nrows, $page, $inputarr, $secs2cache);
return $rs;
@@ -2492,7 +2612,7 @@
//==============================================================================================
// DATE AND TIME FUNCTIONS
//==============================================================================================
include_once(ADODB_DIR.'/adodb-time.inc.php');
if (!defined('ADODB_DATE_VERSION')) include(ADODB_DIR.'/adodb-time.inc.php');
//==============================================================================================
// CLASS ADORecordSet
@@ -2603,7 +2723,7 @@
$size=0, $selectAttr='',$compareFields0=true)
{
global $ADODB_INCLUDED_LIB;
if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php');
if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
return _adodb_getmenu($this, $name,$defstr,$blank1stItem,$multiple,
$size, $selectAttr,$compareFields0);
}
@@ -2630,7 +2750,7 @@
$size=0, $selectAttr='')
{
global $ADODB_INCLUDED_LIB;
if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php');
if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
return _adodb_getmenu_gp($this, $name,$defstr,$blank1stItem,$multiple,
$size, $selectAttr,false);
}
@@ -2747,7 +2867,17 @@
if ($ADODB_EXTENSION) {
if ($numIndex) {
while (!$this->EOF) {
$results[trim($this->fields[0])] = array_slice($this->fields, 1);
// $results[trim($this->fields[0])] = array_slice($this->fields, 1);
// Fix for array_slice re-numbering numeric associative keys in PHP5
$keys = array_slice(array_keys($this->fields), 1);
$sliced_array = array();
foreach($keys as $key) {
$sliced_array[$key] = $this->fields[$key];
}
$results[trim(reset($this->fields))] = $sliced_array;
adodb_movenext($this);
}
} else {
@@ -2759,7 +2889,16 @@
} else {
if ($numIndex) {
while (!$this->EOF) {
$results[trim($this->fields[0])] = array_slice($this->fields, 1);
//$results[trim($this->fields[0])] = array_slice($this->fields, 1);
// Fix for array_slice re-numbering numeric associative keys in PHP5
$keys = array_slice(array_keys($this->fields), 1);
$sliced_array = array();
foreach($keys as $key) {
$sliced_array[$key] = $this->fields[$key];
}
$results[trim(reset($this->fields))] = $sliced_array;
$this->MoveNext();
}
} else {
@@ -3146,6 +3285,7 @@
return $lnumrows;
}
/**
* @return the current row in the recordset. If at EOF, will return the last row. 0-based.
*/
@@ -3316,6 +3456,7 @@
'BPCHAR' => 'C',
'CHARACTER' => 'C',
'INTERVAL' => 'C', # Postgres
'MACADDR' => 'C', # postgres
##
'LONGCHAR' => 'X',
'TEXT' => 'X',
@@ -3342,6 +3483,7 @@
'DATETIME' => 'T',
'TIMESTAMPTZ' => 'T',
'T' => 'T',
'TIMESTAMP WITHOUT TIME ZONE' => 'T', // postgresql
##
'BOOL' => 'L',
'BOOLEAN' => 'L',
@@ -3731,7 +3873,7 @@
$fakedsn = 'fake'.substr($db,$at);
$dsna = @parse_url($fakedsn);
$dsna['scheme'] = substr($db,0,$at);
if (strncmp($db,'pdo',3) == 0) {
$sch = explode('_',$dsna['scheme']);
if (sizeof($sch)>1) {
@@ -3764,7 +3906,6 @@
}
} else $opt = array();
}
/*
* phptype: Database backend used in PHP (mysql, odbc etc.)
* dbsyntax: Database used with regards to SQL syntax etc.
@@ -3814,6 +3955,8 @@
if (isset($dsna['port'])) $obj->port = $dsna['port'];
foreach($opt as $k => $v) {
switch(strtolower($k)) {
case 'new':
$nconnect = true; $persist = true; break;
case 'persist':
case 'persistent': $persist = $v; break;
case 'debug': $obj->debug = (integer) $v; break;
@@ -3837,8 +3980,10 @@
}
if (empty($persist))
$ok = $obj->Connect($dsna['host'], $dsna['user'], $dsna['pass'], $dsna['path']);
else
else if (empty($nconnect))
$ok = $obj->PConnect($dsna['host'], $dsna['user'], $dsna['pass'], $dsna['path']);
else
$ok = $obj->NConnect($dsna['host'], $dsna['user'], $dsna['pass'], $dsna['path']);
if (!$ok) return $false;
}
@@ -3905,7 +4050,7 @@
$path = ADODB_DIR."/datadict/datadict-$drivername.inc.php";
if (!file_exists($path)) {
ADOConnection::outp("Database driver '$path' not available");
ADOConnection::outp("Dictionary driver '$path' not available");
return $false;
}
include_once($path);
@@ -3951,10 +4096,10 @@
function adodb_backtrace($printOrArr=true,$levels=9999)
{
global $ADODB_INCLUDED_LIB;
if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php');
if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php');
return _adodb_backtrace($printOrArr,$levels);
}
}
?>
?>
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
/**
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
/**
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
/**
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
/**
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
/**
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+2 -2
View File
@@ -1,7 +1,7 @@
<?php
/**
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
@@ -32,7 +32,7 @@ class ADODB2_informix extends ADODB_DataDict {
case 'B': return 'BLOB';
case 'D': return 'DATE';
case 'T': return 'DATETIME';
case 'T': return 'DATETIME YEAR TO SECOND';
case 'L': return 'SMALLINT';
case 'I': return 'INTEGER';
+29 -1
View File
@@ -1,7 +1,7 @@
<?php
/**
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
@@ -10,6 +10,34 @@
*/
/*
In ADOdb, named quotes for MS SQL Server use ". From the MSSQL Docs:
Note Delimiters are for identifiers only. Delimiters cannot be used for keywords,
whether or not they are marked as reserved in SQL Server.
Quoted identifiers are delimited by double quotation marks ("):
SELECT * FROM "Blanks in Table Name"
Bracketed identifiers are delimited by brackets ([ ]):
SELECT * FROM [Blanks In Table Name]
Quoted identifiers are valid only when the QUOTED_IDENTIFIER option is set to ON. By default,
the Microsoft OLE DB Provider for SQL Server and SQL Server ODBC driver set QUOTED_IDENTIFIER ON
when they connect.
In Transact-SQL, the option can be set at various levels using SET QUOTED_IDENTIFIER,
the quoted identifier option of sp_dboption, or the user options option of sp_configure.
When SET ANSI_DEFAULTS is ON, SET QUOTED_IDENTIFIER is enabled.
Syntax
SET QUOTED_IDENTIFIER { ON | OFF }
*/
// security - hide paths
if (!defined('ADODB_DIR')) die();
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
/**
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+3 -3
View File
@@ -1,7 +1,7 @@
<?php
/**
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
@@ -75,8 +75,8 @@ class ADODB2_oci8 extends ADODB_DataDict {
case 'X': return $this->typeX;
case 'XL': return $this->typeXL;
case 'C2': return 'NVARCHAR';
case 'X2': return 'NVARCHAR(2000)';
case 'C2': return 'NVARCHAR2';
case 'X2': return 'NVARCHAR2(4000)';
case 'B': return 'BLOB';
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
/**
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
/**
V4.50 6 July 2004 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.50 6 July 2004 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
/**
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence. See License.txt.
+4 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
@@ -263,6 +263,7 @@ class ADODB_ado extends ADOConnection {
$this->transCnt += 1;
return true;
}
function CommitTrans($ok=true)
{
if (!$ok) return $this->RollbackTrans();
@@ -283,7 +284,9 @@ class ADODB_ado extends ADOConnection {
function ErrorMsg()
{
if (!$this->_connectionID) return "No connection established";
$errc = $this->_connectionID->Errors;
if (!$errc) return "No Errors object found";
if ($errc->Count == 0) return '';
$err = $errc->Item($errc->Count-1);
return $err->Description;
+43 -14
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
@@ -58,8 +58,22 @@ class ADODB_ado extends ADOConnection {
// you can also pass a connection string like this:
//
// $DB->Connect('USER ID=sa;PASSWORD=pwd;SERVER=mangrove;DATABASE=ai',false,false,'SQLOLEDB');
function _connect($argHostname, $argUsername, $argPassword, $argProvider= 'MSDASQL')
function _connect($argHostname, $argUsername, $argPassword,$argDBorProvider, $argProvider= '')
{
// two modes
// - if $argProvider is empty, we assume that $argDBorProvider holds provider -- this is for backward compat
// - if $argProvider is not empty, then $argDBorProvider holds db
if ($argProvider) {
$argDatabasename = $argDBorProvider;
} else {
$argDatabasename = '';
if ($argDBorProvider) $argProvider = $argDBorProvider;
else $argProvider = 'MSDASQL';
}
try {
$u = 'UID';
$p = 'PWD';
@@ -86,7 +100,11 @@ class ADODB_ado extends ADOConnection {
$argProvider = "Microsoft.Jet.OLEDB.4.0"; // Microsoft Jet Provider
if ($argProvider) $dbc->Provider = $argProvider;
if ($argProvider) $argHostname = "PROVIDER=$argProvider;DRIVER={SQL Server};SERVER=$argHostname";
if ($argDatabasename) $argHostname .= ";DATABASE=$argDatabasename";
if ($argUsername) $argHostname .= ";$u=$argUsername";
if ($argPassword)$argHostname .= ";$p=$argPassword";
@@ -205,9 +223,6 @@ class ADODB_ado extends ADOConnection {
return $arr;
}
/* returns queryID or false */
function &_query($sql,$inputarr=false)
{
@@ -216,6 +231,9 @@ class ADODB_ado extends ADOConnection {
$dbc = $this->_connectionID;
// return rs
$false = false;
if ($inputarr) {
if (!empty($this->charPage))
@@ -236,22 +254,25 @@ class ADODB_ado extends ADOConnection {
$p = false;
$rs = $oCmd->Execute();
$e = $dbc->Errors;
if ($dbc->Errors->Count > 0) return false;
if ($dbc->Errors->Count > 0) return $false;
return $rs;
}
$rs = @$dbc->Execute($sql,$this->_affectedRows, $this->_execute_option);
if ($dbc->Errors->Count > 0) return false;
if (! $rs) return false;
if ($dbc->Errors->Count > 0) return $false;
if (! $rs) return $false;
if ($rs->State == 0) return true; // 0 = adStateClosed means no records returned
if ($rs->State == 0) {
$true = true;
return $true; // 0 = adStateClosed means no records returned
}
return $rs;
} catch (exception $e) {
}
return false;
return $false;
}
@@ -290,10 +311,18 @@ class ADODB_ado extends ADOConnection {
function ErrorMsg()
{
$errc = $this->_connectionID->Errors;
if ($errc->Count == 0) return '';
$err = $errc->Item($errc->Count-1);
return $err->Description;
if (!$this->_connectionID) return "No connection established";
$errmsg = '';
try {
$errc = $this->_connectionID->Errors;
if (!$errc) return "No Errors object found";
if ($errc->Count == 0) return '';
$err = $errc->Item($errc->Count-1);
$errmsg = $err->Description;
}catch(exception $e) {
}
return $errmsg;
}
function ErrorNo()
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence. See License.txt.
+52 -3
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
@@ -11,8 +11,8 @@ Set tabs to 4 for best viewing.
Microsoft SQL Server ADO data driver. Requires ADO and MSSQL client.
Works only on MS Windows.
It is normally better to use the mssql driver directly because it is much faster.
This file is only a technology demonstration and for test purposes.
Warning: Some versions of PHP (esp PHP4) leak memory when ADO/COM is used.
Please check http://bugs.php.net/ for more info.
*/
// security - hide paths
@@ -53,6 +53,17 @@ class ADODB_ado_mssql extends ADODB_ado {
return $this->GetOne('select @@rowcount');
}
function SetTransactionMode( $transaction_mode )
{
$this->_transmode = $transaction_mode;
if (empty($transaction_mode)) {
$this->Execute('SET TRANSACTION ISOLATION LEVEL READ COMMITTED');
return;
}
if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
$this->Execute("SET TRANSACTION ".$transaction_mode);
}
function MetaColumns($table)
{
$table = strtoupper($table);
@@ -84,6 +95,44 @@ class ADODB_ado_mssql extends ADODB_ado {
return empty($arr) ? $false : $arr;
}
function CreateSequence($seq='adodbseq',$start=1)
{
$this->Execute('BEGIN TRANSACTION adodbseq');
$start -= 1;
$this->Execute("create table $seq (id float(53))");
$ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)");
if (!$ok) {
$this->Execute('ROLLBACK TRANSACTION adodbseq');
return false;
}
$this->Execute('COMMIT TRANSACTION adodbseq');
return true;
}
function GenID($seq='adodbseq',$start=1)
{
//$this->debug=1;
$this->Execute('BEGIN TRANSACTION adodbseq');
$ok = $this->Execute("update $seq with (tablock,holdlock) set id = id + 1");
if (!$ok) {
$this->Execute("create table $seq (id float(53))");
$ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)");
if (!$ok) {
$this->Execute('ROLLBACK TRANSACTION adodbseq');
return false;
}
$this->Execute('COMMIT TRANSACTION adodbseq');
return $start;
}
$num = $this->GetOne("select id from $seq");
$this->Execute('COMMIT TRANSACTION adodbseq');
return $num;
// in old implementation, pre 1.90, we returned GUID...
//return $this->GetOne("SELECT CONVERT(varchar(255), NEWID()) AS 'Char'");
}
} // end class
class ADORecordSet_ado_mssql extends ADORecordSet_ado {
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
@version V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
@version V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+29 -3
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
@@ -556,9 +556,9 @@ class ADODB_ibase extends ADOConnection {
// old blobdecode function
// still used to auto-decode all blob's
function _BlobDecode( $blob )
function _BlobDecode_old( $blob )
{
$blobid = ibase_blob_open( $blob );
$blobid = ibase_blob_open($this->_connectionID, $blob );
$realblob = ibase_blob_get( $blobid,$this->maxblobsize); // 2nd param is max size of blob -- Kevin Boillet <[email protected]>
while($string = ibase_blob_get($blobid, 8192)){
$realblob .= $string;
@@ -568,6 +568,32 @@ class ADODB_ibase extends ADOConnection {
return( $realblob );
}
function _BlobDecode( $blob )
{
if (ADODB_PHPVER >= 0x5000) {
$blob_data = ibase_blob_info($this->_connectionID, $blob );
$blobid = ibase_blob_open($this->_connectionID, $blob );
} else {
$blob_data = ibase_blob_info( $blob );
$blobid = ibase_blob_open( $blob );
}
if( $blob_data[0] > $this->maxblobsize ) {
$realblob = ibase_blob_get($blobid, $this->maxblobsize);
while($string = ibase_blob_get($blobid, 8192)){
$realblob .= $string;
}
} else {
$realblob = ibase_blob_get($blobid, $blob_data[0]);
}
ibase_blob_close( $blobid );
return( $realblob );
}
function UpdateBlobFile($table,$column,$path,$where,$blobtype='BLOB')
{
$fd = fopen($path,'rb');
+6 -1
View File
@@ -1,6 +1,6 @@
<?php
/**
* @version V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
* @version V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
* Released under both BSD license and Lesser GPL library license.
* Whenever there is any discrepancy between the two licenses,
* the BSD license will take precedence.
@@ -22,6 +22,11 @@ class ADODB_informix extends ADODB_informix72 {
var $databaseType = "informix";
var $hasTop = 'FIRST';
var $ansiOuter = true;
function IfNull( $field, $ifNull )
{
return " NVL($field, $ifNull) "; // if Informix 9.X or 10.X
}
}
class ADORecordset_informix extends ADORecordset_informix72 {
+3 -3
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim. All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 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.
@@ -58,7 +58,7 @@ class ADODB_informix72 extends ADOConnection {
{
// alternatively, use older method:
//putenv("DBDATE=Y4MD-");
// force ISO date format
putenv('GL_DATE=%Y-%m-%d');
@@ -192,7 +192,7 @@ class ADODB_informix72 extends ADOConnection {
}
$rs->Close();
$rspKey->Close(); //!eos
$rspkey->Close(); //!eos
return $retarr;
}
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+14 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
@@ -161,6 +161,8 @@ class ADODB_mssql extends ADOConnection {
function CreateSequence($seq='adodbseq',$start=1)
{
$this->Execute('BEGIN TRANSACTION adodbseq');
$start -= 1;
$this->Execute("create table $seq (id float(53))");
$ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)");
@@ -294,6 +296,17 @@ class ADODB_mssql extends ADOConnection {
return true;
}
function SetTransactionMode( $transaction_mode )
{
$this->_transmode = $transaction_mode;
if (empty($transaction_mode)) {
$this->Execute('SET TRANSACTION ISOLATION LEVEL READ COMMITTED');
return;
}
if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
$this->Execute("SET TRANSACTION ".$transaction_mode);
}
/*
Usage:
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/**
* @version V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
* @version V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
* Released under both BSD license and Lesser GPL library license.
* Whenever there is any discrepancy between the two licenses,
* the BSD license will take precedence.
+13 -6
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
@@ -24,7 +24,7 @@ class ADODB_mysql extends ADOConnection {
var $hasInsertID = true;
var $hasAffectedRows = true;
var $metaTablesSQL = "SHOW TABLES";
var $metaColumnsSQL = "SHOW COLUMNS FROM %s";
var $metaColumnsSQL = "SHOW COLUMNS FROM `%s`";
var $fmtTimeStamp = "'Y-m-d H:i:s'";
var $hasLimit = true;
var $hasMoveFirst = true;
@@ -38,6 +38,7 @@ class ADODB_mysql extends ADOConnection {
var $clientFlags = 0;
var $substr = "substring";
var $nameQuote = '`'; /// string to use to quote identifiers and names
var $compat323 = false; // true if compat with mysql 3.23
function ADODB_mysql()
{
@@ -156,7 +157,7 @@ class ADODB_mysql extends ADOConnection {
function GetOne($sql,$inputarr=false)
{
if (strncasecmp($sql,'sele',4) == 0) {
if ($this->compat323 == false && strncasecmp($sql,'sele',4) == 0) {
$rs =& $this->SelectLimit($sql,1,-1,$inputarr);
if ($rs) {
$rs->Close();
@@ -340,8 +341,11 @@ class ADODB_mysql extends ADOConnection {
function OffsetDate($dayFraction,$date=false)
{
if (!$date) $date = $this->sysDate;
$fraction = $dayFraction * 24 * 3600;
return "from_unixtime(unix_timestamp($date)+$fraction)";
return $date . ' + INTERVAL ' . $fraction.' SECOND';
// return "from_unixtime(unix_timestamp($date)+$fraction)";
}
// returns true or false
@@ -541,6 +545,9 @@ class ADODB_mysql extends ADOConnection {
// "Innox - Juan Carlos Gonzalez" <jgonzalez#innox.com.mx>
function MetaForeignKeys( $table, $owner = FALSE, $upper = FALSE, $associative = FALSE )
{
global $ADODB_FETCH_MODE;
if ($ADODB_FETCH_MODE == ADODB_FETCH_ASSOC || $this->fetchMode == ADODB_FETCH_ASSOC) $associative = true;
if ( !empty($owner) ) {
$table = "$owner.$table";
}
@@ -636,8 +643,8 @@ class ADORecordSet_mysql extends ADORecordSet{
function &GetRowAssoc($upper=true)
{
if ($this->fetchMode == MYSQL_ASSOC && !$upper) return $this->fields;
$row =& ADORecordSet::GetRowAssoc($upper);
if ($this->fetchMode == MYSQL_ASSOC && !$upper) $row = $this->fields;
else $row =& ADORecordSet::GetRowAssoc($upper);
return $row;
}
+24 -7
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
@@ -32,7 +32,7 @@ class ADODB_mysqli extends ADOConnection {
var $hasInsertID = true;
var $hasAffectedRows = true;
var $metaTablesSQL = "SHOW TABLES";
var $metaColumnsSQL = "SHOW COLUMNS FROM %s";
var $metaColumnsSQL = "SHOW COLUMNS FROM `%s`";
var $fmtTimeStamp = "'Y-m-d H:i:s'";
var $hasLimit = true;
var $hasMoveFirst = true;
@@ -58,6 +58,16 @@ class ADODB_mysqli extends ADOConnection {
}
function SetTransactionMode( $transaction_mode )
{
$this->_transmode = $transaction_mode;
if (empty($transaction_mode)) {
$this->Execute('SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ');
return;
}
if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
$this->Execute("SET SESSION TRANSACTION ".$transaction_mode);
}
// returns true or false
// To add: parameter int $port,
@@ -420,9 +430,12 @@ class ADODB_mysqli extends ADOConnection {
// dayFraction is a day in floating point
function OffsetDate($dayFraction,$date=false)
{
if (!$date)
$date = $this->sysDate;
return "from_unixtime(unix_timestamp($date)+($dayFraction)*24*3600)";
if (!$date) $date = $this->sysDate;
$fraction = $dayFraction * 24 * 3600;
return $date . ' + INTERVAL ' . $fraction.' SECOND';
// return "from_unixtime(unix_timestamp($date)+$fraction)";
}
function &MetaTables($ttype=false,$showSchema=false,$mask=false)
@@ -445,6 +458,10 @@ class ADODB_mysqli extends ADOConnection {
// "Innox - Juan Carlos Gonzalez" <jgonzalez#innox.com.mx>
function MetaForeignKeys( $table, $owner = FALSE, $upper = FALSE, $associative = FALSE )
{
global $ADODB_FETCH_MODE;
if ($ADODB_FETCH_MODE == ADODB_FETCH_ASSOC || $this->fetchMode == ADODB_FETCH_ASSOC) $associative = true;
if ( !empty($owner) ) {
$table = "$owner.$table";
}
@@ -680,7 +697,7 @@ class ADODB_mysqli extends ADOConnection {
function GetCharSet()
{
//we will use ADO's builtin property charSet
if (!is_callable($this->_connectionID,'character_set_name'))
if (!method_exists($this->_connectionID,'character_set_name'))
return false;
$this->charSet = @$this->_connectionID->character_set_name();
@@ -694,7 +711,7 @@ class ADODB_mysqli extends ADOConnection {
// SetCharSet - switch the client encoding
function SetCharSet($charset_name)
{
if (!is_callable($this->_connectionID,'set_charset'))
if (!method_exists($this->_connectionID,'set_charset'))
return false;
if ($this->charSet !== $charset_name) {
+18 -1
View File
@@ -1,7 +1,7 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
@@ -30,6 +30,23 @@ class ADODB_mysqlt extends ADODB_mysql {
global $ADODB_EXTENSION; if ($ADODB_EXTENSION) $this->rsPrefix .= 'ext_';
}
/* set transaction mode
SET [GLOBAL | SESSION] TRANSACTION ISOLATION LEVEL
{ READ UNCOMMITTED | READ COMMITTED | REPEATABLE READ | SERIALIZABLE }
*/
function SetTransactionMode( $transaction_mode )
{
$this->_transmode = $transaction_mode;
if (empty($transaction_mode)) {
$this->Execute('SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ');
return;
}
if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
$this->Execute("SET SESSION TRANSACTION ".$transaction_mode);
}
function BeginTrans()
{
if ($this->transOff) return true;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 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.
+20 -3
View File
@@ -1,7 +1,7 @@
<?php
/*
version V4.71 24 Jan 2006 (c) 2000-2006 John Lim. All rights reserved.
version V4.91 2 Aug 2006 (c) 2000-2006 John Lim. All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
@@ -278,6 +278,21 @@ NATSOFT.DOMAIN =
return "TO_DATE(".adodb_date($this->fmtDate,$d).",'".$this->NLS_DATE_FORMAT."')";
}
function BindDate($d)
{
$d = ADOConnection::DBDate($d);
if (strncmp($d,"'",1)) return $d;
return substr($d,1,strlen($d)-2);
}
function BindTimeStamp($d)
{
$d = ADOConnection::DBTimeStamp($d);
if (strncmp($d,"'",1)) return $d;
return substr($d,1,strlen($d)-2);
}
// format and return date string in database timestamp format
function DBTimeStamp($ts)
@@ -298,7 +313,7 @@ NATSOFT.DOMAIN =
if ($mask) {
$save = $this->metaTablesSQL;
$mask = $this->qstr(strtoupper($mask));
$this->metaTablesSQL .= " AND table_name like $mask";
$this->metaTablesSQL .= " AND upper(table_name) like $mask";
}
$ret =& ADOConnection::MetaTables($ttype,$showSchema);
@@ -381,6 +396,8 @@ NATSOFT.DOMAIN =
$this->transCnt += 1;
$this->autoCommit = false;
$this->_commit = OCI_DEFAULT;
if ($this->_transmode) $this->Execute("SET TRANSACTION ".$this->_transmode);
return true;
}
@@ -1481,4 +1498,4 @@ class ADORecordSet_ext_oci8 extends ADORecordSet_oci8 {
return adodb_movenext($this);
}
}
?>
?>
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/**
* @version V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
* @version V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
* Released under both BSD license and Lesser GPL library license.
* Whenever there is any discrepancy between the two licenses,
* the BSD license will take precedence.
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim. All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 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.
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+368
View File
@@ -0,0 +1,368 @@
<?php
/*
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
Set tabs to 4 for best viewing.
Latest version is available at http://adodb.sourceforge.net
DB2 data driver. Requires ODBC.
From phpdb list:
Hi Andrew,
thanks a lot for your help. Today we discovered what
our real problem was:
After "playing" a little bit with the php-scripts that try
to connect to the IBM DB2, we set the optional parameter
Cursortype when calling odbc_pconnect(....).
And the exciting thing: When we set the cursor type
to SQL_CUR_USE_ODBC Cursor Type, then
the whole query speed up from 1 till 10 seconds
to 0.2 till 0.3 seconds for 100 records. Amazing!!!
Therfore, PHP is just almost fast as calling the DB2
from Servlets using JDBC (don't take too much care
about the speed at whole: the database was on a
completely other location, so the whole connection
was made over a slow network connection).
I hope this helps when other encounter the same
problem when trying to connect to DB2 from
PHP.
Kind regards,
Christian Szardenings
2 Oct 2001
Mark Newnham has discovered that the SQL_CUR_USE_ODBC is not supported by
IBM's DB2 ODBC driver, so this must be a 3rd party ODBC driver.
From the IBM CLI Reference:
SQL_ATTR_ODBC_CURSORS (DB2 CLI v5)
This connection attribute is defined by ODBC, but is not supported by DB2
CLI. Any attempt to set or get this attribute will result in an SQLSTATE of
HYC00 (Driver not capable).
A 32-bit option specifying how the Driver Manager uses the ODBC cursor
library.
So I guess this means the message [above] was related to using a 3rd party
odbc driver.
Setting SQL_CUR_USE_ODBC
========================
To set SQL_CUR_USE_ODBC for drivers that require it, do this:
$db = NewADOConnection('odbc_db2');
$db->curMode = SQL_CUR_USE_ODBC;
$db->Connect($dsn, $userid, $pwd);
USING CLI INTERFACE
===================
I have had reports that the $host and $database params have to be reversed in
Connect() when using the CLI interface. From Halmai Csongor csongor.halmai#nexum.hu:
> The symptom is that if I change the database engine from postgres or any other to DB2 then the following
> connection command becomes wrong despite being described this version to be correct in the docs.
>
> $connection_object->Connect( $DATABASE_HOST, $DATABASE_AUTH_USER_NAME, $DATABASE_AUTH_PASSWORD, $DATABASE_NAME )
>
> In case of DB2 I had to swap the first and last arguments in order to connect properly.
System Error 5
==============
IF you get a System Error 5 when trying to Connect/Load, it could be a permission problem. Give the user connecting
to DB2 full rights to the DB2 SQLLIB directory, and place the user in the DBUSERS group.
*/
// security - hide paths
if (!defined('ADODB_DIR')) die();
if (!defined('_ADODB_ODBC_LAYER')) {
include(ADODB_DIR."/drivers/adodb-odbc.inc.php");
}
if (!defined('ADODB_ODBC_DB2')){
define('ADODB_ODBC_DB2',1);
class ADODB_ODBC_DB2 extends ADODB_odbc {
var $databaseType = "db2";
var $concat_operator = '||';
var $sysTime = 'CURRENT TIME';
var $sysDate = 'CURRENT DATE';
var $sysTimeStamp = 'CURRENT TIMESTAMP';
// The complete string representation of a timestamp has the form
// yyyy-mm-dd-hh.mm.ss.nnnnnn.
var $fmtTimeStamp = "'Y-m-d-H.i.s'";
var $ansiOuter = true;
var $identitySQL = 'values IDENTITY_VAL_LOCAL()';
var $_bindInputArray = true;
var $hasInsertID = true;
var $rsPrefix = 'ADORecordset_odbc_';
function ADODB_DB2()
{
if (strncmp(PHP_OS,'WIN',3) === 0) $this->curmode = SQL_CUR_USE_ODBC;
$this->ADODB_odbc();
}
function IfNull( $field, $ifNull )
{
return " COALESCE($field, $ifNull) "; // if DB2 UDB
}
function ServerInfo()
{
//odbc_setoption($this->_connectionID,1,101 /*SQL_ATTR_ACCESS_MODE*/, 1 /*SQL_MODE_READ_ONLY*/);
$vers = $this->GetOne('select versionnumber from sysibm.sysversions');
//odbc_setoption($this->_connectionID,1,101, 0 /*SQL_MODE_READ_WRITE*/);
return array('description'=>'DB2 ODBC driver', 'version'=>$vers);
}
function _insertid()
{
return $this->GetOne($this->identitySQL);
}
function RowLock($tables,$where,$flds='1 as ignore')
{
if ($this->_autocommit) $this->BeginTrans();
return $this->GetOne("select $flds from $tables where $where for update");
}
function &MetaTables($ttype=false,$showSchema=false, $qtable="%", $qschema="%")
{
global $ADODB_FETCH_MODE;
$savem = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
$qid = odbc_tables($this->_connectionID, "", $qschema, $qtable, "");
$rs = new ADORecordSet_odbc($qid);
$ADODB_FETCH_MODE = $savem;
if (!$rs) {
$false = false;
return $false;
}
$rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change;
$arr =& $rs->GetArray();
//print_r($arr);
$rs->Close();
$arr2 = array();
if ($ttype) {
$isview = strncmp($ttype,'V',1) === 0;
}
for ($i=0; $i < sizeof($arr); $i++) {
if (!$arr[$i][2]) continue;
if (strncmp($arr[$i][1],'SYS',3) === 0) continue;
$type = $arr[$i][3];
if ($showSchema) $arr[$i][2] = $arr[$i][1].'.'.$arr[$i][2];
if ($ttype) {
if ($isview) {
if (strncmp($type,'V',1) === 0) $arr2[] = $arr[$i][2];
} else if (strncmp($type,'T',1) === 0) $arr2[] = $arr[$i][2];
} else if (strncmp($type,'S',1) !== 0) $arr2[] = $arr[$i][2];
}
return $arr2;
}
function &MetaIndexes ($table, $primary = FALSE, $owner=false)
{
// save old fetch mode
global $ADODB_FETCH_MODE;
$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
if ($this->fetchMode !== FALSE) {
$savem = $this->SetFetchMode(FALSE);
}
$false = false;
// get index details
$table = strtoupper($table);
$SQL="SELECT NAME, UNIQUERULE, COLNAMES FROM SYSIBM.SYSINDEXES WHERE TBNAME='$table'";
if ($primary)
$SQL.= " AND UNIQUERULE='P'";
$rs = $this->Execute($SQL);
if (!is_object($rs)) {
if (isset($savem))
$this->SetFetchMode($savem);
$ADODB_FETCH_MODE = $save;
return $false;
}
$indexes = array ();
// parse index data into array
while ($row = $rs->FetchRow()) {
$indexes[$row[0]] = array(
'unique' => ($row[1] == 'U' || $row[1] == 'P'),
'columns' => array()
);
$cols = ltrim($row[2],'+');
$indexes[$row[0]]['columns'] = explode('+', $cols);
}
if (isset($savem)) {
$this->SetFetchMode($savem);
$ADODB_FETCH_MODE = $save;
}
return $indexes;
}
// Format date column in sql string given an input format that understands Y M D
function SQLDate($fmt, $col=false)
{
// use right() and replace() ?
if (!$col) $col = $this->sysDate;
$s = '';
$len = strlen($fmt);
for ($i=0; $i < $len; $i++) {
if ($s) $s .= '||';
$ch = $fmt[$i];
switch($ch) {
case 'Y':
case 'y':
$s .= "char(year($col))";
break;
case 'M':
$s .= "substr(monthname($col),1,3)";
break;
case 'm':
$s .= "right(digits(month($col)),2)";
break;
case 'D':
case 'd':
$s .= "right(digits(day($col)),2)";
break;
case 'H':
case 'h':
if ($col != $this->sysDate) $s .= "right(digits(hour($col)),2)";
else $s .= "''";
break;
case 'i':
case 'I':
if ($col != $this->sysDate)
$s .= "right(digits(minute($col)),2)";
else $s .= "''";
break;
case 'S':
case 's':
if ($col != $this->sysDate)
$s .= "right(digits(second($col)),2)";
else $s .= "''";
break;
default:
if ($ch == '\\') {
$i++;
$ch = substr($fmt,$i,1);
}
$s .= $this->qstr($ch);
}
}
return $s;
}
function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputArr=false)
{
$nrows = (integer) $nrows;
if ($offset <= 0) {
// could also use " OPTIMIZE FOR $nrows ROWS "
if ($nrows >= 0) $sql .= " FETCH FIRST $nrows ROWS ONLY ";
$rs =& $this->Execute($sql,$inputArr);
} else {
if ($offset > 0 && $nrows < 0);
else {
$nrows += $offset;
$sql .= " FETCH FIRST $nrows ROWS ONLY ";
}
$rs =& ADOConnection::SelectLimit($sql,-1,$offset,$inputArr);
}
return $rs;
}
};
class ADORecordSet_odbc_db2 extends ADORecordSet_odbc {
var $databaseType = "db2";
function ADORecordSet_db2($id,$mode=false)
{
$this->ADORecordSet_odbc($id,$mode);
}
function MetaType($t,$len=-1,$fieldobj=false)
{
if (is_object($t)) {
$fieldobj = $t;
$t = $fieldobj->type;
$len = $fieldobj->max_length;
}
switch (strtoupper($t)) {
case 'VARCHAR':
case 'CHAR':
case 'CHARACTER':
case 'C':
if ($len <= $this->blobSize) return 'C';
case 'LONGCHAR':
case 'TEXT':
case 'CLOB':
case 'DBCLOB': // double-byte
case 'X':
return 'X';
case 'BLOB':
case 'GRAPHIC':
case 'VARGRAPHIC':
return 'B';
case 'DATE':
case 'D':
return 'D';
case 'TIME':
case 'TIMESTAMP':
case 'T':
return 'T';
//case 'BOOLEAN':
//case 'BIT':
// return 'L';
//case 'COUNTER':
// return 'R';
case 'INT':
case 'INTEGER':
case 'BIGINT':
case 'SMALLINT':
case 'I':
return 'I';
default: return 'N';
}
}
}
} //define
?>
+12 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
@@ -142,6 +142,17 @@ order by constraint_name, referenced_table_name, keyno";
return ADODB_odbc::_query($sql,$inputarr);
}
function SetTransactionMode( $transaction_mode )
{
$this->_transmode = $transaction_mode;
if (empty($transaction_mode)) {
$this->Execute('SET TRANSACTION ISOLATION LEVEL READ COMMITTED');
return;
}
if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
$this->Execute("SET TRANSACTION ".$transaction_mode);
}
// "Stein-Aksel Basma" <[email protected]>
// tested with MSSQL 2000
function &MetaPrimaryKeys($table)
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence. See License.txt.
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence. See License.txt.
+19 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
@@ -45,6 +45,24 @@ class ADODB_oracle extends ADOConnection {
if (is_string($ts)) $d = ADORecordSet::UnixTimeStamp($ts);
return 'TO_DATE('.adodb_date($this->fmtTimeStamp,$ts).",'RRRR-MM-DD, HH:MI:SS AM')";
}
function BindDate($d)
{
$d = ADOConnection::DBDate($d);
if (strncmp($d,"'",1)) return $d;
return substr($d,1,strlen($d)-2);
}
function BindTimeStamp($d)
{
$d = ADOConnection::DBTimeStamp($d);
if (strncmp($d,"'",1)) return $d;
return substr($d,1,strlen($d)-2);
}
function BeginTrans()
+5 -3
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
@@ -325,7 +325,8 @@ class ADODB_pdo extends ADOConnection {
$obj = new ADOPDOStatement($stmt,$this);
return $obj;
}
/* returns queryID or false */
function _query($sql,$inputarr=false)
{
@@ -334,7 +335,8 @@ class ADODB_pdo extends ADOConnection {
} else {
$stmt = $this->_connectionID->prepare($sql);
}
#adodb_backtrace();
#var_dump($this->_bindInputArray);
if ($stmt) {
$this->_driver->debug = $this->debug;
if ($inputarr) $ok = $stmt->execute($inputarr);
+12 -1
View File
@@ -2,7 +2,7 @@
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
@@ -36,6 +36,17 @@ class ADODB_pdo_mssql extends ADODB_pdo {
return $ret;
}
function SetTransactionMode( $transaction_mode )
{
$this->_transmode = $transaction_mode;
if (empty($transaction_mode)) {
$this->Execute('SET TRANSACTION ISOLATION LEVEL READ COMMITTED');
return;
}
if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
$this->Execute("SET TRANSACTION ".$transaction_mode);
}
function MetaTables()
{
return false;
+27 -5
View File
@@ -2,7 +2,7 @@
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
@@ -12,20 +12,31 @@ V4.71 24 Jan 2006 (c) 2000-2006 John Lim ([email protected]). All rights rese
class ADODB_pdo_mysql extends ADODB_pdo {
var $metaTablesSQL = "SHOW TABLES";
var $metaColumnsSQL = "SHOW COLUMNS FROM %s";
var $_bindInputArray = false;
var $metaColumnsSQL = "SHOW COLUMNS FROM `%s`";
var $sysDate = 'CURDATE()';
var $sysTimeStamp = 'NOW()';
var $nameQuote = '`';
function _init($parentDriver)
{
$parentDriver->hasTransactions = false;
$parentDriver->_bindInputArray = true;
$parentDriver->_bindInputArray = false;
$parentDriver->hasInsertID = true;
$parentDriver->_connectionID->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true);
}
// dayFraction is a day in floating point
function OffsetDate($dayFraction,$date=false)
{
if (!$date) $date = $this->sysDate;
$fraction = $dayFraction * 24 * 3600;
return $date . ' + INTERVAL ' . $fraction.' SECOND';
// return "from_unixtime(unix_timestamp($date)+$fraction)";
}
function ServerInfo()
{
$arr['description'] = ADOConnection::GetOne("select version()");
@@ -50,6 +61,17 @@ class ADODB_pdo_mysql extends ADODB_pdo {
return $ret;
}
function SetTransactionMode( $transaction_mode )
{
$this->_transmode = $transaction_mode;
if (empty($transaction_mode)) {
$this->Execute('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ');
return;
}
if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
$this->Execute("SET SESSION TRANSACTION ".$transaction_mode);
}
function &MetaColumns($table)
{
$this->_findschema($table,$schema);
+1 -1
View File
@@ -2,7 +2,7 @@
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+15 -8
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
@@ -161,7 +161,7 @@ a different OID if a database must be reloaded. */
}
// I get this error with PHP before 4.0.6 - jlim
// Warning: This compilation does not support pg_cmdtuples() in d:/inetpub/wwwroot/php/adodb/adodb-postgres.inc.php on line 44
// Warning: This compilation does not support pg_cmdtuples() in adodb-postgres.inc.php on line 44
function _affectedrows()
{
if (!is_resource($this->_resultid) || get_resource_type($this->_resultid) !== 'pgsql result') return false;
@@ -174,7 +174,7 @@ a different OID if a database must be reloaded. */
{
if ($this->transOff) return true;
$this->transCnt += 1;
return @pg_Exec($this->_connectionID, "begin");
return @pg_Exec($this->_connectionID, "begin ".$this->_transmode);
}
function RowLock($tables,$where,$flds='1 as ignore')
@@ -532,6 +532,8 @@ select viewname,'V' from pg_views where viewname like $mask";
$fld->name = $rs->fields[0];
$fld->type = $rs->fields[1];
$fld->max_length = $rs->fields[2];
$fld->attnum = $rs->fields[6];
if ($fld->max_length <= 0) $fld->max_length = $rs->fields[3]-4;
if ($fld->max_length <= 0) $fld->max_length = -1;
if ($fld->type == 'numeric') {
@@ -617,12 +619,14 @@ WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\'))';
return $false;
}
$col_names = $this->MetaColumnNames($table,true);
$col_names = $this->MetaColumnNames($table,true,true);
//3rd param is use attnum,
// see http://sourceforge.net/tracker/index.php?func=detail&aid=1451245&group_id=42718&atid=433976
$indexes = array();
while ($row = $rs->FetchRow()) {
$columns = array();
foreach (explode(' ', $row[2]) as $col) {
$columns[] = $col_names[$col - 1];
$columns[] = $col_names[$col];
}
$indexes[$row[0]] = array(
@@ -701,7 +705,7 @@ WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\'))';
// returns queryID or false
function _query($sql,$inputarr)
{
$this->_errorMsg = false;
if ($inputarr) {
/*
It appears that PREPARE/EXECUTE is slower for many queries.
@@ -731,6 +735,7 @@ WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\'))';
if ($execp) $exsql = "EXECUTE $plan ($execp)";
else $exsql = "EXECUTE $plan";
$rez = @pg_exec($this->_connectionID,$exsql);
if (!$rez) {
# Perhaps plan does not exist? Prepare/compile plan.
@@ -756,12 +761,11 @@ WHERE (c2.relname=\'%s\' or c2.relname=lower(\'%s\'))';
$s = "PREPARE $plan ($params) AS ".substr($sql,0,strlen($sql)-2);
//adodb_pr($s);
pg_exec($this->_connectionID,$s);
echo $this->ErrorMsg();
//echo $this->ErrorMsg();
}
$rez = pg_exec($this->_connectionID,$exsql);
} else {
$this->_errorMsg = false;
//adodb_backtrace();
$rez = pg_exec($this->_connectionID,$sql);
}
@@ -1000,6 +1004,7 @@ class ADORecordSet_postgres64 extends ADORecordSet{
case 'BPCHAR':
case '_VARCHAR':
case 'INET':
case 'MACADDR':
if ($len <= $this->blobSize) return 'C';
case 'TEXT':
@@ -1019,6 +1024,8 @@ class ADORecordSet_postgres64 extends ADORecordSet{
case 'DATE':
return 'D';
case 'TIMESTAMP WITHOUT TIME ZONE':
case 'TIME':
case 'DATETIME':
case 'TIMESTAMP':
+16 -14
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
@@ -56,6 +56,7 @@ class ADODB_postgres7 extends ADODB_postgres64 {
}
*/
// from Edward Jaramilla, improved version - works on pg 7.4
function MetaForeignKeys($table, $owner=false, $upper=false)
{
@@ -73,21 +74,21 @@ class ADODB_postgres7 extends ADODB_postgres64 {
$rs =& $this->Execute($sql);
if ($rs && !$rs->EOF) {
$arr =& $rs->GetArray();
$a = array();
foreach($arr as $v)
{
$data = explode(chr(0), $v['args']);
if ($upper) {
$a[strtoupper($data[2])][] = strtoupper($data[4].'='.$data[5]);
} else {
$a[$data[2]][] = $data[4].'='.$data[5];
}
if (!$rs || $rs->EOF) return false;
$arr =& $rs->GetArray();
$a = array();
foreach($arr as $v) {
$data = explode(chr(0), $v['args']);
$size = count($data)-1; //-1 because the last node is empty
for($i = 4; $i < $size; $i++) {
if ($upper)
$a[strtoupper($data[2])][] = strtoupper($data[$i].'='.$data[++$i]);
else
$a[$data[2]][] = $data[$i].'='.$data[++$i];
}
return $a;
}
return false;
return $a;
}
function _query($sql,$inputarr)
@@ -96,6 +97,7 @@ class ADODB_postgres7 extends ADODB_postgres64 {
// We don't have native support for parameterized queries, so let's emulate it at the parent
return ADODB_postgres64::_query($sql, $inputarr);
}
$this->_errorMsg = false;
// -- added Cristiano da Cunha Duarte
if ($inputarr) {
$sqlarr = explode('?',trim($sql));
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
version V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights
version V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights
reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim. All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 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.
+5 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
@@ -9,6 +9,10 @@
Contributed by Interakt Online. Thx Cristian MARIN cristic#interaktonline.com
*/
require_once ADODB_DIR."/drivers/adodb-sybase.inc.php";
class ADODB_sybase_ase extends ADODB_sybase {
var $databaseType = "sybase_ase";
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
-1
View File
@@ -1 +0,0 @@
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence. See License.txt.
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence. See License.txt.
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence. See License.txt.
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence. See License.txt.
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence. See License.txt.
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence. See License.txt.
+9 -7
View File
@@ -1,15 +1,12 @@
<?php
/**
* @version V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
* @version V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
* Released under both BSD license and Lesser GPL library license.
* Whenever there is any discrepancy between the two licenses,
* the BSD license will take precedence.
*
* Set tabs to 4 for best viewing.
*
* Latest version is available at http://php.weblogs.com
*
* Requires PHP4.01pl2 or later because it uses include_once
*/
/*
@@ -23,7 +20,7 @@
* @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. $sumfield = 'AVG(fieldname)';
* 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
@@ -31,14 +28,14 @@
* @returns Sql generated
*/
function PivotTableSQL($db,$tables,$rowfields,$colfield, $where=false,
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 still doesn' work even with IIF enabled || $db->databaseType == 'vfp';
// note - vfp 6 still doesn' work even with IIF enabled || $db->databaseType == 'vfp';
//$hidecnt = false;
@@ -95,7 +92,12 @@
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;
}
+16
View File
@@ -0,0 +1,16 @@
Description of ADODB v4.91 library import into Moodle
Removed:
* contrib
* cute_icons_for_site
* docs
* pear
* tests
Added:
* index.html - prevent directory browsing on misconfigured servers
* tests/tmssql.php - detection of attack attempts and overwrite on incorrectly upgraded sites
* readme_moodle.txt - this file ;-)
skodak
21 August 2006
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/**
* @version V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
* @version V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
* Released under both BSD license and Lesser GPL library license.
* Whenever there is any discrepancy between the two licenses,
* the BSD license will take precedence.
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
/**
* @version V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
* @version V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
* Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Contributed by Ross Smith ([email protected]).
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
+1 -1
View File
@@ -2,7 +2,7 @@
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Contributed by Ross Smith ([email protected]).
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
+5 -2
View File
@@ -2,7 +2,7 @@
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Contributed by Ross Smith ([email protected]).
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
@@ -16,7 +16,10 @@ This file is provided for backwards compatibility purposes
*/
require_once dirname(__FILE__) . '/adodb-session.php';
if (!defined('ADODB_SESSION')) {
require_once dirname(__FILE__) . '/adodb-session.php';
}
require_once ADODB_SESSION . '/adodb-encrypt-md5.php';
ADODB_Session::filter(new ADODB_Encrypt_MD5());
+27
View File
@@ -0,0 +1,27 @@
<?php
/*
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Contributed by Ross Smith ([email protected]).
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.
*/
/*
This file is provided for backwards compatibility purposes
*/
if (!defined('ADODB_SESSION')) {
require_once dirname(__FILE__) . '/adodb-session2.php';
}
require_once ADODB_SESSION . '/adodb-encrypt-md5.php';
ADODB_Session::filter(new ADODB_Encrypt_MD5());
?>
+1 -1
View File
@@ -2,7 +2,7 @@
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Contributed by Ross Smith ([email protected]).
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Contributed by Ross Smith ([email protected]).
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Contributed by Ross Smith ([email protected]).
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
+32
View File
@@ -0,0 +1,32 @@
<?php
if (!defined('ADODB_SESSION')) die();
include_once ADODB_SESSION . '/crypt.inc.php';
/**
*/
class ADODB_Encrypt_SHA1 {
function write($data, $key)
{
$sha1crypt =& new SHA1Crypt();
return $sha1crypt->encrypt($data, $key);
}
function read($data, $key)
{
$sha1crypt =& new SHA1Crypt();
return $sha1crypt->decrypt($data, $key);
}
}
return 1;
?>
+4 -3
View File
@@ -2,7 +2,7 @@
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Contributed by Ross Smith ([email protected]).
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
@@ -16,8 +16,9 @@ This file is provided for backwards compatibility purposes
*/
require_once dirname(__FILE__) . '/adodb-session.php';
if (!defined('ADODB_SESSION')) {
require_once dirname(__FILE__) . '/adodb-session.php';
}
ADODB_Session::clob('CLOB');
?>
+24
View File
@@ -0,0 +1,24 @@
<?php
/*
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Contributed by Ross Smith ([email protected]).
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.
*/
/*
This file is provided for backwards compatibility purposes
*/
if (!defined('ADODB_SESSION')) {
require_once dirname(__FILE__) . '/adodb-session2.php';
}
ADODB_Session::clob('CLOB');
?>
+66 -49
View File
@@ -2,7 +2,7 @@
/*
V4.71 24 Jan 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Contributed by Ross Smith ([email protected]).
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
@@ -26,7 +26,7 @@ V4.71 24 Jan 2006 (c) 2000-2006 John Lim ([email protected]). All rights rese
*/
if (!defined('_ADODB_LAYER')) {
require_once realpath(dirname(__FILE__) . '/../adodb.inc.php');
require realpath(dirname(__FILE__) . '/../adodb.inc.php');
}
if (defined('ADODB_SESSION')) return 1;
@@ -492,13 +492,29 @@ class ADODB_Session {
/////////////////////
// public methods
/////////////////////
function config($driver, $host, $user, $password, $database=false,$options=false)
{
ADODB_Session::driver($driver);
ADODB_Session::host($host);
ADODB_Session::user($user);
ADODB_Session::password($password);
ADODB_Session::database($database);
if ($driver == 'oci8' || $driver == 'oci8po') $options['lob'] = 'CLOB';
if (isset($options['table'])) ADODB_Session::table($options['table']);
if (isset($options['lob'])) ADODB_Session::clob($options['lob']);
if (isset($options['debug'])) ADODB_Session::debug($options['debug']);
}
/*!
Create the connection to the database.
If $conn already exists, reuse that connection
*/
function open($save_path, $session_name, $persist = null) {
function open($save_path, $session_name, $persist = null)
{
$conn =& ADODB_Session::_conn();
if ($conn) {
@@ -523,7 +539,6 @@ class ADODB_Session {
# assert('$driver');
# assert('$host');
// cannot use =& below - do not know why...
$conn =& ADONewConnection($driver);
if ($debug) {
@@ -553,7 +568,8 @@ class ADODB_Session {
/*!
Close the connection
*/
function close() {
function close()
{
/*
$conn =& ADODB_Session::_conn();
if ($conn) $conn->Close();
@@ -564,7 +580,8 @@ class ADODB_Session {
/*
Slurp in the session variables and return the serialized string
*/
function read($key) {
function read($key)
{
$conn =& ADODB_Session::_conn();
$data = ADODB_Session::dataFieldName();
$filter = ADODB_Session::filter();
@@ -574,7 +591,7 @@ class ADODB_Session {
return '';
}
assert('$table');
//assert('$table');
$qkey = $conn->quote($key);
$binary = $conn->dataProvider === 'mysql' ? '/*! BINARY */' : '';
@@ -617,7 +634,12 @@ class ADODB_Session {
If the data has not been modified since the last read(), we do not write.
*/
function write($key, $val) {
function write($key, $val)
{
global $ADODB_SESSION_READONLY;
if (!empty($ADODB_SESSION_READONLY)) return;
$clob = ADODB_Session::clob();
$conn =& ADODB_Session::_conn();
$crc = ADODB_Session::_crc();
@@ -634,7 +656,7 @@ class ADODB_Session {
}
$qkey = $conn->qstr($key);
assert('$table');
//assert('$table');
$expiry = time() + $lifetime;
@@ -646,12 +668,19 @@ class ADODB_Session {
if ($debug) {
echo '<p>Session: Only updating date - crc32 not changed</p>';
}
$sql = "UPDATE $table SET expiry = ".$conn->Param('0')." WHERE $binary sesskey = ".$conn->Param('1')." AND expiry >= ".$conn->Param('2');
$rs =& $conn->Execute($sql,array($expiry,$key,time()));
ADODB_Session::_dumprs($rs);
if ($rs) {
$rs->Close();
$expirevar = '';
if ($expire_notify) {
$var = reset($expire_notify);
global $$var;
if (isset($$var)) {
$expirevar = $$var;
}
}
$sql = "UPDATE $table SET expiry = ".$conn->Param('0').",expireref=".$conn->Param('1')." WHERE $binary sesskey = ".$conn->Param('2')." AND expiry >= ".$conn->Param('3');
$rs =& $conn->Execute($sql,array($expiry,$expirevar,$key,time()));
return true;
}
$val = rawurlencode($val);
@@ -673,7 +702,7 @@ class ADODB_Session {
if (!$clob) { // no lobs, simply use replace()
$arr[$data] = $conn->qstr($val);
$rs = $conn->Replace($table, $arr, 'sesskey', $autoQuote = true);
ADODB_Session::_dumprs($rs);
} else {
// what value shall we insert/update for lob row?
switch ($driver) {
@@ -691,36 +720,27 @@ class ADODB_Session {
break;
}
$conn->StartTrans();
$expiryref = $conn->qstr($arr['expireref']);
// do we insert or update? => as for sesskey
$rs =& $conn->Execute("SELECT COUNT(*) AS cnt FROM $table WHERE $binary sesskey = $qkey");
ADODB_Session::_dumprs($rs);
if ($rs && reset($rs->fields) > 0) {
$sql = "UPDATE $table SET expiry = $expiry, $data = $lob_value WHERE sesskey = $qkey";
$sql = "UPDATE $table SET expiry = $expiry, $data = $lob_value, expireref=$expiryref WHERE sesskey = $qkey";
} else {
$sql = "INSERT INTO $table (expiry, $data, sesskey) VALUES ($expiry, $lob_value, $qkey)";
}
if ($rs) {
$rs->Close();
$sql = "INSERT INTO $table (expiry, $data, sesskey,expireref) VALUES ($expiry, $lob_value, $qkey,$expiryref)";
}
if ($rs)$rs->Close();
$err = '';
$rs1 =& $conn->Execute($sql);
ADODB_Session::_dumprs($rs1);
if (!$rs1) {
$err = $conn->ErrorMsg()."\n";
}
if (!$rs1) $err = $conn->ErrorMsg()."\n";
$rs2 =& $conn->UpdateBlob($table, $data, $val, " sesskey=$qkey", strtoupper($clob));
ADODB_Session::_dumprs($rs2);
if (!$rs2) {
$err .= $conn->ErrorMsg()."\n";
}
if (!$rs2) $err .= $conn->ErrorMsg()."\n";
$rs = ($rs && $rs2) ? true : false;
if ($rs1) {
$rs1->Close();
}
if (is_object($rs2)) {
$rs2->Close();
}
$conn->CompleteTrans();
}
if (!$rs) {
@@ -755,7 +775,7 @@ class ADODB_Session {
return false;
}
assert('$table');
//assert('$table');
$qkey = $conn->quote($key);
$binary = $conn->dataProvider === 'mysql' ? '/*! BINARY */' : '';
@@ -784,16 +804,14 @@ class ADODB_Session {
$sql = "DELETE FROM $table WHERE $binary sesskey = $qkey";
$rs =& $conn->Execute($sql);
ADODB_Session::_dumprs($rs);
if ($rs) {
$rs->Close();
}
return $rs ? true : false;
}
/*!
*/
function gc($maxlifetime) {
function gc($maxlifetime)
{
$conn =& ADODB_Session::_conn();
$debug = ADODB_Session::debug();
$expire_notify = ADODB_Session::expireNotify();
@@ -805,10 +823,8 @@ class ADODB_Session {
return false;
}
assert('$table');
$time = time();
$binary = $conn->dataProvider === 'mysql' ? '/*! BINARY */' : '';
if ($expire_notify) {
@@ -820,18 +836,18 @@ class ADODB_Session {
ADODB_Session::_dumprs($rs);
$conn->SetFetchMode($savem);
if ($rs) {
$conn->BeginTrans();
$conn->StartTrans();
$keys = array();
while (!$rs->EOF) {
$ref = $rs->fields[0];
$key = $rs->fields[1];
$fn($ref, $key);
$del = $conn->Execute("DELETE FROM $table WHERE sesskey='$key'");
$del = $conn->Execute("DELETE FROM $table WHERE sesskey=".$conn->Param('0'),array($key));
$rs->MoveNext();
}
$rs->Close();
$conn->CommitTrans();
$conn->CompleteTrans();
}
} else {
@@ -839,8 +855,8 @@ class ADODB_Session {
$sql = "SELECT sesskey FROM $table WHERE expiry < $time";
$arr =& $conn->GetAll($sql);
foreach ($arr as $row) {
$sql2 = "DELETE FROM $table WHERE sesskey='$row[0]'";
$conn->Execute($sql2);
$sql2 = "DELETE FROM $table WHERE sesskey=".$conn->Param('0');
$conn->Execute($sql2,array($row[0]));
}
} else {
$sql = "DELETE FROM $table WHERE expiry < $time";
@@ -901,7 +917,8 @@ class ADODB_Session {
}
ADODB_Session::_init();
register_shutdown_function('session_write_close');
if (empty($ADODB_SESSION_READONLY))
register_shutdown_function('session_write_close');
// for backwards compatability only
function adodb_sess_open($save_path, $session_name, $persist = true) {
@@ -914,4 +931,4 @@ function adodb_sess_gc($t)
return ADODB_Session::gc($t);
}
?>
?>
+941
View File
@@ -0,0 +1,941 @@
<?php
/*
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Contributed by Ross Smith ([email protected]).
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.
*/
/*
CREATE Table SCripts
Oracle
======
CREATE TABLE SESSIONS2
(
SESSKEY VARCHAR2(48 BYTE) NOT NULL,
EXPIRY DATE NOT NULL,
EXPIREREF VARCHAR2(200 BYTE),
CREATED DATE NOT NULL,
MODIFIED DATE NOT NULL,
SESSDATA CLOB,
PRIMARY KEY(SESSKEY)
);
CREATE INDEX SESS2_EXPIRY ON SESSIONS2(EXPIRY);
CREATE UNIQUE INDEX SESS2_PK ON SESSIONS2(SESSKEY);
CREATE INDEX SESS2_EXP_REF ON SESSIONS2(EXPIREREF);
MySQL
=====
CREATE TABLE sessions2(
sesskey VARCHAR( 64 ) NOT NULL DEFAULT '',
expiry TIMESTAMP NOT NULL ,
expireref VARCHAR( 250 ) DEFAULT '',
created TIMESTAMP NOT NULL ,
modified TIMESTAMP NOT NULL ,
sessdata LONGTEXT DEFAULT '',
PRIMARY KEY ( sesskey ) ,
INDEX sess2_expiry( expiry ),
INDEX sess2_expireref( expireref )
)
*/
if (!defined('_ADODB_LAYER')) {
require realpath(dirname(__FILE__) . '/../adodb.inc.php');
}
if (defined('ADODB_SESSION')) return 1;
define('ADODB_SESSION', dirname(__FILE__));
define('ADODB_SESSION2', ADODB_SESSION);
/*
Unserialize session data manually. See http://phplens.com/lens/lensforum/msgs.php?id=9821
From Kerr Schere, to unserialize session data stored via ADOdb.
1. Pull the session data from the db and loop through it.
2. Inside the loop, you will need to urldecode the data column.
3. After urldecode, run the serialized string through this function:
*/
function adodb_unserialize( $serialized_string )
{
$variables = array( );
$a = preg_split( "/(\w+)\|/", $serialized_string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
for( $i = 0; $i < count( $a ); $i = $i+2 ) {
$variables[$a[$i]] = unserialize( $a[$i+1] );
}
return( $variables );
}
/*
Thanks Joe Li. See http://phplens.com/lens/lensforum/msgs.php?id=11487&x=1
Since adodb 4.61.
*/
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;
}
/*
Generate database table for session data
@see http://phplens.com/lens/lensforum/msgs.php?id=12280
@return 0 if failure, 1 if errors, 2 if successful.
@author Markus Staab http://www.public-4u.de
*/
function adodb_session_create_table($schemaFile=null,$conn = null)
{
// set default values
if ($schemaFile===null) $schemaFile = ADODB_SESSION . '/session_schema2.xml';
if ($conn===null) $conn =& ADODB_Session::_conn();
if (!$conn) return 0;
$schema = new adoSchema($conn);
$schema->ParseSchema($schemaFile);
return $schema->ExecuteSchema();
}
/*!
\static
*/
class ADODB_Session {
/////////////////////
// getter/setter methods
/////////////////////
/*
function Lock($lock=null)
{
static $_lock = false;
if (!is_null($lock)) $_lock = $lock;
return $lock;
}
*/
/*!
*/
function driver($driver = null)
{
static $_driver = 'mysql';
static $set = false;
if (!is_null($driver)) {
$_driver = trim($driver);
$set = true;
} elseif (!$set) {
// backwards compatibility
if (isset($GLOBALS['ADODB_SESSION_DRIVER'])) {
return $GLOBALS['ADODB_SESSION_DRIVER'];
}
}
return $_driver;
}
/*!
*/
function host($host = null) {
static $_host = 'localhost';
static $set = false;
if (!is_null($host)) {
$_host = trim($host);
$set = true;
} elseif (!$set) {
// backwards compatibility
if (isset($GLOBALS['ADODB_SESSION_CONNECT'])) {
return $GLOBALS['ADODB_SESSION_CONNECT'];
}
}
return $_host;
}
/*!
*/
function user($user = null)
{
static $_user = 'root';
static $set = false;
if (!is_null($user)) {
$_user = trim($user);
$set = true;
} elseif (!$set) {
// backwards compatibility
if (isset($GLOBALS['ADODB_SESSION_USER'])) {
return $GLOBALS['ADODB_SESSION_USER'];
}
}
return $_user;
}
/*!
*/
function password($password = null)
{
static $_password = '';
static $set = false;
if (!is_null($password)) {
$_password = $password;
$set = true;
} elseif (!$set) {
// backwards compatibility
if (isset($GLOBALS['ADODB_SESSION_PWD'])) {
return $GLOBALS['ADODB_SESSION_PWD'];
}
}
return $_password;
}
/*!
*/
function database($database = null)
{
static $_database = '';
static $set = false;
if (!is_null($database)) {
$_database = trim($database);
$set = true;
} elseif (!$set) {
// backwards compatibility
if (isset($GLOBALS['ADODB_SESSION_DB'])) {
return $GLOBALS['ADODB_SESSION_DB'];
}
}
return $_database;
}
/*!
*/
function persist($persist = null)
{
static $_persist = true;
if (!is_null($persist)) {
$_persist = trim($persist);
}
return $_persist;
}
/*!
*/
function lifetime($lifetime = null)
{
static $_lifetime;
static $set = false;
if (!is_null($lifetime)) {
$_lifetime = (int) $lifetime;
$set = true;
} elseif (!$set) {
// backwards compatibility
if (isset($GLOBALS['ADODB_SESS_LIFE'])) {
return $GLOBALS['ADODB_SESS_LIFE'];
}
}
if (!$_lifetime) {
$_lifetime = ini_get('session.gc_maxlifetime');
if ($_lifetime <= 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: $lifetime</h3>";
$_lifetime = 1440;
}
}
return $_lifetime;
}
/*!
*/
function debug($debug = null)
{
static $_debug = false;
static $set = false;
if (!is_null($debug)) {
$_debug = (bool) $debug;
$conn = ADODB_Session::_conn();
if ($conn) {
$conn->debug = $_debug;
}
$set = true;
} elseif (!$set) {
// backwards compatibility
if (isset($GLOBALS['ADODB_SESS_DEBUG'])) {
return $GLOBALS['ADODB_SESS_DEBUG'];
}
}
return $_debug;
}
/*!
*/
function expireNotify($expire_notify = null)
{
static $_expire_notify;
static $set = false;
if (!is_null($expire_notify)) {
$_expire_notify = $expire_notify;
$set = true;
} elseif (!$set) {
// backwards compatibility
if (isset($GLOBALS['ADODB_SESSION_EXPIRE_NOTIFY'])) {
return $GLOBALS['ADODB_SESSION_EXPIRE_NOTIFY'];
}
}
return $_expire_notify;
}
/*!
*/
function table($table = null)
{
static $_table = 'sessions2';
static $set = false;
if (!is_null($table)) {
$_table = trim($table);
$set = true;
} elseif (!$set) {
// backwards compatibility
if (isset($GLOBALS['ADODB_SESSION_TBL'])) {
return $GLOBALS['ADODB_SESSION_TBL'];
}
}
return $_table;
}
/*!
*/
function optimize($optimize = null)
{
static $_optimize = false;
static $set = false;
if (!is_null($optimize)) {
$_optimize = (bool) $optimize;
$set = true;
} elseif (!$set) {
// backwards compatibility
if (defined('ADODB_SESSION_OPTIMIZE')) {
return true;
}
}
return $_optimize;
}
/*!
*/
function syncSeconds($sync_seconds = null) {
//echo ("<p>WARNING: ADODB_SESSION::syncSeconds is longer used, please remove this function for your code</p>");
return 0;
}
/*!
*/
function clob($clob = null) {
static $_clob = false;
static $set = false;
if (!is_null($clob)) {
$_clob = strtolower(trim($clob));
$set = true;
} elseif (!$set) {
// backwards compatibility
if (isset($GLOBALS['ADODB_SESSION_USE_LOBS'])) {
return $GLOBALS['ADODB_SESSION_USE_LOBS'];
}
}
return $_clob;
}
/*!
*/
function dataFieldName($data_field_name = null) {
//echo ("<p>WARNING: ADODB_SESSION::dataFieldName() is longer used, please remove this function for your code</p>");
return '';
}
/*!
*/
function filter($filter = null) {
static $_filter = array();
if (!is_null($filter)) {
if (!is_array($filter)) {
$filter = array($filter);
}
$_filter = $filter;
}
return $_filter;
}
/*!
*/
function encryptionKey($encryption_key = null) {
static $_encryption_key = 'CRYPTED ADODB SESSIONS ROCK!';
if (!is_null($encryption_key)) {
$_encryption_key = $encryption_key;
}
return $_encryption_key;
}
/////////////////////
// private methods
/////////////////////
/*!
*/
function &_conn($conn=null) {
return $GLOBALS['ADODB_SESS_CONN'];
}
/*!
*/
function _crc($crc = null) {
static $_crc = false;
if (!is_null($crc)) {
$_crc = $crc;
}
return $_crc;
}
/*!
*/
function _init() {
session_module_name('user');
session_set_save_handler(
array('ADODB_Session', 'open'),
array('ADODB_Session', 'close'),
array('ADODB_Session', 'read'),
array('ADODB_Session', 'write'),
array('ADODB_Session', 'destroy'),
array('ADODB_Session', 'gc')
);
}
/*!
*/
function _sessionKey() {
// use this function to create the encryption key for crypted sessions
// crypt the used key, ADODB_Session::encryptionKey() as key and session_id() as salt
return crypt(ADODB_Session::encryptionKey(), session_id());
}
/*!
*/
function _dumprs($rs) {
$conn =& ADODB_Session::_conn();
$debug = ADODB_Session::debug();
if (!$conn) {
return;
}
if (!$debug) {
return;
}
if (!$rs) {
echo "<br />\$rs is null or false<br />\n";
return;
}
//echo "<br />\nAffected_Rows=",$conn->Affected_Rows(),"<br />\n";
if (!is_object($rs)) {
return;
}
require_once ADODB_SESSION.'/../tohtml.inc.php';
rs2html($rs);
}
/////////////////////
// public methods
/////////////////////
function config($driver, $host, $user, $password, $database=false,$options=false)
{
ADODB_Session::driver($driver);
ADODB_Session::host($host);
ADODB_Session::user($user);
ADODB_Session::password($password);
ADODB_Session::database($database);
if ($driver == 'oci8' || $driver == 'oci8po') $options['lob'] = 'CLOB';
if (isset($options['table'])) ADODB_Session::table($options['table']);
if (isset($options['lob'])) ADODB_Session::clob($options['lob']);
if (isset($options['debug'])) ADODB_Session::debug($options['debug']);
}
/*!
Create the connection to the database.
If $conn already exists, reuse that connection
*/
function open($save_path, $session_name, $persist = null)
{
$conn =& ADODB_Session::_conn();
if ($conn) {
return true;
}
$database = ADODB_Session::database();
$debug = ADODB_Session::debug();
$driver = ADODB_Session::driver();
$host = ADODB_Session::host();
$password = ADODB_Session::password();
$user = ADODB_Session::user();
if (!is_null($persist)) {
ADODB_Session::persist($persist);
} else {
$persist = ADODB_Session::persist();
}
# these can all be defaulted to in php.ini
# assert('$database');
# assert('$driver');
# assert('$host');
$conn =& ADONewConnection($driver);
if ($debug) {
$conn->debug = true;
ADOConnection::outp( " driver=$driver user=$user db=$database ");
}
if ($persist) {
switch($persist) {
default:
case 'P': $ok = $conn->PConnect($host, $user, $password, $database); break;
case 'C': $ok = $conn->Connect($host, $user, $password, $database); break;
case 'N': $ok = $conn->NConnect($host, $user, $password, $database); break;
}
} else {
$ok = $conn->Connect($host, $user, $password, $database);
}
if ($ok) $GLOBALS['ADODB_SESS_CONN'] =& $conn;
else
ADOConnection::outp('<p>Session: connection failed</p>', false);
return $ok;
}
/*!
Close the connection
*/
function close()
{
/*
$conn =& ADODB_Session::_conn();
if ($conn) $conn->Close();
*/
return true;
}
/*
Slurp in the session variables and return the serialized string
*/
function read($key)
{
$conn =& ADODB_Session::_conn();
$filter = ADODB_Session::filter();
$table = ADODB_Session::table();
if (!$conn) {
return '';
}
//assert('$table');
$qkey = $conn->quote($key);
$binary = $conn->dataProvider === 'mysql' ? '/*! BINARY */' : '';
$sql = "SELECT sessdata FROM $table WHERE sesskey = $binary $qkey AND expiry >= " . $conn->sysTimeStamp;
/* Lock code does not work as it needs to hold transaction within whole page, and we don't know if
developer has commited elsewhere... :(
*/
#if (ADODB_Session::Lock())
# $rs =& $conn->RowLock($table, "$binary sesskey = $qkey AND expiry >= " . time(), sessdata);
#else
$rs =& $conn->Execute($sql);
//ADODB_Session::_dumprs($rs);
if ($rs) {
if ($rs->EOF) {
$v = '';
} else {
$v = reset($rs->fields);
$filter = array_reverse($filter);
foreach ($filter as $f) {
if (is_object($f)) {
$v = $f->read($v, ADODB_Session::_sessionKey());
}
}
$v = rawurldecode($v);
}
$rs->Close();
ADODB_Session::_crc(strlen($v) . crc32($v));
return $v;
}
return '';
}
/*!
Write the serialized data to a database.
If the data has not been modified since the last read(), we do not write.
*/
function write($key, $val)
{
global $ADODB_SESSION_READONLY;
if (!empty($ADODB_SESSION_READONLY)) return;
$clob = ADODB_Session::clob();
$conn =& ADODB_Session::_conn();
$crc = ADODB_Session::_crc();
$debug = ADODB_Session::debug();
$driver = ADODB_Session::driver();
$expire_notify = ADODB_Session::expireNotify();
$filter = ADODB_Session::filter();
$lifetime = ADODB_Session::lifetime();
$table = ADODB_Session::table();
if (!$conn) {
return false;
}
$sysTimeStamp = $conn->sysTimeStamp;
//assert('$table');
$expiry = $conn->OffsetDate($lifetime/(24*3600),$sysTimeStamp);
$binary = $conn->dataProvider === 'mysql' ? '/*! BINARY */' : '';
// crc32 optimization since adodb 2.1
// now we only update expiry date, thx to sebastian thom in adodb 2.32
if ($crc !== false && $crc == (strlen($val) . crc32($val))) {
if ($debug) {
echo '<p>Session: Only updating date - crc32 not changed</p>';
}
$expirevar = '';
if ($expire_notify) {
$var = reset($expire_notify);
global $$var;
if (isset($$var)) {
$expirevar = $$var;
}
}
$sql = "UPDATE $table SET expiry = $expiry ,expireref=".$conn->Param('0').", modified = $sysTimeStamp WHERE $binary sesskey = ".$conn->Param('1')." AND expiry >= $sysTimeStamp";
$rs =& $conn->Execute($sql,array($expirevar,$key));
return true;
}
$val = rawurlencode($val);
foreach ($filter as $f) {
if (is_object($f)) {
$val = $f->write($val, ADODB_Session::_sessionKey());
}
}
$expireref = '';
if ($expire_notify) {
$var = reset($expire_notify);
global $$var;
if (isset($$var)) {
$expireref = $$var;
}
}
if (!$clob) { // no lobs, simply use replace()
$rs =& $conn->Execute("SELECT COUNT(*) AS cnt FROM $table WHERE $binary sesskey = ".$conn->Param(0),array($key));
if ($rs) $rs->Close();
if ($rs && reset($rs->fields) > 0) {
$sql = "UPDATE $table SET expiry=$expiry, sessdata=".$conn->Param(0).", expireref= ".$conn->Param(1).",modified=$sysTimeStamp WHERE sesskey = ".$conn->Param('2');
} else {
$sql = "INSERT INTO $table (expiry, sessdata, expireref, sesskey, created, modified)
VALUES ($expiry,".$conn->Param('0').", ". $conn->Param('1').", ".$conn->Param('2').", $sysTimeStamp, $sysTimeStamp)";
}
$rs =& $conn->Execute($sql,array($val,$expireref,$key));
} else {
// what value shall we insert/update for lob row?
switch ($driver) {
// empty_clob or empty_lob for oracle dbs
case 'oracle':
case 'oci8':
case 'oci8po':
case 'oci805':
$lob_value = sprintf('empty_%s()', strtolower($clob));
break;
// null for all other
default:
$lob_value = 'null';
break;
}
$conn->StartTrans();
$rs =& $conn->Execute("SELECT COUNT(*) AS cnt FROM $table WHERE $binary sesskey = ".$conn->Param(0),array($key));
if ($rs) $rs->Close();
if ($rs && reset($rs->fields) > 0) {
$sql = "UPDATE $table SET expiry=$expiry, sessdata=$lob_value, expireref= ".$conn->Param(0).",modified=$sysTimeStamp WHERE sesskey = ".$conn->Param('1');
} else {
$sql = "INSERT INTO $table (expiry, sessdata, expireref, sesskey, created, modified)
VALUES ($expiry,$lob_value, ". $conn->Param('0').", ".$conn->Param('1').", $sysTimeStamp, $sysTimeStamp)";
}
$rs =& $conn->Execute($sql,array($expireref,$key));
$qkey = $conn->qstr($key);
$rs2 =& $conn->UpdateBlob($table, 'sessdata', $val, " sesskey=$qkey", strtoupper($clob));
$rs = $conn->CompleteTrans();
}
if (!$rs) {
ADOConnection::outp('<p>Session Replace: ' . $conn->ErrorMsg() . '</p>', false);
return false;
} else {
// bug in access driver (could be odbc?) means that info is not committed
// properly unless select statement executed in Win2000
if ($conn->databaseType == 'access') {
$sql = "SELECT sesskey FROM $table WHERE $binary sesskey = $qkey";
$rs =& $conn->Execute($sql);
ADODB_Session::_dumprs($rs);
if ($rs) {
$rs->Close();
}
}
}/*
if (ADODB_Session::Lock()) {
$conn->CommitTrans();
}*/
return $rs ? true : false;
}
/*!
*/
function destroy($key) {
$conn =& ADODB_Session::_conn();
$table = ADODB_Session::table();
$expire_notify = ADODB_Session::expireNotify();
if (!$conn) {
return false;
}
//assert('$table');
$qkey = $conn->quote($key);
$binary = $conn->dataProvider === 'mysql' ? '/*! BINARY */' : '';
if ($expire_notify) {
reset($expire_notify);
$fn = next($expire_notify);
$savem = $conn->SetFetchMode(ADODB_FETCH_NUM);
$sql = "SELECT expireref, sesskey FROM $table WHERE $binary sesskey = $qkey";
$rs =& $conn->Execute($sql);
ADODB_Session::_dumprs($rs);
$conn->SetFetchMode($savem);
if (!$rs) {
return false;
}
if (!$rs->EOF) {
$ref = $rs->fields[0];
$key = $rs->fields[1];
//assert('$ref');
//assert('$key');
$fn($ref, $key);
}
$rs->Close();
}
$sql = "DELETE FROM $table WHERE $binary sesskey = $qkey";
$rs =& $conn->Execute($sql);
ADODB_Session::_dumprs($rs);
if ($rs) {
$rs->Close();
}
return $rs ? true : false;
}
/*!
*/
function gc($maxlifetime)
{
$conn =& ADODB_Session::_conn();
$debug = ADODB_Session::debug();
$expire_notify = ADODB_Session::expireNotify();
$optimize = ADODB_Session::optimize();
$table = ADODB_Session::table();
if (!$conn) {
return false;
}
//assert('$table');
$time = $conn->sysTimeStamp;
$binary = $conn->dataProvider === 'mysql' ? '/*! BINARY */' : '';
if ($expire_notify) {
reset($expire_notify);
$fn = next($expire_notify);
$savem = $conn->SetFetchMode(ADODB_FETCH_NUM);
$sql = "SELECT expireref, sesskey FROM $table WHERE expiry < $time";
$rs =& $conn->Execute($sql);
ADODB_Session::_dumprs($rs);
$conn->SetFetchMode($savem);
if ($rs) {
$conn->StartTrans();
$keys = array();
while (!$rs->EOF) {
$ref = $rs->fields[0];
$key = $rs->fields[1];
$fn($ref, $key);
$del = $conn->Execute("DELETE FROM $table WHERE sesskey=".$conn->Param('0'),array($key));
$rs->MoveNext();
}
$rs->Close();
$conn->CompleteTrans();
}
} else {
if (0) {
$sql = "SELECT sesskey FROM $table WHERE expiry < $time";
$arr =& $conn->GetAll($sql);
foreach ($arr as $row) {
$sql2 = "DELETE FROM $table WHERE sesskey=".$conn->Param('0');
$conn->Execute($sql2,array($row[0]));
}
} else {
$sql = "DELETE FROM $table WHERE expiry < $time";
$rs =& $conn->Execute($sql);
ADODB_Session::_dumprs($rs);
if ($rs) $rs->Close();
}
if ($debug) {
ADOConnection::outp("<p><b>Garbage Collection</b>: $sql</p>");
}
}
// suggested by Cameron, "GaM3R" <[email protected]>
if ($optimize) {
$driver = ADODB_Session::driver();
if (preg_match('/mysql/i', $driver)) {
$sql = "OPTIMIZE TABLE $table";
}
if (preg_match('/postgres/i', $driver)) {
$sql = "VACUUM $table";
}
if (!empty($sql)) {
$conn->Execute($sql);
}
}
return true;
}
}
ADODB_Session::_init();
if (empty($ADODB_SESSION_READONLY))
register_shutdown_function('session_write_close');
// for backwards compatability only
function adodb_sess_open($save_path, $session_name, $persist = true) {
return ADODB_Session::open($save_path, $session_name, $persist);
}
// for backwards compatability only
function adodb_sess_gc($t)
{
return ADODB_Session::gc($t);
}
?>
@@ -0,0 +1,324 @@
<?php
/*
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
Made table name configurable - by David Johnson [email protected]
Encryption by Ari Kuorikoski <[email protected]>
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-cryptsession.php');
#---------------------------------#
session_start();
session_register('AVAR');
$_SESSION['AVAR'] += 1;
print "
-- \$_SESSION['AVAR']={$_SESSION['AVAR']}</p>";
Installation
============
1. Create a new database in MySQL or Access "sessions" like
so:
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. 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.0.2 or later. There are documented
session bugs in earlier versions of PHP.
*/
include_once('crypt.inc.php');
if (!defined('_ADODB_LAYER')) {
include (dirname(__FILE__).'/adodb.inc.php');
}
/* if database time and system time is difference is greater than this, then give warning */
define('ADODB_SESSION_SYNCH_SECS',60);
if (!defined('ADODB_SESSION')) {
define('ADODB_SESSION',1);
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_SESS_INSERT,
$ADODB_SESSION_EXPIRE_NOTIFY,
$ADODB_SESSION_TBL;
//$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_TBL)){
$ADODB_SESSION_TBL = 'sessions';
}
if (empty($ADODB_SESSION_EXPIRE_NOTIFY)) {
$ADODB_SESSION_EXPIRE_NOTIFY = false;
}
function ADODB_Session_Key()
{
$ADODB_CRYPT_KEY = 'CRYPTED ADODB SESSIONS ROCK!';
/* USE THIS FUNCTION TO CREATE THE ENCRYPTION KEY FOR CRYPTED SESSIONS */
/* Crypt the used key, $ADODB_CRYPT_KEY as key and session_ID as SALT */
return crypt($ADODB_CRYPT_KEY, session_ID());
}
$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;
}
function adodb_sess_open($save_path, $session_name)
{
GLOBAL $ADODB_SESSION_CONNECT,
$ADODB_SESSION_DRIVER,
$ADODB_SESSION_USER,
$ADODB_SESSION_PWD,
$ADODB_SESSION_DB,
$ADODB_SESS_CONN,
$ADODB_SESS_DEBUG;
$ADODB_SESS_INSERT = false;
if (isset($ADODB_SESS_CONN)) return true;
$ADODB_SESS_CONN = ADONewConnection($ADODB_SESSION_DRIVER);
if (!empty($ADODB_SESS_DEBUG)) {
$ADODB_SESS_CONN->debug = true;
print" conn=$ADODB_SESSION_CONNECT user=$ADODB_SESSION_USER pwd=$ADODB_SESSION_PWD db=$ADODB_SESSION_DB ";
}
return $ADODB_SESS_CONN->PConnect($ADODB_SESSION_CONNECT,
$ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB);
}
function adodb_sess_close()
{
global $ADODB_SESS_CONN;
if ($ADODB_SESS_CONN) $ADODB_SESS_CONN->Close();
return true;
}
function adodb_sess_read($key)
{
$Crypt = new MD5Crypt;
global $ADODB_SESS_CONN,$ADODB_SESS_INSERT,$ADODB_SESSION_TBL;
$rs = $ADODB_SESS_CONN->Execute("SELECT data FROM $ADODB_SESSION_TBL WHERE sesskey = '$key' AND expiry >= " . time());
if ($rs) {
if ($rs->EOF) {
$ADODB_SESS_INSERT = true;
$v = '';
} else {
// Decrypt session data
$v = rawurldecode($Crypt->Decrypt(reset($rs->fields), ADODB_Session_Key()));
}
$rs->Close();
return $v;
}
else $ADODB_SESS_INSERT = true;
return '';
}
function adodb_sess_write($key, $val)
{
$Crypt = new MD5Crypt;
global $ADODB_SESS_INSERT,$ADODB_SESS_CONN, $ADODB_SESS_LIFE, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY;
$expiry = time() + $ADODB_SESS_LIFE;
// encrypt session data..
$val = $Crypt->Encrypt(rawurlencode($val), ADODB_Session_Key());
$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 isset($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_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_EXPIRE_NOTIFY,$ADODB_SESS_DEBUG;
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 {
$qry = "DELETE FROM $ADODB_SESSION_TBL WHERE expiry < " . time();
$ADODB_SESS_CONN->Execute($qry);
}
// suggested by Cameron, "GaM3R" <[email protected]>
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 ($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;
print "
-- \$_SESSION['AVAR']={$_SESSION['AVAR']}</p>";
}
*/
?>
@@ -0,0 +1,448 @@
<?php
/*
V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
Set tabs to 4 for best viewing.
Latest version of ADODB is available at http://php.weblogs.com/adodb
======================================================================
This file provides PHP4 session management using the ADODB database
wrapper library, using Oracle CLOB's to store data. Contributed by [email protected].
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 [email protected]
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" <[email protected]>
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);
}
?>

Some files were not shown because too many files have changed in this diff Show More