adodb 최신버전으로 변경
<? 를 <?php 로 변경
This commit is contained in:
@@ -2,13 +2,15 @@
|
||||
|
||||
|
||||
/*
|
||||
V5.09 25 June 2009 (c) 2000-2009 John Lim (jlim#natsoft.com). All rights reserved.
|
||||
Contributed by Ross Smith (adodb@netebb.com).
|
||||
@version v5.20.9 21-Dec-2016
|
||||
@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
|
||||
@copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community
|
||||
Contributed by Ross Smith (adodb@netebb.com).
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
@@ -36,10 +38,10 @@ 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 ,
|
||||
@@ -64,16 +66,16 @@ 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.
|
||||
/*
|
||||
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 )
|
||||
function adodb_unserialize( $serialized_string )
|
||||
{
|
||||
$variables = array( );
|
||||
$a = preg_split( "/(\w+)\|/", $serialized_string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
|
||||
@@ -87,7 +89,7 @@ function adodb_unserialize( $serialized_string )
|
||||
Thanks Joe Li. See http://phplens.com/lens/lensforum/msgs.php?id=11487&x=1
|
||||
Since adodb 4.61.
|
||||
*/
|
||||
function adodb_session_regenerate_id()
|
||||
function adodb_session_regenerate_id()
|
||||
{
|
||||
$conn = ADODB_Session::_conn();
|
||||
if (!$conn) return false;
|
||||
@@ -103,7 +105,7 @@ function adodb_session_regenerate_id()
|
||||
}
|
||||
$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);
|
||||
@@ -111,7 +113,7 @@ function adodb_session_regenerate_id()
|
||||
setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -141,20 +143,20 @@ class ADODB_Session {
|
||||
/////////////////////
|
||||
// getter/setter methods
|
||||
/////////////////////
|
||||
|
||||
|
||||
/*
|
||||
|
||||
|
||||
function Lock($lock=null)
|
||||
{
|
||||
static $_lock = false;
|
||||
|
||||
|
||||
if (!is_null($lock)) $_lock = $lock;
|
||||
return $lock;
|
||||
}
|
||||
*/
|
||||
/*!
|
||||
*/
|
||||
static function driver($driver = null)
|
||||
static function driver($driver = null)
|
||||
{
|
||||
static $_driver = 'mysql';
|
||||
static $set = false;
|
||||
@@ -193,7 +195,7 @@ class ADODB_Session {
|
||||
|
||||
/*!
|
||||
*/
|
||||
static function user($user = null)
|
||||
static function user($user = null)
|
||||
{
|
||||
static $_user = 'root';
|
||||
static $set = false;
|
||||
@@ -213,7 +215,7 @@ class ADODB_Session {
|
||||
|
||||
/*!
|
||||
*/
|
||||
static function password($password = null)
|
||||
static function password($password = null)
|
||||
{
|
||||
static $_password = '';
|
||||
static $set = false;
|
||||
@@ -233,11 +235,11 @@ class ADODB_Session {
|
||||
|
||||
/*!
|
||||
*/
|
||||
static function database($database = null)
|
||||
static function database($database = null)
|
||||
{
|
||||
static $_database = '';
|
||||
static $set = false;
|
||||
|
||||
|
||||
if (!is_null($database)) {
|
||||
$_database = trim($database);
|
||||
$set = true;
|
||||
@@ -252,7 +254,7 @@ class ADODB_Session {
|
||||
|
||||
/*!
|
||||
*/
|
||||
static function persist($persist = null)
|
||||
static function persist($persist = null)
|
||||
{
|
||||
static $_persist = true;
|
||||
|
||||
@@ -265,7 +267,7 @@ class ADODB_Session {
|
||||
|
||||
/*!
|
||||
*/
|
||||
static function lifetime($lifetime = null)
|
||||
static function lifetime($lifetime = null)
|
||||
{
|
||||
static $_lifetime;
|
||||
static $set = false;
|
||||
@@ -293,7 +295,7 @@ class ADODB_Session {
|
||||
|
||||
/*!
|
||||
*/
|
||||
static function debug($debug = null)
|
||||
static function debug($debug = null)
|
||||
{
|
||||
static $_debug = false;
|
||||
static $set = false;
|
||||
@@ -318,7 +320,7 @@ class ADODB_Session {
|
||||
|
||||
/*!
|
||||
*/
|
||||
static function expireNotify($expire_notify = null)
|
||||
static function expireNotify($expire_notify = null)
|
||||
{
|
||||
static $_expire_notify;
|
||||
static $set = false;
|
||||
@@ -338,7 +340,7 @@ class ADODB_Session {
|
||||
|
||||
/*!
|
||||
*/
|
||||
static function table($table = null)
|
||||
static function table($table = null)
|
||||
{
|
||||
static $_table = 'sessions2';
|
||||
static $set = false;
|
||||
@@ -358,7 +360,7 @@ class ADODB_Session {
|
||||
|
||||
/*!
|
||||
*/
|
||||
static function optimize($optimize = null)
|
||||
static function optimize($optimize = null)
|
||||
{
|
||||
static $_optimize = false;
|
||||
static $set = false;
|
||||
@@ -380,7 +382,7 @@ class ADODB_Session {
|
||||
*/
|
||||
static function syncSeconds($sync_seconds = null) {
|
||||
//echo ("<p>WARNING: ADODB_SESSION::syncSeconds is longer used, please remove this function for your code</p>");
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -507,7 +509,7 @@ class ADODB_Session {
|
||||
return;
|
||||
}
|
||||
$rs = $conn->_rs2rs($rs);
|
||||
|
||||
|
||||
require_once ADODB_SESSION.'/../tohtml.inc.php';
|
||||
rs2html($rs);
|
||||
$rs->MoveFirst();
|
||||
@@ -516,7 +518,7 @@ class ADODB_Session {
|
||||
/////////////////////
|
||||
// public methods
|
||||
/////////////////////
|
||||
|
||||
|
||||
static function config($driver, $host, $user, $password, $database=false,$options=false)
|
||||
{
|
||||
ADODB_Session::driver($driver);
|
||||
@@ -524,9 +526,9 @@ class ADODB_Session {
|
||||
ADODB_Session::user($user);
|
||||
ADODB_Session::password($password);
|
||||
ADODB_Session::database($database);
|
||||
|
||||
if ($driver == 'oci8' || $driver == 'oci8po') $options['lob'] = 'CLOB';
|
||||
|
||||
|
||||
if (strncmp($driver, 'oci8', 4) == 0) $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']);
|
||||
@@ -537,7 +539,7 @@ class ADODB_Session {
|
||||
|
||||
If $conn already exists, reuse that connection
|
||||
*/
|
||||
static function open($save_path, $session_name, $persist = null)
|
||||
static function open($save_path, $session_name, $persist = null)
|
||||
{
|
||||
$conn = ADODB_Session::_conn();
|
||||
|
||||
@@ -566,25 +568,29 @@ class ADODB_Session {
|
||||
$conn = ADONewConnection($driver);
|
||||
|
||||
if ($debug) {
|
||||
$conn->debug = true;
|
||||
$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;
|
||||
|
||||
if (empty($conn->_connectionID)) { // not dsn
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
$ok = $conn->Connect($host, $user, $password, $database);
|
||||
$ok = true; // $conn->_connectionID is set after call to ADONewConnection
|
||||
}
|
||||
|
||||
if ($ok) $GLOBALS['ADODB_SESS_CONN'] = $conn;
|
||||
else
|
||||
ADOConnection::outp('<p>Session: connection failed</p>', false);
|
||||
|
||||
|
||||
|
||||
return $ok;
|
||||
}
|
||||
@@ -592,7 +598,7 @@ class ADODB_Session {
|
||||
/*!
|
||||
Close the connection
|
||||
*/
|
||||
static function close()
|
||||
static function close()
|
||||
{
|
||||
/*
|
||||
$conn = ADODB_Session::_conn();
|
||||
@@ -604,7 +610,7 @@ class ADODB_Session {
|
||||
/*
|
||||
Slurp in the session variables and return the serialized string
|
||||
*/
|
||||
static function read($key)
|
||||
static function read($key)
|
||||
{
|
||||
$conn = ADODB_Session::_conn();
|
||||
$filter = ADODB_Session::filter();
|
||||
@@ -617,9 +623,12 @@ class ADODB_Session {
|
||||
//assert('$table');
|
||||
|
||||
$binary = $conn->dataProvider === 'mysql' ? '/*! BINARY */' : '';
|
||||
|
||||
$sql = "SELECT sessdata FROM $table WHERE sesskey = $binary ".$conn->Param(0)." AND expiry >= " . $conn->sysTimeStamp;
|
||||
/* Lock code does not work as it needs to hold transaction within whole page, and we don't know if
|
||||
|
||||
global $ADODB_SESSION_SELECT_FIELDS;
|
||||
if (!isset($ADODB_SESSION_SELECT_FIELDS)) $ADODB_SESSION_SELECT_FIELDS = 'sessdata';
|
||||
$sql = "SELECT $ADODB_SESSION_SELECT_FIELDS FROM $table WHERE sesskey = $binary ".$conn->Param(0)." 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())
|
||||
@@ -655,12 +664,12 @@ class ADODB_Session {
|
||||
|
||||
If the data has not been modified since the last read(), we do not write.
|
||||
*/
|
||||
static function write($key, $oval)
|
||||
static function write($key, $oval)
|
||||
{
|
||||
global $ADODB_SESSION_READONLY;
|
||||
|
||||
|
||||
if (!empty($ADODB_SESSION_READONLY)) return;
|
||||
|
||||
|
||||
$clob = ADODB_Session::clob();
|
||||
$conn = ADODB_Session::_conn();
|
||||
$crc = ADODB_Session::_crc();
|
||||
@@ -670,13 +679,13 @@ class ADODB_Session {
|
||||
$filter = ADODB_Session::filter();
|
||||
$lifetime = ADODB_Session::lifetime();
|
||||
$table = ADODB_Session::table();
|
||||
|
||||
|
||||
if (!$conn) {
|
||||
return false;
|
||||
}
|
||||
if ($debug) $conn->debug = 1;
|
||||
$sysTimeStamp = $conn->sysTimeStamp;
|
||||
|
||||
|
||||
//assert('$table');
|
||||
|
||||
$expiry = $conn->OffsetDate($lifetime/(24*3600),$sysTimeStamp);
|
||||
@@ -685,11 +694,11 @@ class ADODB_Session {
|
||||
|
||||
// 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($oval) . crc32($oval))) {
|
||||
if ($crc !== '00' && $crc !== false && $crc == (strlen($oval) . crc32($oval))) {
|
||||
if ($debug) {
|
||||
echo '<p>Session: Only updating date - crc32 not changed</p>';
|
||||
}
|
||||
|
||||
|
||||
$expirevar = '';
|
||||
if ($expire_notify) {
|
||||
$var = reset($expire_notify);
|
||||
@@ -698,8 +707,8 @@ class ADODB_Session {
|
||||
$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;
|
||||
@@ -718,61 +727,48 @@ class ADODB_Session {
|
||||
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');
|
||||
|
||||
$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)
|
||||
$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;
|
||||
if (strncmp($driver, 'oci8', 4) == 0) $lob_value = sprintf('empty_%s()', strtolower($clob));
|
||||
else $lob_value = 'null';
|
||||
|
||||
// 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)
|
||||
$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));
|
||||
if ($debug) echo "<hr>",htmlspecialchars($oval), "<hr>";
|
||||
$rs = @$conn->CompleteTrans();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (!$rs) {
|
||||
@@ -845,7 +841,7 @@ class ADODB_Session {
|
||||
|
||||
/*!
|
||||
*/
|
||||
static function gc($maxlifetime)
|
||||
static function gc($maxlifetime)
|
||||
{
|
||||
$conn = ADODB_Session::_conn();
|
||||
$debug = ADODB_Session::debug();
|
||||
@@ -865,7 +861,7 @@ class ADODB_Session {
|
||||
} else {
|
||||
$COMMITNUM = 20;
|
||||
}
|
||||
|
||||
|
||||
//assert('$table');
|
||||
|
||||
$time = $conn->OffsetDate(-$maxlifetime/24/3600,$conn->sysTimeStamp);
|
||||
@@ -877,12 +873,12 @@ class ADODB_Session {
|
||||
} else {
|
||||
$fn = false;
|
||||
}
|
||||
|
||||
|
||||
$savem = $conn->SetFetchMode(ADODB_FETCH_NUM);
|
||||
$sql = "SELECT expireref, sesskey FROM $table WHERE expiry < $time ORDER BY 2"; # add order by to prevent deadlock
|
||||
$rs = $conn->SelectLimit($sql,1000);
|
||||
ADODB_Session::_dumprs($rs);
|
||||
if ($debug) $conn->SetFetchMode($savem);
|
||||
if ($debug) ADODB_Session::_dumprs($rs);
|
||||
$conn->SetFetchMode($savem);
|
||||
if ($rs) {
|
||||
$tr = $conn->hasTransactions;
|
||||
if ($tr) $conn->BeginTrans();
|
||||
@@ -902,10 +898,10 @@ class ADODB_Session {
|
||||
}
|
||||
}
|
||||
$rs->Close();
|
||||
|
||||
|
||||
if ($tr) $conn->CommitTrans();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// suggested by Cameron, "GaM3R" <gamr@outworld.cx>
|
||||
if ($optimize) {
|
||||
@@ -922,7 +918,7 @@ class ADODB_Session {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -938,8 +934,6 @@ function adodb_sess_open($save_path, $session_name, $persist = true) {
|
||||
|
||||
// for backwards compatability only
|
||||
function adodb_sess_gc($t)
|
||||
{
|
||||
{
|
||||
return ADODB_Session::gc($t);
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user