Upgrading ADOdb to 4.11 ... there were lots of little bug fixes

This commit is contained in:
moodler
2004-01-30 03:11:47 +00:00
parent 89f1cea654
commit 25be6cfff3
115 changed files with 5583 additions and 1527 deletions
+2 -2
View File
@@ -3,7 +3,7 @@ global $ADODB_INCLUDED_CSV;
$ADODB_INCLUDED_CSV = 1;
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
@@ -83,8 +83,8 @@ $ADODB_INCLUDED_CSV = 1;
*/
function &csv2rs($url,&$err,$timeout=0)
{
$fp = @fopen($url,'r');
$err = false;
$fp = @fopen($url,'r');
if (!$fp) {
$err = $url.' file/URL not found';
return false;
+112 -41
View File
@@ -1,7 +1,7 @@
<?php
/**
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
@@ -18,19 +18,30 @@
*/
function Lens_ParseTest()
{
$str = "ACOL NUMBER(32,2) DEFAULT 'The \"cow\" (and Jim''s dog) jumps over the moon' PRIMARY, INTI INT AUTO DEFAULT 0";
$str = "`zcol ACOL` NUMBER(32,2) DEFAULT 'The \"cow\" (and Jim''s dog) jumps over the moon' PRIMARY, INTI INT AUTO DEFAULT 0";
print "<p>$str</p>";
$a= Lens_ParseArgs($str);
print "<pre>";
print_r($a);
print "</pre>";
}
if (!function_exists('ctype_alnum')) {
function ctype_alnum($text) {
return preg_match('/^[a-z0-9]*$/i', $text);
}
}
//Lens_ParseTest();
/**
Parse arguments, treat "text" (text) and 'text' as quotation marks.
To escape, use "" or '' or ))
Will read in "abc def" sans quotes, as: abc def
Same with 'abc def'.
However if `abc def`, then will read in as `abc def`
@param endstmtchar Character that indicates end of statement
@param tokenchars Include the following characters in tokens apart from A-Z and 0-9
@returns 2 dimensional array containing parsed tokens.
@@ -63,7 +74,9 @@ function Lens_ParseArgs($args,$endstmtchar=',',$tokenchars='_.-')
$tokarr[] = $ch;
break;
case '`':
if ($intoken) $tokarr[] = $ch;
case '(':
case ')':
case '"':
@@ -98,6 +111,7 @@ function Lens_ParseArgs($args,$endstmtchar=',',$tokenchars='_.-')
$quoted = true;
$intoken = true;
$tokarr = array();
if ($ch == '`') $tokarr[] = '`';
}
break;
@@ -143,14 +157,14 @@ function Lens_ParseArgs($args,$endstmtchar=',',$tokenchars='_.-')
class ADODB_DataDict {
var $connection;
var $debug = false;
var $dropTable = "DROP TABLE %s";
var $dropTable = 'DROP TABLE %s';
var $dropIndex = 'DROP INDEX %s';
var $addCol = ' ADD';
var $alterCol = ' ALTER COLUMN';
var $dropCol = ' DROP COLUMN';
var $schema = false;
var $serverInfo = array();
var $autoIncrement = false;
var $quote = '';
var $dataProvider;
var $blobSize = 100; /// any varchar/char field this size or greater is treated as a blob
/// in other words, we use a text area for editting.
@@ -170,9 +184,9 @@ class ADODB_DataDict {
return $this->connection->MetaTables();
}
function &MetaColumns($tab)
function &MetaColumns($tab,$schema=false,$upper=true)
{
return $this->connection->MetaColumns($tab);
return $this->connection->MetaColumns($tab,$schema,$upper);
}
function &MetaPrimaryKeys($tab,$owner=false,$intkey=false)
@@ -180,11 +194,34 @@ class ADODB_DataDict {
return $this->connection->MetaPrimaryKeys($tab.$owner,$intkey);
}
function &MetaIndexes($table, $primary = false, $owner = false)
{
return $this->connection->MetaIndexes($table, $primary, $owner);
}
function MetaType($t,$len=-1,$fieldobj=false)
{
return ADORecordSet::MetaType($t,$len,$fieldobj);
}
function NameQuote($name)
{
if ( !is_object($this->connection) ) {
return $name;
}
$replace = $this->connection->nameQuote .'$1'. $this->connection->nameQuote;
return preg_replace('/^`([^`]+)`$/', $replace, $name);
}
function TableName($name)
{
if ( $this->schema ) {
return $this->NameQuote($this->schema) .'.'. $this->NameQuote($name);
}
return $this->NameQuote($name);
}
// Executes the sql array returned by GetTableSQL and GetIndexSQL
function ExecuteSQLArray($sql, $continueOnError = true)
{
@@ -231,9 +268,12 @@ class ADODB_DataDict {
function CreateDatabase($dbname,$options=false)
{
$options = $this->_Options($options);
if (!preg_match('/^[a-z0-9A-Z_]*$/',$dbname)) $dbname = $this->quote.$dbname.$this->quote;
$s = 'CREATE DATABASE '.$dbname;
if (isset($options[$this->upperName])) $s .= ' '.$options[$this->upperName];
$sql = array();
$s = 'CREATE DATABASE ' . $this->NameQuote($dbname);
if (isset($options[$this->upperName]))
$s .= ' '.$options[$this->upperName];
$sql[] = $s;
return $sql;
}
@@ -243,8 +283,12 @@ class ADODB_DataDict {
*/
function CreateIndexSQL($idxname, $tabname, $flds, $idxoptions = false)
{
if ($this->schema) $tabname = $this->schema.'.'.$tabname;
return $this->_IndexSQL($idxname, $tabname, $flds, $this->_Options($idxoptions));
return $this->_IndexSQL($this->NameQuote($idxname), $this->TableName($tabname), $flds, $this->_Options($idxoptions));
}
function DropIndexSQL ($idxname, $tabname = NULL)
{
return array(sprintf($this->dropIndex, $this->NameQuote($idxname)));
}
function SetSchema($schema)
@@ -253,44 +297,44 @@ class ADODB_DataDict {
}
function AddColumnSQL($tabname, $flds)
{
if ($this->schema) $tabname = $this->schema.'.'.$tabname;
{
$tabname = $this->TableName ($tabname);
$sql = array();
list($lines,$pkey) = $this->_GenFields($flds);
$alter = 'ALTER TABLE ' . $tabname . ' ' . $this->addCol . ' ';
foreach($lines as $v) {
$sql[] = "ALTER TABLE $tabname $this->addCol $v";
$sql[] = $alter . $v;
}
return $sql;
}
function AlterColumnSQL($tabname, $flds)
{
if ($this->schema) $tabname = $this->schema.'.'.$tabname;
$tabname = $this->TableName ($tabname);
$sql = array();
list($lines,$pkey) = $this->_GenFields($flds);
$alter = 'ALTER TABLE ' . $tabname . ' ' . $this->alterCol . ' ';
foreach($lines as $v) {
$sql[] = "ALTER TABLE $tabname $this->alterCol $v";
$sql[] = $alter . $v;
}
return $sql;
}
function DropColumnSQL($tabname, $flds)
{
if ($this->schema) $tabname = $this->schema.'.'.$tabname;
$tabname = $this->TableName ($tabname);
if (!is_array($flds)) $flds = explode(',',$flds);
$sql = array();
$alter = 'ALTER TABLE ' . $tabname . ' ' . $this->dropCol . ' ';
foreach($flds as $v) {
$sql[] = "ALTER TABLE $tabname $this->dropCol $v";
$sql[] = $alter . $v;
}
return $sql;
}
function DropTableSQL($tabname)
{
if ($this->schema) $tabname = $this->schema.'.'.$tabname;
$sql[] = sprintf($this->dropTable,$tabname);
return $sql;
return array (sprintf($this->dropTable, $this->TableName($tabname)));
}
/*
@@ -299,11 +343,11 @@ class ADODB_DataDict {
function CreateTableSQL($tabname, $flds, $tableoptions=false)
{
if (!$tableoptions) $tableoptions = array();
list($lines,$pkey) = $this->_GenFields($flds);
$taboptions = $this->_Options($tableoptions);
if ($this->schema) $tabname = $this->schema.'.'.$tabname;
$tabname = $this->TableName ($tabname);
$sql = $this->_TableSQL($tabname,$lines,$pkey,$taboptions);
$tsql = $this->_Triggers($tabname,$taboptions);
@@ -370,7 +414,9 @@ class ADODB_DataDict {
case 'NAME': $fname = $v; break;
case '1':
case 'TYPE': $ty = $v; $ftype = $this->ActualType(strtoupper($v)); break;
case 'SIZE': $dotat = strpos($v,'.');
case 'SIZE':
$dotat = strpos($v,'.'); if ($dotat === false) $dotat = strpos($v,',');
if ($dotat === false) $fsize = $v;
else {
$fsize = substr($v,0,$dotat);
@@ -399,6 +445,8 @@ class ADODB_DataDict {
return false;
}
$fname = $this->NameQuote($fname);
if (!strlen($ftype)) {
if ($this->debug) ADOConnection::outp("Undefined TYPE for field '$fname'");
return false;
@@ -456,7 +504,7 @@ class ADODB_DataDict {
{
if (strlen($fsize) && $ty != 'X' && $ty != 'B' && strpos($ftype,'(') === false) {
$ftype .= "(".$fsize;
if ($fprec) $ftype .= ",".$fprec;
if (strlen($fprec)) $ftype .= ",".$fprec;
$ftype .= ')';
}
return $ftype;
@@ -475,14 +523,28 @@ class ADODB_DataDict {
function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
{
if (isset($idxoptions['REPLACE'])) $sql[] = "DROP INDEX $idxname";
if (isset($idxoptions['UNIQUE'])) $unique = ' UNIQUE';
else $unique = '';
$sql = array();
if (is_array($flds)) $flds = implode(', ',$flds);
$s = "CREATE$unique INDEX $idxname ON $tabname ";
if (isset($idxoptions[$this->upperName])) $s .= $idxoptions[$this->upperName];
$s .= "($flds)";
if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
$sql[] = sprintf ($this->dropIndex, $idxname);
if ( isset($idxoptions['DROP']) )
return $sql;
}
if ( empty ($flds) ) {
return $sql;
}
$unique = isset($idxoptions['UNIQUE']) ? ' UNIQUE' : '';
$s = 'CREATE' . $unique . ' INDEX ' . $idxname . ' ON ' . $tabname . ' ';
if ( isset($idxoptions[$this->upperName]) )
$s .= $idxoptions[$this->upperName];
if ( is_array($flds) )
$flds = implode(', ',$flds);
$s .= '(' . $flds . ')';
$sql[] = $s;
return $sql;
@@ -497,12 +559,15 @@ class ADODB_DataDict {
{
$sql = array();
if (isset($tableoptions['REPLACE'])) {
if (isset($tableoptions['REPLACE']) || isset ($tableoptions['DROP'])) {
$sql[] = sprintf($this->dropTable,$tabname);
if ($this->autoIncrement) {
$sInc = $this->_DropAutoIncrement($tabname);
$sInc = $this->_DropAutoIncrement($tabname);
if ($sInc) $sql[] = $sInc;
}
if ( isset ($tableoptions['DROP']) ) {
return $sql;
}
}
$s = "CREATE TABLE $tabname (\n";
$s .= implode(",\n", $lines);
@@ -557,15 +622,21 @@ own.
*/
function ChangeTableSQL($tablename, $flds,$tableoptions=false)
{
if ($this->schema) $tabname = $this->schema.'.'.$tablename;
else $tabname = $tablename;
$tabname = $this->TableName ($tablename);
$conn = &$this->connection;
if (!$conn) return false;
if (!is_object ($conn)) {
return false;
}
$colarr = &$conn->MetaColumns($tabname);
if (!$colarr) return $this->CreateTableSQL($tablename,$flds,$tableoptions);
foreach($colarr as $col) $cols[strtoupper($col->name)] = " ALTER ";
if (!$colarr) {
return $this->CreateTableSQL($tablename,$flds,$tableoptions);
}
foreach($colarr as $col) {
$cols[strtoupper($col->name)] = " ALTER ";
}
$sql = array();
list($lines,$pkey) = $this->_GenFields($flds);
+6 -5
View File
@@ -1,6 +1,6 @@
<?php
/**
* @version V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
* @version V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
@@ -94,12 +94,12 @@ function adodb_error_pg($errormsg)
'/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*/' => DB_ERROR_ALREADY_EXISTS,
'/divide by zero$/' => DB_ERROR_DIVZERO,
'/pg_atoi: error in .*: can\'t parse /' => DB_ERROR_INVALID_NUMBER,
'/ttribute [\"\'].*[\"\'] not found$|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/' => DB_ERROR_NOSUCHFIELD,
'/ttribute [\"\'].*[\"\'] not found|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/' => DB_ERROR_NOSUCHFIELD,
'/parser: parse error at or near \"/' => DB_ERROR_SYNTAX,
'/referential integrity violation/' => DB_ERROR_CONSTRAINT
);
foreach ($error_regexps as $regexp => $code) {
reset($error_regexps);
while (list($regexp,$code) = each($error_regexps)) {
if (preg_match($regexp, $errormsg)) {
return $code;
}
@@ -190,6 +190,7 @@ static $MAP = array(
function adodb_error_oci8()
{
static $MAP = array(
1 => DB_ERROR_ALREADY_EXISTS,
900 => DB_ERROR_SYNTAX,
904 => DB_ERROR_NOSUCHFIELD,
923 => DB_ERROR_SYNTAX,
@@ -199,7 +200,7 @@ static $MAP = array(
1722 => DB_ERROR_INVALID_NUMBER,
2289 => DB_ERROR_NOSUCHTABLE,
2291 => DB_ERROR_CONSTRAINT,
2449 => DB_ERROR_CONSTRAINT,
2449 => DB_ERROR_CONSTRAINT
);
return $MAP;
+7 -6
View File
@@ -1,9 +1,9 @@
<?php
/**
* @version V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
* @version V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
* Whenever there is any discrepancy between the two licenses,
* the BSD license will take precedence.
*
* Set tabs to 4 for best viewing.
*
@@ -16,7 +16,7 @@ if (!defined('ADODB_ERROR_HANDLER_TYPE')) define('ADODB_ERROR_HANDLER_TYPE',E_US
define('ADODB_ERROR_HANDLER','ADODB_Error_Handler');
/**
/**
* Default Error Handler. This will be called with the following params
*
* @param $dbms the RDBMS you are connecting to
@@ -24,8 +24,9 @@ define('ADODB_ERROR_HANDLER','ADODB_Error_Handler');
* @param $errno the native error number from the database
* @param $errmsg the native error msg from the database
* @param $p1 $fn specific parameter - see below
* @param $P2 $fn specific parameter - see below
*/
* @param $p2 $fn specific parameter - see below
* @param $thisConn $current connection object - can be false if no connection object created
*/
function ADODB_Error_Handler($dbms, $fn, $errno, $errmsg, $p1, $p2, &$thisConnection)
{
if (error_reporting() == 0) return; // obey @ protocol
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/**
* @version V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
* @version V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
+77
View File
@@ -0,0 +1,77 @@
<?php
/**
* @version V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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
*
* Exception-handling code using PHP5 exceptions (try-catch-throw).
*/
if (!defined('ADODB_ERROR_HANDLER_TYPE')) define('ADODB_ERROR_HANDLER_TYPE',E_USER_ERROR);
define('ADODB_ERROR_HANDLER','adodb_throw');
class ADODB_Exception extends Exception {
var $dbms;
var $fn;
var $sql = '';
var $params = '';
var $host = '';
var $database = '';
function __construct($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection)
{
switch($fn) {
case 'EXECUTE':
$this->sql = $p1;
$this->params = $p2;
$s = "$dbms error: [$errno: $errmsg] in $fn(\"$p1\")\n";
break;
case 'PCONNECT':
case 'CONNECT':
$user = $thisConnection->user;
$s = "$dbms error: [$errno: $errmsg] in $fn($p1, '$user', '****', $p2)\n";
break;
default:
$s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)\n";
break;
}
$this->dbms = $dbms;
$this->host = $thisConnection->host;
$this->database = $thisConnection->database;
$this->fn = $fn;
$this->msg = $errmsg;
parent::__construct($s,$errno);
}
}
/**
* Default Error Handler. This will be called with the following params
*
* @param $dbms the RDBMS you are connecting to
* @param $fn the name of the calling function (in uppercase)
* @param $errno the native error number from the database
* @param $errmsg the native error msg from the database
* @param $p1 $fn specific parameter - see below
* @param $P2 $fn specific parameter - see below
*/
function adodb_throw($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection)
{
global $ADODB_EXCEPTION;
if (is_string($ADODB_EXCEPTION)) $errfn = $ADODB_EXCEPTION;
else $errfn = 'ADODB_EXCEPTION';
throw new $errfn($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection);
}
?>
+56
View File
@@ -0,0 +1,56 @@
<?php
/*
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
PHP5 Iterator Class:
$rs = $db->Execute("select * from adoxyz");
foreach($rs as $k => $v) {
echo $k; print_r($v); echo "<br>";
}
*/
class ADODB_Iterator implements Iterator {
private $rs;
function __construct($rs)
{
$this->rs = $rs;
}
function rewind()
{
$this->rs->MoveFirst();
}
function hasMore()
{
return !$this->rs->EOF;
}
function key()
{
return $this->rs->_currentRow;
}
function current()
{
return $this->rs->fields;
}
function next()
{
$this->rs->MoveNext();
}
}
class ADODB_BASE_RS implements IteratorAggregate {
function getIterator() {
return new ADODB_Iterator($this);
}
}
?>
+138 -67
View File
@@ -4,7 +4,7 @@ global $ADODB_INCLUDED_LIB;
$ADODB_INCLUDED_LIB = 1;
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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,7 +19,7 @@ V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights rese
function _array_change_key_case($an_array)
{
if (is_array($an_array)) {
foreach($an_array as $key => $value)
foreach($an_array as $key=>$value)
$new_array[strtoupper($key)] = $value;
return $new_array;
@@ -28,6 +28,75 @@ function _array_change_key_case($an_array)
return $an_array;
}
function _adodb_replace(&$zthis, $table, $fieldArray, $keyCol, $autoQuote, $has_autoinc)
{
if (count($fieldArray) == 0) return 0;
$first = true;
$uSet = '';
if (!is_array($keyCol)) {
$keyCol = array($keyCol);
}
foreach($fieldArray as $k => $v) {
if ($autoQuote && !is_numeric($v) and strncmp($v,"'",1) !== 0 and strcasecmp($v,'null')!=0) {
$v = $zthis->qstr($v);
$fieldArray[$k] = $v;
}
if (in_array($k,$keyCol)) continue; // skip UPDATE if is key
if ($first) {
$first = false;
$uSet = "$k=$v";
} else
$uSet .= ",$k=$v";
}
$where = false;
foreach ($keyCol as $v) {
if ($where) $where .= " and $v=$fieldArray[$v]";
else $where = "$v=$fieldArray[$v]";
}
if ($uSet && $where) {
$update = "UPDATE $table SET $uSet WHERE $where";
$rs = $zthis->Execute($update);
if ($rs) {
if ($zthis->poorAffectedRows) {
/*
The Select count(*) wipes out any errors that the update would have returned.
http://phplens.com/lens/lensforum/msgs.php?id=5696
*/
if ($zthis->ErrorNo()<>0) return 0;
# affected_rows == 0 if update field values identical to old values
# for mysql - which is silly.
$cnt = $zthis->GetOne("select count(*) from $table where $where");
if ($cnt > 0) return 1; // record already exists
} else
if (($zthis->Affected_Rows()>0)) return 1;
}
}
// print "<p>Error=".$this->ErrorNo().'<p>';
$first = true;
foreach($fieldArray as $k => $v) {
if ($has_autoinc && in_array($k,$keyCol)) continue; // skip autoinc col
if ($first) {
$first = false;
$iCols = "$k";
$iVals = "$v";
} else {
$iCols .= ",$k";
$iVals .= ",$v";
}
}
$insert = "INSERT INTO $table ($iCols) VALUES ($iVals)";
$rs = $zthis->Execute($insert);
return ($rs) ? 2 : 0;
}
// Requires $ADODB_FETCH_MODE = ADODB_FETCH_NUM
function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=false,
$size=0, $selectAttr='',$compareFields0=true)
@@ -138,9 +207,12 @@ function _adodb_getcount(&$zthis, $sql,$inputarr=false,$secs2cache=0)
if ($qryRecs !== false) return $qryRecs;
}
//--------------------------------------------
// query rewrite failed - so try slower way...
// strip off unneeded ORDER BY
$rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$sql);
$rstest = &$zthis->Execute($rewritesql);
$rstest = &$zthis->Execute($rewritesql,$inputarr);
if ($rstest) {
$qryRecs = $rstest->RecordCount();
if ($qryRecs == -1) {
@@ -400,79 +472,78 @@ function _adodb_getinsertsql(&$zthis,&$rs,$arrFields,$magicq=false)
$values = '';
$fields = '';
$arrFields = _array_change_key_case($arrFields);
if (!$rs) {
printf(ADODB_BAD_RS,'GetInsertSQL');
return false;
}
printf(ADODB_BAD_RS,'GetInsertSQL');
return false;
}
$fieldInsertedCount = 0;
// Loop through all of the fields in the recordset
for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++) {
$fieldInsertedCount = 0;
// Get the field from the recordset
$field = $rs->FetchField($i);
// If the recordset field is one
// of the fields passed in then process.
$upperfname = strtoupper($field->name);
if (adodb_key_exists($upperfname,$arrFields)) {
// Set the counter for the number of fields that will be inserted.
$fieldInsertedCount++;
// Loop through all of the fields in the recordset
for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++) {
// Get the name of the fields to insert
$fields .= $field->name . ", ";
$mt = $rs->MetaType($field->type);
// "mike" <[email protected]> patch and "Ryan Bailey" <[email protected]>
//PostgreSQL uses a 't' or 'f' and therefore needs to be processed as a string ('C') type field.
if ((strncmp($zthis->databaseType,"postgres",8) === 0) && ($mt == "L")) $mt = "C";
// Get the field from the recordset
$field = $rs->FetchField($i);
// If the recordset field is one
// of the fields passed in then process.
$upperfname = strtoupper($field->name);
if (adodb_key_exists($upperfname,$arrFields)) {
// Based on the datatype of the field
// Format the value properly for the database
if ((defined('ADODB_FORCE_NULLS') && is_null($arrFields[$upperfname])) || $arrFields[$upperfname] === 'null')
$values .= "null, ";
else
switch($mt) {
case "C":
case "X":
case 'B':
$values .= $zthis->qstr($arrFields[$upperfname],$magicq) . ", ";
break;
case "D":
$values .= $zthis->DBDate($arrFields[$upperfname]) . ", ";
break;
case "T":
$values .= $zthis->DBTimeStamp($arrFields[$upperfname]) . ", ";
break;
default:
$val = $arrFields[$upperfname];
if (!is_numeric($val)) $val = (float) $val;
$values .= $val . ", ";
break;
};
// Set the counter for the number of fields that will be inserted.
$fieldInsertedCount++;
// Get the name of the fields to insert
$fields .= $field->name . ", ";
$mt = $rs->MetaType($field->type);
// "mike" <[email protected]> patch and "Ryan Bailey" <[email protected]>
//PostgreSQL uses a 't' or 'f' and therefore needs to be processed as a string ('C') type field.
if ((strncmp($zthis->databaseType,"postgres",8) === 0) && ($mt == "L")) $mt = "C";
// Based on the datatype of the field
// Format the value properly for the database
if ((defined('ADODB_FORCE_NULLS') && is_null($arrFields[$upperfname])) || $arrFields[$upperfname] === 'null')
$values .= "null, ";
else
switch($mt) {
case "C":
case "X":
case 'B':
$values .= $zthis->qstr($arrFields[$upperfname],$magicq) . ", ";
break;
case "D":
$values .= $zthis->DBDate($arrFields[$upperfname]) . ", ";
break;
case "T":
$values .= $zthis->DBTimeStamp($arrFields[$upperfname]) . ", ";
break;
default:
$val = $arrFields[$upperfname];
if (!is_numeric($val)) $val = (float) $val;
$values .= $val . ", ";
break;
};
};
};
};
// If there were any inserted fields then build the rest of the insert query.
if ($fieldInsertedCount > 0) {
// Get the table name from the existing query.
preg_match("/FROM\s+".ADODB_TABLE_REGEX."/is", $rs->sql, $tableName);
// If there were any inserted fields then build the rest of the insert query.
if ($fieldInsertedCount <= 0) return false;
// Get the table name from the existing query.
preg_match("/FROM\s+".ADODB_TABLE_REGEX."/is", $rs->sql, $tableName);
// Strip off the comma and space on the end of both the fields
// and their values.
$fields = substr($fields, 0, -2);
$values = substr($values, 0, -2);
// Strip off the comma and space on the end of both the fields
// and their values.
$fields = substr($fields, 0, -2);
$values = substr($values, 0, -2);
// Append the fields and their values to the insert query.
$insertSQL = "INSERT INTO " . $tableName[1] . " ( $fields ) VALUES ( $values )";
// Append the fields and their values to the insert query.
$insertSQL = "INSERT INTO " . $tableName[1] . " ( $fields ) VALUES ( $values )";
return $insertSQL;
} else {
return false;
};
return $insertSQL;
}
?>
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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,6 +1,6 @@
<?php
/**
* @version V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
* @version V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
@@ -175,7 +175,7 @@ class DB
if($persist) $ok = $obj->PConnect($dsninfo['hostspec'], $dsninfo['username'],$dsninfo['password'],$dsninfo['database']);
else $ok = $obj->Connect($dsninfo['hostspec'], $dsninfo['username'],$dsninfo['password'],$dsninfo['database']);
if (!$ok) return ADODB_PEAR_Error();
if (!$ok) $obj = ADODB_PEAR_Error();
return $obj;
}
+176 -28
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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,6 +19,7 @@ V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights rese
if (!defined(ADODB_DIR)) include_once(dirname(__FILE__).'/adodb.inc.php');
include_once(ADODB_DIR.'/tohtml.inc.php');
/* return microtime value as a float */
function adodb_microtime()
{
@@ -32,6 +33,7 @@ function& adodb_log_sql(&$conn,$sql,$inputarr)
{
global $HTTP_SERVER_VARS;
$perf_table = adodb_perf::table();
$conn->fnExecute = false;
$t0 = microtime();
$rs =& $conn->Execute($sql,$inputarr);
@@ -58,8 +60,12 @@ global $HTTP_SERVER_VARS;
$tracer = '';
$errM = '';
$errN = 0;
$conn->lastInsID = $conn->Insert_ID();
$dbg = $conn->debug;
$conn->debug = false;
if (!is_object($rs) || $rs->dataProvider == 'empty')
$conn->_affected = $conn->affected_rows(true);
$conn->lastInsID = @$conn->Insert_ID();
$conn->debug = $dbg;
}
if (isset($HTTP_SERVER_VARS['HTTP_HOST'])) {
$tracer .= '<br>'.$HTTP_SERVER_VARS['HTTP_HOST'];
@@ -89,7 +95,7 @@ global $HTTP_SERVER_VARS;
$conn->debug = 0;
if ($conn->dataProvider == 'oci8' && $dbT != 'oci8po') {
$isql = "insert into adodb_logsql values($conn->sysTimeStamp,:b,:c,:d,:e,:f)";
$isql = "insert into $perf_table values($conn->sysTimeStamp,:b,:c,:d,:e,:f)";
} else if ($dbT == 'odbc_mssql' || $dbT == 'informix') {
$timer = $arr['f'];
if ($dbT == 'informix') $sql2 = substr($sql2,0,230);
@@ -99,13 +105,12 @@ global $HTTP_SERVER_VARS;
$params = $conn->qstr($arr['d']);
$tracer = $conn->qstr($arr['e']);
$isql = "insert into adodb_logsql (created,sql0,sql1,params,tracer,timer) values($conn->sysTimeStamp,$sql1,$sql2,$params,$tracer,$timer)";
$isql = "insert into $perf_table (created,sql0,sql1,params,tracer,timer) values($conn->sysTimeStamp,$sql1,$sql2,$params,$tracer,$timer)";
if ($dbT == 'informix') $isql = str_replace(chr(10),' ',$isql);
$arr = false;
} else {
$isql = "insert into adodb_logsql (created,sql0,sql1,params,tracer,timer) values( $conn->sysTimeStamp,?,?,?,?,?)";
$isql = "insert into $perf_table (created,sql0,sql1,params,tracer,timer) values( $conn->sysTimeStamp,?,?,?,?,?)";
}
$conn->_affected = $conn->affected_rows(true);
$ok = $conn->Execute($isql,$arr);
$conn->debug = $saved;
@@ -118,7 +123,7 @@ global $HTTP_SERVER_VARS;
if ($perf) {
if ($perf->CreateLogTable()) $ok = $conn->Execute($isql,$arr);
} else {
$ok = $conn->Execute("create table adodb_logsql (
$ok = $conn->Execute("create table $perf_table (
created varchar(50),
sql0 varchar(250),
sql1 varchar(4000),
@@ -165,7 +170,18 @@ class adodb_perf {
var $explain = true;
var $helpurl = "<a href=http://phplens.com/adodb/reference.functions.fnexecute.and.fncacheexecute.properties.html#logsql>LogSQL help</a>";
var $createTableSQL = false;
var $maxLength = 2000;
// Sets the tablename to be used
function table($newtable = false)
{
static $_table;
if (!empty($newtable)) $_table = $newtable;
if (empty($_table)) $_table = 'adodb_logsql';
return $_table;
}
// returns array with info to calculate CPU Load
function _CPULoad()
{
@@ -285,10 +301,14 @@ Committed_AS: 348732 kB
function Tracer($sql)
{
$perf_table = adodb_perf::table();
$saveE = $this->conn->fnExecute;
$this->conn->fnExecute = false;
$sqlq = $this->conn->qstr($sql);
$arr = $this->conn->GetArray(
"select count(*),tracer
from adodb_logsql where sql1=$sqlq
from $perf_table where sql1=$sqlq
group by tracer
order by 1 desc");
$s = '';
@@ -298,11 +318,17 @@ Committed_AS: 348732 kB
$s .= sprintf("%4d",$k[0]).' &nbsp; '.strip_tags($k[1]).'<br>';
}
}
$this->conn->fnExecute = $saveE;
return $s;
}
function Explain($sql)
{
/*
Explain Plan for $sql.
If only a snippet of the $sql is passed in, then $partial will hold the crc32 of the
actual sql.
*/
function Explain($sql,$partial=false)
{
return false;
}
@@ -314,7 +340,8 @@ Committed_AS: 348732 kB
$s = '<h3>Invalid SQL</h3>';
$saveE = $this->conn->fnExecute;
$this->conn->fnExecute = false;
$rs =& $this->conn->SelectLimit("select distinct count(*),sql1,tracer as error_msg from adodb_logsql where tracer like 'ERROR:%' group by sql1,tracer order by 1 desc",$numsql);//,$numsql);
$perf_table = adodb_perf::table();
$rs =& $this->conn->SelectLimit("select distinct count(*),sql1,tracer as error_msg from $perf_table where tracer like 'ERROR:%' group by sql1,tracer order by 1 desc",$numsql);//,$numsql);
$this->conn->fnExecute = $saveE;
if ($rs) {
$s .= rs2html($rs,false,false,false,false);
@@ -323,6 +350,7 @@ Committed_AS: 348732 kB
return $s;
}
/*
This script identifies the longest running SQL
@@ -331,11 +359,13 @@ Committed_AS: 348732 kB
{
global $ADODB_FETCH_MODE,$HTTP_GET_VARS;
$perf_table = adodb_perf::table();
$saveE = $this->conn->fnExecute;
$this->conn->fnExecute = false;
if (isset($HTTP_GET_VARS['exps']) && isset($HTTP_GET_VARS['sql'])) {
echo "<a name=explain></a>".$this->Explain($HTTP_GET_VARS['sql'])."\n";
$partial = !empty($HTTP_GET_VARS['part']);
echo "<a name=explain></a>".$this->Explain($HTTP_GET_VARS['sql'],$partial)."\n";
}
if (isset($HTTP_GET_VARS['sql'])) return;
@@ -346,7 +376,7 @@ Committed_AS: 348732 kB
//$this->conn->debug=1;
$rs =& $this->conn->SelectLimit(
"select avg(timer) as avg_timer,$sql1,count(*),max(timer) as max_timer,min(timer) as min_timer
from adodb_logsql
from $perf_table
where {$this->conn->upperCase}({$this->conn->substr}(sql0,1,5)) not in ('DROP ','INSER','COMMI','CREAT')
and (tracer is null or tracer not like 'ERROR:%')
group by sql1
@@ -358,14 +388,19 @@ Committed_AS: 348732 kB
$s = "<h3>Suspicious SQL</h3>
<font size=1>The following SQL have high average execution times</font><br>
<table border=1 bgcolor=white><tr><td><b>Avg Time</b><td><b>Count</b><td><b>SQL</b><td><b>Max</b><td><b>Min</b></tr>\n";
$max = $this->maxLength;
while (!$rs->EOF) {
$sql = trim($rs->fields[1]);
$prefix = "<a target=sql".rand()." href=\"?hidem=1&exps=1&sql=".rawurlencode($sql)."&x#explain\">";
$sql = $rs->fields[1];
$raw = urlencode($sql);
if (strlen($raw)>$max-100) {
$sql2 = substr($sql,0,$max-500);
$raw = urlencode($sql2).'&part='.crc32($sql);
}
$prefix = "<a target=sql".rand()." href=\"?hidem=1&exps=1&sql=".$raw."&x#explain\">";
$suffix = "</a>";
if ($this->explain == false || strlen($prefix)>2000) {
if ($this->explain == false || strlen($prefix)>$max) {
$suffix = ' ... <i>String too long for GET parameter: '.strlen($prefix).'</i>';
$prefix = '';
$suffix = '';
}
$s .= "<tr><td>".round($rs->fields[0],6)."<td align=right>".$rs->fields[2]."<td><font size=-1>".$prefix.htmlspecialchars($sql).$suffix."</font>".
"<td>".$rs->fields[3]."<td>".$rs->fields[4]."</tr>";
@@ -401,11 +436,13 @@ Committed_AS: 348732 kB
{
global $HTTP_GET_VARS,$ADODB_FETCH_MODE;
$perf_table = adodb_perf::table();
$saveE = $this->conn->fnExecute;
$this->conn->fnExecute = false;
if (isset($HTTP_GET_VARS['expe']) && isset($HTTP_GET_VARS['sql'])) {
echo "<a name=explain></a>".$this->Explain($HTTP_GET_VARS['sql'])."\n";
$partial = !empty($HTTP_GET_VARS['part']);
echo "<a name=explain></a>".$this->Explain($HTTP_GET_VARS['sql'],$partial)."\n";
}
if (isset($HTTP_GET_VARS['sql'])) return;
@@ -415,7 +452,7 @@ Committed_AS: 348732 kB
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
$rs =& $this->conn->SelectLimit(
"select sum(timer) as total,$sql1,count(*),max(timer) as max_timer,min(timer) as min_timer
from adodb_logsql
from $perf_table
where {$this->conn->upperCase}({$this->conn->substr}(sql0,1,5)) not in ('DROP ','INSER','COMMI','CREAT')
and (tracer is null or tracer not like 'ERROR:%')
group by sql1
@@ -427,12 +464,17 @@ Committed_AS: 348732 kB
$s = "<h3>Expensive SQL</h3>
<font size=1>Tuning the following SQL will reduce the server load substantially</font><br>
<table border=1 bgcolor=white><tr><td><b>Load</b><td><b>Count</b><td><b>SQL</b><td><b>Max</b><td><b>Min</b></tr>\n";
$max = $this->maxLength;
while (!$rs->EOF) {
$sql = $rs->fields[1];
$prefix = "<a target=sqle".rand()." href=\"?hidem=1&expe=1&sql=".rawurlencode($sql)."&x#explain\">";
$raw = urlencode($sql);
if (strlen($raw)>$max-100) {
$sql2 = substr($sql,0,$max-500);
$raw = urlencode($sql2).'&part='.crc32($sql);
}
$prefix = "<a target=sqle".rand()." href=\"?hidem=1&expe=1&sql=".$raw."&x#explain\">";
$suffix = "</a>";
if($this->explain == false || strlen($prefix>2000)) {
if($this->explain == false || strlen($prefix>$max)) {
$prefix = '';
$suffix = '';
}
@@ -529,8 +571,9 @@ Committed_AS: 348732 kB
function UI($pollsecs=5)
{
global $HTTP_GET_VARS,$HTTP_SERVER_VARS;
global $HTTP_GET_VARS,$HTTP_SERVER_VARS,$HTTP_POST_VARS;
$perf_table = adodb_perf::table();
$conn = $this->conn;
$app = $conn->host;
@@ -541,7 +584,7 @@ Committed_AS: 348732 kB
$savelog = $this->conn->LogSQL(false);
$info = $conn->ServerInfo();
if (isset($HTTP_GET_VARS['clearsql'])) {
$this->conn->Execute('delete from adodb_logsql');
$this->conn->Execute('delete from $perf_table');
}
$this->conn->LogSQL($savelog);
@@ -558,6 +601,7 @@ Committed_AS: 348732 kB
if (isset($HTTP_GET_VARS['do'])) $do = $HTTP_GET_VARS['do'];
else if (isset($HTTP_POST_VARS['do'])) $do = $HTTP_POST_VARS['do'];
else if (isset($HTTP_GET_VARS['sql'])) $do = 'viewsql';
else $do = 'stats';
@@ -568,11 +612,14 @@ Committed_AS: 348732 kB
if ($do == 'viewsql') $form = "<td><form># SQL:<input type=hidden value=viewsql name=do> <input type=text size=4 name=nsql value=$nsql><input type=submit value=Go></td></form>";
else $form = "<td>&nbsp;</td>";
$allowsql = !defined('ADODB_PERF_NO_RUN_SQL');
if (empty($HTTP_GET_VARS['hidem']))
echo "<table border=1 width=100% bgcolor=lightyellow><tr><td colspan=2>
<b><a href=http://php.weblogs.com/adodb?perf=1>ADOdb</a> Performance Monitor</b> for $app</tr><tr><td>
<a href=?do=stats>Performance Stats</a> &nbsp; <a href=?do=viewsql>View SQL</a>
&nbsp; <a href=?do=tables>View Tables</a> &nbsp; <a href=?do=poll>Poll Stats</a>",
$allowsql ? ' &nbsp; <a href=?do=dosql>Run SQL</a>' : '',
"$form",
"</tr></table>";
@@ -581,7 +628,7 @@ Committed_AS: 348732 kB
default:
case 'stats':
echo $this->HealthCheck();
$this->conn->debug=1;
echo $this->CheckMemory();
break;
case 'poll':
@@ -592,6 +639,12 @@ Committed_AS: 348732 kB
echo "<pre>";
$this->Poll($pollsecs);
break;
case 'dosql':
if (!$allowsql) break;
$this->DoSQLForm();
break;
case 'viewsql':
if (empty($HTTP_GET_VARS['hidem']))
echo "&nbsp; <a href=\"?do=viewsql&clearsql=1\">Clear SQL Log</a><br>";
@@ -747,9 +800,104 @@ Committed_AS: 348732 kB
$this->conn->LogSQL($savelog);
return ($ok) ? true : false;
}
function DoSQLForm()
{
global $HTTP_SERVER_VARS,$HTTP_GET_VARS,$HTTP_POST_VARS,$HTTP_SESSION_VARS;
$HTTP_VARS = array_merge($HTTP_GET_VARS,$HTTP_POST_VARS);
$PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];
$sql = isset($HTTP_VARS['sql']) ? $HTTP_VARS['sql'] : '';
if (isset($HTTP_SESSION_VARS['phplens_sqlrows'])) $rows = $HTTP_SESSION_VARS['phplens_sqlrows'];
else $rows = 3;
if (isset($HTTP_VARS['SMALLER'])) {
$rows /= 2;
if ($rows < 3) $rows = 3;
$HTTP_SESSION_VARS['phplens_sqlrows'] = $rows;
}
if (isset($HTTP_VARS['BIGGER'])) {
$rows *= 2;
$HTTP_SESSION_VARS['phplens_sqlrows'] = $rows;
}
?>
<form method="POST" action="<?php echo $PHP_SELF ?>">
<table><tr>
<td> Form size: <input type="submit" value=" &lt; " name="SMALLER"><input type="submit" value=" &gt; &gt; " name="BIGGER">
</td>
<td align=right>
<input type="submit" value=" Run SQL Below " name="RUN"><input type=hidden name=do value=dosql>
</td></tr>
<tr>
<td colspan=2><textarea rows=<?php print $rows; ?> name="sql" cols="80"><?php print htmlspecialchars($sql) ?></textarea>
</td>
</tr>
</table>
</form>
<?php
if (!isset($HTTP_VARS['sql'])) return;
$sql = $this->undomq(trim($sql));
if (substr($sql,strlen($sql)-1) === ';') {
$print = true;
$sqla = $this->SplitSQL($sql);
} else {
$print = false;
$sqla = array($sql);
}
foreach($sqla as $sqls) {
if (!$sqls) continue;
if ($print) {
print "<p>".htmlspecialchars($sqls)."</p>";
flush();
}
$savelog = $this->conn->LogSQL(false);
$rs = $this->conn->Execute($sqls);
$this->conn->LogSQL($savelog);
if ($rs && is_object($rs) && !$rs->EOF) {
rs2html($rs);
while ($rs->NextRecordSet()) {
print "<table width=98% bgcolor=#C0C0FF><tr><td>&nbsp;</td></tr></table>";
rs2html($rs);
}
} else {
$e1 = (integer) $this->conn->ErrorNo();
$e2 = $this->conn->ErrorMsg();
if (($e1) || ($e2)) {
if (empty($e1)) $e1 = '-1'; // postgresql fix
print ' &nbsp; '.$e1.': '.$e2;
} else {
print "<p>No Recordset returned<br></p>";
}
}
} // foreach
}
function SplitSQL($sql)
{
$arr = explode(';',$sql);
return $arr;
}
function undomq(&$m)
{
if (get_magic_quotes_gpc()) {
// undo the damage
$m = str_replace('\\\\','\\',$m);
$m = str_replace('\"','"',$m);
$m = str_replace('\\\'','\'',$m);
}
return $m;
}
}
?>
+16
View File
@@ -0,0 +1,16 @@
<?php
/*
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
*/
class ADODB_BASE_RS {
}
?>
+16 -13
View File
@@ -23,7 +23,7 @@ This library replaces native functions as follows:
date() with adodb_date()
gmdate() with adodb_gmdate()
mktime() with adodb_mktime()
gmmktime() with adodb_gmmktime()45
gmmktime() with adodb_gmmktime()
</pre>
The parameters are identical, except that adodb_date() accepts a subset
@@ -56,7 +56,7 @@ adodb_mktime(0,0,0,10,15,1582) - adodb_mktime(0,0,0,10,4,1582)
COPYRIGHT
(c) 2003 John Lim and released under BSD-style license except for code by jackbbs,
which includes adodb_mktime, adodb_get_gmt_different, adodb_is_leap_year
which includes adodb_mktime, adodb_get_gmt_diff, adodb_is_leap_year
and originally found at http://www.php.net/manual/en/function.mktime.php
=============================================================================
@@ -174,6 +174,9 @@ c. Implement daylight savings, which looks awfully complicated, see
CHANGELOG
- 26 Oct 2003 0.11
Because of daylight savings problems (some systems apply daylight savings to
January!!!), changed adodb_get_gmt_diff() to ignore daylight savings.
- 9 Aug 2003 0.10
Fixed bug with dates after 2038.
@@ -231,7 +234,7 @@ First implementation.
/*
Version Number
*/
define('ADODB_DATE_VERSION',0.10);
define('ADODB_DATE_VERSION',0.11);
/*
We check for Windows as only +ve ints are accepted as dates on Windows.
@@ -496,13 +499,13 @@ function adodb_year_digit_check($y)
/**
get local time zone offset from GMT
*/
function adodb_get_gmt_different()
function adodb_get_gmt_diff()
{
static $DIFF;
if (isset($DIFF)) return $DIFF;
static $TZ;
if (isset($TZ)) return $TZ;
$DIFF = mktime(0,0,0,1,2,1970) - gmmktime(0,0,0,1,2,1970);
return $DIFF;
$TZ = mktime(0,0,0,1,2,1970,0) - gmmktime(0,0,0,1,2,1970,0);
return $TZ;
}
/**
@@ -527,7 +530,7 @@ function adodb_getdate($d=false,$fast=false)
*/
function _adodb_getdate($origd=false,$fast=false,$is_gmt=false)
{
$d = $origd - ($is_gmt ? 0 : adodb_get_gmt_different());
$d = $origd - ($is_gmt ? 0 : adodb_get_gmt_diff());
$_day_power = 86400;
$_hour_power = 3600;
@@ -709,7 +712,7 @@ function adodb_date($fmt,$d=false,$is_gmt=false)
if ($secs < 10) $dates .= ':0'.$secs; else $dates .= ':'.$secs;
$gmt = adodb_get_gmt_different();
$gmt = adodb_get_gmt_diff();
$dates .= sprintf(' %s%04d',($gmt<0)?'+':'-',abs($gmt)/36); break;
case 'Y': $dates .= $year; break;
@@ -738,9 +741,9 @@ function adodb_date($fmt,$d=false,$is_gmt=false)
// HOUR
case 'Z':
$dates .= ($is_gmt) ? 0 : -adodb_get_gmt_different(); break;
$dates .= ($is_gmt) ? 0 : -adodb_get_gmt_diff(); break;
case 'O':
$gmt = ($is_gmt) ? 0 : adodb_get_gmt_different();
$gmt = ($is_gmt) ? 0 : adodb_get_gmt_diff();
$dates .= sprintf('%s%04d',($gmt<0)?'+':'-',abs($gmt)/36); break;
case 'H':
@@ -820,7 +823,7 @@ function adodb_mktime($hr,$min,$sec,$mon,$day,$year,$is_dst=false,$is_gmt=false)
return @mktime($hr,$min,$sec,$mon,$day,$year);
}
$gmt_different = ($is_gmt) ? 0 : adodb_get_gmt_different();
$gmt_different = ($is_gmt) ? 0 : adodb_get_gmt_diff();
$hr = intval($hr);
$min = intval($min);
+294 -284
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
/**
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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 -16
View File
@@ -1,7 +1,7 @@
<?php
/**
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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,7 +13,6 @@
class ADODB2_mssql extends ADODB_DataDict {
var $databaseType = 'mssql';
function MetaType($t,$len=-1,$fieldobj=false)
{
if (is_object($t)) {
@@ -69,8 +68,8 @@ class ADODB2_mssql extends ADODB_DataDict {
function AddColumnSQL($tabname, $flds)
{
if ($this->schema) $tabname = $this->schema.'.'.$tabname;
{
$tabname = $this->TableName ($tabname);
$f = array();
list($lines,$pkey) = $this->_GenFields($flds);
$s = "ALTER TABLE $tabname $this->addCol";
@@ -82,9 +81,10 @@ class ADODB2_mssql extends ADODB_DataDict {
return $sql;
}
/*
function AlterColumnSQL($tabname, $flds)
{
if ($this->schema) $tabname = $this->schema.'.'.$tabname;
$tabname = $this->TableName ($tabname);
$sql = array();
list($lines,$pkey) = $this->_GenFields($flds);
foreach($lines as $v) {
@@ -93,13 +93,15 @@ class ADODB2_mssql extends ADODB_DataDict {
return $sql;
}
*/
function DropColumnSQL($tabname, $flds)
{
if ($this->schema) $tabname = $this->schema.'.'.$tabname;
if (!is_array($flds)) $flds = explode(',',$flds);
$tabname = $this->TableName ($tabname);
if (!is_array($flds))
$flds = explode(',',$flds);
$f = array();
$s = "ALTER TABLE $tabname";
$s = 'ALTER TABLE ' . $tabname;
foreach($flds as $v) {
$f[] = "\n$this->dropCol $v";
}
@@ -194,15 +196,29 @@ CREATE TABLE
*/
function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
{
if (isset($idxoptions['REPLACE'])) $sql[] = "DROP INDEX $tabname.$idxname";
if (isset($idxoptions['UNIQUE'])) $unique = ' UNIQUE';
else $unique = '';
if (is_array($flds)) $flds = implode(', ',$flds);
if (isset($idxoptions['CLUSTERED'])) $clustered = ' CLUSTERED';
else $clustered = '';
$sql = array();
$s = "CREATE$unique$clustered INDEX $idxname ON $tabname ($flds)";
if (isset($idxoptions[$this->upperName])) $s .= $idxoptions[$this->upperName];
if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
$sql[] = sprintf ($this->dropIndex, $tabname . '.' . $idxname);
if ( isset($idxoptions['DROP']) )
return $sql;
}
if ( empty ($flds) ) {
return $sql;
}
$unique = isset($idxoptions['UNIQUE']) ? ' UNIQUE' : '';
$clustered = isset($idxoptions['CLUSTERED']) ? ' CLUSTERED' : '';
if ( is_array($flds) )
$flds = implode(', ',$flds);
$s = 'CREATE' . $unique . $clustered . ' INDEX ' . $idxname . ' ON ' . $tabname . ' (' . $flds . ')';
if ( isset($idxoptions[$this->upperName]) )
$s .= $idxoptions[$this->upperName];
$sql[] = $s;
return $sql;
+35 -10
View File
@@ -1,7 +1,7 @@
<?php
/**
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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,7 +13,8 @@
class ADODB2_mysql extends ADODB_DataDict {
var $databaseType = 'mysql';
var $alterCol = ' MODIFY COLUMN';
var $quote = '`';
var $dropIndex = 'DROP INDEX %s ON %s';
function MetaType($t,$len=-1,$fieldobj=false)
{
@@ -84,6 +85,7 @@ class ADODB2_mysql extends ADODB_DataDict {
case 'T': return 'DATETIME';
case 'L': return 'TINYINT';
case 'R':
case 'I': return 'INTEGER';
case 'I1': return 'TINYINT';
case 'I2': return 'SMALLINT';
@@ -130,17 +132,40 @@ class ADODB2_mysql extends ADODB_DataDict {
ON tbl_name (col_name[(length)],... )
*/
function DropIndexSQL ($idxname, $tabname)
{
return array(sprintf($this->dropIndex, $this->NameQuote($idxname), $this->TableName($tabname)));
}
function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
{
//if (isset($idxoptions['REPLACE'])) $sql[] = "DROP INDEX IF EXISTS $idxname";
if (isset($idxoptions['REPLACE'])) $sql[] = "DROP INDEX $idxname ON $tabname";
if (isset($idxoptions['FULLTEXT'])) $unique = ' FULLTEXT';
else if (isset($idxoptions['UNIQUE'])) $unique = ' UNIQUE';
else $unique = '';
$sql = array();
if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
$sql[] = sprintf ($this->dropIndex, $idxname, $tabname);
if ( isset($idxoptions['DROP']) )
return $sql;
}
if ( empty ($flds) ) {
return $sql;
}
if (isset($idxoptions['FULLTEXT'])) {
$unique = ' FULLTEXT';
} elseif (isset($idxoptions['UNIQUE'])) {
$unique = ' UNIQUE';
} else {
$unique = '';
}
if ( is_array($flds) )
$flds = implode(', ',$flds);
$s = 'CREATE' . $unique . ' INDEX ' . $idxname . ' ON ' . $tabname . ' (' . $flds . ')';
if ( isset($idxoptions[$this->upperName]) )
$s .= $idxoptions[$this->upperName];
if (is_array($flds)) $flds = implode(', ',$flds);
$s = "CREATE$unique INDEX $idxname ON $tabname ($flds)";
if (isset($idxoptions[$this->upperName])) $s .= $idxoptions[$this->upperName];
$sql[] = $s;
return $sql;
+28 -9
View File
@@ -1,7 +1,7 @@
<?php
/**
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
@@ -40,7 +40,7 @@ class ADODB2_oci8 extends ADODB_DataDict {
return 'X2';
case 'NCLOB':
case 'CLOB';
case 'CLOB':
return 'XL';
case 'LONG RAW':
@@ -211,18 +211,37 @@ end;
function _IndexSQL($idxname, $tabname, $flds,$idxoptions)
{
if (isset($idxoptions['REPLACE'])) $sql[] = "DROP INDEX $idxname";
$sql = array();
if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
$sql[] = sprintf ($this->dropIndex, $idxname);
if ( isset($idxoptions['DROP']) )
return $sql;
}
if ( empty ($flds) ) {
return $sql;
}
if (isset($idxoptions['BITMAP'])) {
$unique = ' BITMAP';
} else if (isset($idxoptions['UNIQUE']))
} elseif (isset($idxoptions['UNIQUE'])) {
$unique = ' UNIQUE';
else
} else {
$unique = '';
}
if (is_array($flds)) $flds = implode(', ',$flds);
$s = "CREATE$unique INDEX $idxname ON $tabname ($flds)";
if (isset($idxoptions[$this->upperName])) $s .= $idxoptions[$this->upperName];
if (isset($idxoptions['oci8'])) $s .= $idxoptions['oci8'];
if ( is_array($flds) )
$flds = implode(', ',$flds);
$s = 'CREATE' . $unique . ' INDEX ' . $idxname . ' ON ' . $tabname . ' (' . $flds . ')';
if ( isset($idxoptions[$this->upperName]) )
$s .= $idxoptions[$this->upperName];
if (isset($idxoptions['oci8']))
$s .= $idxoptions['oci8'];
$sql[] = $s;
return $sql;
+25 -9
View File
@@ -1,7 +1,7 @@
<?php
/**
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
@@ -181,15 +181,31 @@ CREATE [ UNIQUE ] INDEX index_name ON table
*/
function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
{
if (isset($idxoptions['REPLACE'])) $sql[] = "DROP INDEX $idxname";
if (isset($idxoptions['UNIQUE'])) $unique = ' UNIQUE';
else $unique = '';
$sql = array();
if (is_array($flds)) $flds = implode(', ',$flds);
$s = "CREATE$unique INDEX $idxname ON $tabname ";
if (isset($idxoptions['HASH'])) $s .= 'USING HASH ';
if (isset($idxoptions[$this->upperName])) $s .= $idxoptions[$this->upperName];
$s .= "($flds)";
if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
$sql[] = sprintf ($this->dropIndex, $idxname);
if ( isset($idxoptions['DROP']) )
return $sql;
}
if ( empty ($flds) ) {
return $sql;
}
$unique = isset($idxoptions['UNIQUE']) ? ' UNIQUE' : '';
$s = 'CREATE' . $unique . ' INDEX ' . $idxname . ' ON ' . $tabname . ' ';
if (isset($idxoptions['HASH']))
$s .= 'USING HASH ';
if ( isset($idxoptions[$this->upperName]) )
$s .= $idxoptions[$this->upperName];
if ( is_array($flds) )
$flds = implode(', ',$flds);
$s .= '(' . $flds . ')';
$sql[] = $s;
return $sql;
+26 -13
View File
@@ -1,7 +1,7 @@
<?php
/**
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
@@ -69,8 +69,8 @@ class ADODB2_sybase extends ADODB_DataDict {
function AddColumnSQL($tabname, $flds)
{
if ($this->schema) $tabname = $this->schema.'.'.$tabname;
{
$tabname = $this->TableName ($tabname);
$f = array();
list($lines,$pkey) = $this->_GenFields($flds);
$s = "ALTER TABLE $tabname $this->addCol";
@@ -84,7 +84,7 @@ class ADODB2_sybase extends ADODB_DataDict {
function AlterColumnSQL($tabname, $flds)
{
if ($this->schema) $tabname = $this->schema.'.'.$tabname;
$tabname = $this->TableName ($tabname);
$sql = array();
list($lines,$pkey) = $this->_GenFields($flds);
foreach($lines as $v) {
@@ -96,7 +96,7 @@ class ADODB2_sybase extends ADODB_DataDict {
function DropColumnSQL($tabname, $flds)
{
if ($this->schema) $tabname = $this->schema.'.'.$tabname;
$tabname = $this->TableName ($tabname);
if (!is_array($flds)) $flds = explode(',',$flds);
$f = array();
$s = "ALTER TABLE $tabname";
@@ -194,15 +194,28 @@ CREATE TABLE
*/
function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
{
if (isset($idxoptions['REPLACE'])) $sql[] = "DROP INDEX $tabname.$idxname";
if (isset($idxoptions['UNIQUE'])) $unique = ' UNIQUE';
else $unique = '';
if (is_array($flds)) $flds = implode(', ',$flds);
if (isset($idxoptions['CLUSTERED'])) $clustered = ' CLUSTERED';
else $clustered = '';
$sql = array();
$s = "CREATE$unique$clustered INDEX $idxname ON $tabname ($flds)";
if (isset($idxoptions[$this->upperName])) $s .= $idxoptions[$this->upperName];
if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
$sql[] = sprintf ($this->dropIndex, $tabname . '.' . $idxname);
if ( isset($idxoptions['DROP']) )
return $sql;
}
if ( empty ($flds) ) {
return $sql;
}
$unique = isset($idxoptions['UNIQUE']) ? ' UNIQUE' : '';
$clustered = isset($idxoptions['CLUSTERED']) ? ' CLUSTERED' : '';
if ( is_array($flds) )
$flds = implode(', ',$flds);
$s = 'CREATE' . $unique . $clustered . ' INDEX ' . $idxname . ' ON ' . $tabname . ' (' . $flds . ')';
if ( isset($idxoptions[$this->upperName]) )
$s .= $idxoptions[$this->upperName];
$sql[] = $s;
return $sql;
+342 -75
View File
@@ -11,7 +11,7 @@
<body bgcolor="#FFFFFF">
<h2>ADOdb Library for PHP</h2>
<p>V4.01 23 Oct 2003 (c) 2000-2003 John Lim (jlim#natsoft.com)</p>
<p>V4.11 27 Jan 2004 (c) 2000-2004 John Lim (jlim#natsoft.com)</p>
<p><font size="1">This software is dual licensed using BSD-Style and LGPL. This
means you can use it in compiled proprietary and commercial products.</font></p>
<p>Useful ADOdb links: <a href=http://php.weblogs.com/adodb>Download</a> &nbsp; <a href=http://php.weblogs.com/adodb_manual>Other Docs</a>
@@ -21,12 +21,16 @@
<a href="#users">How People are using ADOdb</a><br>
<a href="#bugs">Feature Requests and Bug Reports</a><br>
</b><b><a href="#install">Installation</a><br>
<a href="#coding">Initializing Code and Connection Examples</a></b><br>
<b><a href="#hack">Hacking ADOdb Safely</a></b><br>
<font size="2"><a href=#adonewconnection>ADONewConnection</a></font>
<a href="#mininstall">Minimum Install</a><br>
<a href="#coding">Initializing Code and Connection Examples</a><br>
<font size="2"><a href=#adonewconnection>ADONewConnection</a></font>
<font size="2"><a href=#adonewconnection>NewADOConnection</a></font><br>
<a href="#speed">High Speed ADOdb - tuning tips</a></b><br>
<b><a href="#hack">Hacking and Modifying ADOdb Safely</a><br>
<a href="#php5">PHP5 Features</a></b><br>
<font size="2"><a href=#php5iterators>foreach iterators</a> <a href=#php5exceptions>exceptions</a></font><br>
<b> <a href="#drivers">Supported Databases</a></b><br>
<b> <a href="#quickstart">Tutorial</a></b><br>
<b> <a href="#quickstart">Tutorials</a></b><br>
<a href="#ex1">Example 1: Select</a><br>
<a href="#ex2">Example 2: Advanced Select</a><br>
<a href="#ex3">Example 3: Insert</a><br>
@@ -45,7 +49,7 @@
<a href="#caching">Caching</a><br>
<a href="#pivot">Pivot Tables</a></b>
<p><a href="#ref"><b>REFERENCE</b></a>
<p> <font size="2">Variables: <a href="#adodb_countrecs">$ADODB_COUNTRECS</a>
<p> <font size="2">Variables: <a href="#adodb_countrecs">$ADODB_COUNTRECS</a> <a href=#adodb_ansi_padding_off>$ADODB_ANSI_PADDING_OFF</a>
<a href="#adodb_cache_dir">$ADODB_CACHE_DIR</a> </font><font size="2"><a href=#adodb_fetch_mode>$ADODB_FETCH_MODE</a>
<a href=#adodb_lang>$ADODB_LANG</a><br>
Constants: </font><font size="2"><a href=#adodb_assoc_case>ADODB_ASSOC_CASE</a>
@@ -56,7 +60,8 @@
Executing SQL: <a href="#execute">Execute</a> <a href="#cacheexecute"><i>CacheExecute</i></a>
<a href="#SelectLimit">SelectLimit</a> <a href="#cacheSelectLimit"><i>CacheSelectLimit</i></a>
<a href="#param">Param</a> <a href="#prepare">Prepare</a> <a href=#preparesp>PrepareSP</a>
<a href="#parameter">Parameter</a><br>
<a href="#inparameter">InParameter</a> <a href="#outparameter">OutParameter</a>
<br>
&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#getone">GetOne</a>
<a href="#cachegetone"><i>CacheGetOne</i></a> <a href="#getrow">GetRow</a> <a href="#cachegetrow"><i>CacheGetRow</i></a>
<a href="#getall">GetAll</a> <a href="#cachegetall"><i>CacheGetAll</i></a> <a href="#getcol">GetCol</a>
@@ -65,9 +70,11 @@
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="#executecursor">ExecuteCursor</a>
(oci8 only)<br>
Generates SQL strings: <a href="#getupdatesql">GetUpdateSQL</a> <a href="#getinsertsql">GetInsertSQL</a>
<a href="#concat">Concat</a> <a href="#ifnull">IfNull</a> <a href="#substr">substr</a> <a href="#qstr"></a><a href="#param">Param</a>
<a href="#concat">Concat</a> <a href="#ifnull">IfNull</a> <a href="#length">length</a> <a href="#random">random</a> <a href="#substr">substr</a>
<a href="#qstr">qstr</a> <a href="#param">Param</a>
<a href="#prepare"></a><a href="#OffsetDate">OffsetDate</a> <a href="#SQLDate">SQLDate</a>
<a href="#dbdate">DBDate</a> <a href="#dbtimestamp"></a> <a href="#dbtimestamp">DBTimeStamp</a><br>
<a href="#dbdate">DBDate</a> <a href="#dbtimestamp"></a> <a href="#dbtimestamp">DBTimeStamp</a>
<br>
Blobs: <a href="#updateblob">UpdateBlob</a> <a href="#updateclob">UpdateClob</a>
<a href="#updateblobfile">UpdateBlobFile</a> <a href="#blobencode">BlobEncode</a>
<a href="#blobdecode">BlobDecode</a><br>
@@ -78,11 +85,11 @@
<a href="#begintrans">BeginTrans</a> <a href="#committrans">CommitTrans</a>
<a href="#rollbacktrans">RollbackTrans</a> <br>
Fetching Data: </font> <font size="2"><a href="#setfetchmode">SetFetchMode</a><br>
Strings: <a href="#concat">concat</a> <a href="#qstr">qstr</a> <a href="#quote">quote</a> <a href="#substr">substr</a><br>
Strings: <a href="#concat">concat</a> <a href="#length">length</a> <a href="#qstr">qstr</a> <a href="#quote">quote</a> <a href="#substr">substr</a><br>
Dates: <a href="#dbdate">DBDate</a> <a href="#dbtimestamp">DBTimeStamp</a> <a href="#unixdate">UnixDate</a>
<a href="#unixtimestamp">UnixTimeStamp</a> <a href="#OffsetDate">OffsetDate</a>
<a href="#SQLDate">SQLDate</a> <br>
Row Management: <a href="#affected_rows">Affected_Rows</a> <a href="#inserted_id">Insert_ID</a>
Row Management: <a href="#affected_rows">Affected_Rows</a> <a href="#inserted_id">Insert_ID</a> <a href=#rowlock>RowLock</a>
<a href="#genid">GenID</a> <a href=#createseq>CreateSequence</a> <a href=#dropseq>DropSequence</a>
<br>
Error Handling: <a href="#errormsg">ErrorMsg</a> <a href="#errorno">ErrorNo</a>
@@ -93,7 +100,8 @@
<a href="#serverinfo">ServerInfo</a> <br>
Statistics and Query-Rewriting: <a href="#logsql">LogSQL</a> <a href="#fnexecute">fnExecute
and fnCacheExecute</a><br>
</font><font size="2">Deprecated: <a href="#bind">Bind</a> <a href="#blankrecordset">BlankRecordSet</a></font><br>
</font><font size="2">Deprecated: <a href="#bind">Bind</a> <a href="#blankrecordset">BlankRecordSet</a>
<a href="#parameter">Parameter</a></font>
<a href="#adorecordSet"><b><br>
ADORecordSet</b></a><br>
<font size="2">
@@ -176,7 +184,7 @@ visit <a href="http://php.weblogs.com/adodb-cool-applications">http://php.weblog
<p>Make sure you are running PHP 4.0.4 or later.
Unpack all the files into a directory accessible by your webserver.</p>
<p>To test, try modifying some of the tutorial examples. Make sure you customize
the connection settings correctly. You can debug using:</p>
the connection settings correctly. You can debug using <i>$db->debug = true</i> as shown below:</p>
<pre>&lt;?php
include('adodb/adodb.inc.php');
$db = <a href="#adonewconnection">ADONewConnection</a>($dbdriver); # eg 'mysql' or 'postgres'
@@ -187,18 +195,32 @@ visit <a href="http://php.weblogs.com/adodb-cool-applications">http://php.weblog
print_r($rs-><a href="#getrows">GetRows</a>());
print &quot;&lt;/pre&gt;&quot;;
?&gt;</pre>
<h3>Code Initialization<a name="coding"></a></h3>
<h3>Minimum Install<a name=mininstall></a></h3>
<p>For developers who want to release a minimal install of ADOdb, you will need:
<ul>
<li>adodb.inc.php
<li>adodb-lib.inc.php
<li>adodb-time.inc.php
<li>adodb-csvlib.inc.php (if you use cached recordsets - CacheExecute(), etc)
<li>adodb-error.inc.php and lang/adodb-$lang.inc.php (if you use MetaError())
<li>drivers/adodb-$database.inc.php
<li>license.txt (for legal reasons)
</ul>
<h3>Code Initialization Examples<a name="coding"></a></h3>
<p>When running ADOdb, at least two files are loaded. First is adodb/adodb.inc.php,
which contains all functions used by all database classes. The code specific
to a particular database is in the adodb/driver/adodb-????.inc.php file.</p>
<a name="adonewconnection">
<p>For example, to connect to a mysql database:</p>
<pre>
include('/path/to/set/here/adodb.inc.php');
$conn = &amp;ADONewConnection('mysql');
</pre>
<p>Whenever you need to connect to a database, you create a Connection object
using the <a name="adonewconnection">ADONewConnection</a>($driver) function.
NewADOConnection($driver) is an alternative name for the same function.</p>
using the <b>ADONewConnection</b></a>($driver) function.
<b>NewADOConnection</b>($driver) is an alternative name for the same function.</p>
<p>At this point, you are not connected to the database. You will first need to decide
whether to use <i>persistent</i> or <i>non-persistent</i> connections. The advantage of <i>persistent</i>
@@ -215,6 +237,7 @@ the creation of a new connection.
PHP will share the same connection. This can cause problems if the connections are meant to
different databases. The solution is to always use different userid's for different databases,
or use NConnect().
<h3>Examples of Connecting to Databases</h3>
<h4>MySQL and Most Other Database Drivers</h4>
<p>MySQL connections are very straightforward, and the parameters are identical
@@ -240,19 +263,24 @@ You define the database in the $host parameter:
$conn = &ADONewConnection('ibase');
$conn->PConnect('localhost:c:\ibase\employee.gdb','sysdba','masterkey');
</pre>
<h4>SQLite</h4>
Sqlite will create database if it does not exist.
<pre>
$conn = &ADONewConnection('sqlite');
$conn->PConnect('c:\path\to\sqlite.db'); # sqlite will create if does not exist
</pre>
<h4>Oracle</h4>
<p>With Oracle, you can connect in multiple ways.</p>
<p>a. PHP and Oracle reside on the same machine, use default SID.</p>
<pre> $conn-&gt;Connect(false, 'scott', 'tiger');</pre>
<p>b. TNS Name defined, eg. 'TNSDB'</p>
<pre> $conn-&gt;PConnect(false, 'scott', 'tiger', TNSDB');
<p>b. TNS Name defined, eg. 'myTNS'</p>
<pre> $conn-&gt;PConnect(false, 'scott', 'tiger', 'myTNS');
</pre>
<p>or</p>
<pre> $conn-&gt;PConnect('TNSDB', 'scott', 'tiger');</pre>
<p>c. Host address and SID</p>
<pre> $conn-&gt;PConnect('myTNS', 'scott', 'tiger');</pre>
<p>c. Host Address and SID</p>
<pre> $conn-&gt;Connect('192.168.0.1', 'scott', 'tiger', 'SID');</pre>
<p>d. Host address and Service Name</p>
<p>d. Host Address and Service Name</p>
<pre> $conn-&gt;Connect('192.168.0.1', 'scott', 'tiger', 'servicename');</pre>
<a name=dsnless></a>
<h4>DSN-less ODBC (access and mssql examples)</h4>
@@ -262,7 +290,7 @@ You define the database in the $host parameter:
<p>For Microsoft Access:</a></p>
<pre>
$db =& ADONewConnection('access');
$dsn = <strong>"Driver=&#123;Microsoft Access Driver (*.mdb)&#125;;Dbq=d:\northwind.mdb;Uid=Admin;Pwd=;";</strong>
$dsn = <strong>"Driver=&#123;Microsoft Access Driver (*.mdb)&#125;;Dbq=d:\\northwind.mdb;Uid=Admin;Pwd=;";</strong>
$db->Connect($dsn);
</pre>
For Microsoft SQL Server:
@@ -278,7 +306,6 @@ using the ADOdb library and Microsoft's ADO:
<pre>
&lt;?php
include('adodb.inc.php');
ADOLoadCode("ado_mssql");
$db = &ADONewConnection("ado_mssql");
print "&lt;h1>Connecting DSN-less $db->databaseType...&lt;/h1>";
@@ -290,10 +317,36 @@ using the ADOdb library and Microsoft's ADO:
$arr = $rs->GetArray();
print_r($arr);
?>
</pre>
<p></p><a name=hack></a>
<h1>Hacking ADOdb Safely</h1>
</pre><a name=speed></a>
<h2>High Speed ADOdb - tuning tips</h2>
<p>ADOdb is a big class library, yet it <a href=http://phplens.com/lens/adodb/>consistently beats</a> all other PHP class
libraries in performance. This is because it is designed in a layered fashion,
like an onion, with the fastest functions in the innermost layer. Stick to the
following functions for best performance:</p>
<table width="40%" border="1" align="center">
<tr>
<td><div align="center"><b>Innermost Layer</b></div></td>
</tr>
<tr>
<td><p align="center">Connect, PConnect, NConnect<br>
Execute, CacheExecute<br>
SelectLimit, SelectLimit<br>
MoveNext, Close <br>
qstr, Affected_Rows, Insert_ID</p></td>
</tr>
</table>
<p>The fastest way to access the fields is by accessing the array $recordset->fields
directly. Also set the global variables <a href="#adodb_fetch_mode">$ADODB_FETCH_MODE</a>
= ADODB_FETCH_NUM, and (for oci8, ibase/firebird and odbc) <a href="#adodb_countrecs">$ADODB_COUNTRECS</a> = false
before you connect to your database. At the time of writing (Dec 2003).</p>
<p>Consider using bind parameters if your database supports it, as it improves
query plan reuse. Use ADOdb's performance tuning system to identify bottlenecks
quickly. At the time of writing (Dec 2003), this means oci8 and odbc drivers.</p>
<p>Lastly make sure you have a PHP accelerator cache installed such as APC, Turck
MMCache, Zend Accelerator or ionCube.</p>
<p>Informix tips: Disable scrollable cursors with $db->cursorType = 0.
<p><a name=hack></a> </p>
<h2>Hacking ADOdb Safely</h2>
<p>You might want to modify ADOdb for your own purposes. Luckily you can
still maintain backward compatibility by sub-classing ADOdb and using the $ADODB_NEWCONNECTION
variable. $ADODB_NEWCONNECTION allows you to override the behaviour of ADONewConnection().
@@ -339,6 +392,35 @@ include_once('adodb.inc.php');
</pre>
<p>Don't forget to call the constructor of the parent class.
<a name="php5">
<h2>PHP5 Features</h2>
ADOdb 4.02 or later will transparently determine which version of PHP you are using.
If PHP5 is detected, the following features become available:
<ul>
<a name="php5iterators">
<li><b>Foreach iterators</b>: This is a very natural way of going through a recordset:
<pre>
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
$rs = $db->Execute($sql);
foreach($rs as $k => $row) {
echo "r1=".$row[0]." r2=".$row[1]."&lt;br>";
}
</pre>
<p>
<a name="php5exceptions">
<li><b>Exceptions</b>: Just include <i>adodb-exceptions.inc.php</i> and you can now
catch exceptions on errors as they occur.
<pre>
<b>include("../adodb-exceptions.inc.php");</b>
include("../adodb.inc.php");
try {
$db = NewADOConnection("oci8");
$db->Connect('','scott','bad-password');
} catch (exception $e) {
var_dump($e);
}
</pre>
</ul>
<h3><a name="drivers"></a>Databases Supported</h3>
<table width="100%" border="1">
<tr valign="top">
@@ -641,7 +723,7 @@ include_once('adodb.inc.php');
</tr>
<p>
</table>
<h3></h3>
<p>The &quot;Tested&quot; column indicates how extensively the code has been tested
and used. <br>
A = well tested and used by many people<br>
@@ -659,7 +741,7 @@ include_once('adodb.inc.php');
is executed, so you can selectively choose which recordsets to count.</p>
<p>
<hr>
<h1>Tutorial<a name="quickstart"></a></h1>
<h1>Tutorials<a name="quickstart"></a></h1>
<h3>Example 1: Select Statement<a name="ex1"></a></h3>
<p>Task: Connect to the Access Northwind DSN, display the first 2 columns of each
row.</p>
@@ -1124,7 +1206,7 @@ include('tohtml.inc.php');
$c = NewADOConnection('mysql');
$c->PConnect('localhost','root','','northwind');
$rs=$c->Execute('select * from productsz'); #invalid table productsz');
if ($rs) $rs2html($rs);
if ($rs) rs2html($rs);
?>
</pre>
<p> If you want to log the error message, you can do so by defining the following
@@ -1145,7 +1227,7 @@ include('tohtml.inc.php');
$c = NewADOConnection('mysql');
$c->PConnect('localhost','root','','northwind');
$rs=$c->Execute('select * from productsz'); ## invalid table productsz
if ($rs) $rs2html($rs);
if ($rs) rs2html($rs);
?>
</pre>
The following message will be logged in the error.log file:
@@ -1164,7 +1246,7 @@ include('tohtml.inc.php');
$c = NewADOConnection('mysql');
$c->PConnect('localhost','root','','northwind');
$rs=$c->Execute('select * from productsz'); #invalid table productsz');
if ($rs) $rs2html($rs);
if ($rs) rs2html($rs);
else &#123;
<b>$e = ADODB_Pear_Error();
echo '&lt;p>',$e->message,'&lt;/p>';</b>
@@ -1237,7 +1319,7 @@ $<font color="#663300">rs</font> = $<font color="#663300">conn</font>->CacheExec
</font> <p><font color="#000000">Since ADOdb 2.30, we support the generation of
SQL to create pivot tables, also known as cross-tabulations. For further explanation
read this DevShed <a href=http://www.devshed.com/Server_Side/MySQL/MySQLWiz/>Cross-Tabulation
tutorial</a>. We assume that your database supports the SQL case-when expression. </font></p>
tutorial. We assume that your database supports the SQL case-when expression. </font></p>
<font color="#000000">
<p>In this example, we will use the Northwind database from Microsoft. In the
database, we have a products table, and we want to analyze this table by <i>suppliers
@@ -1396,6 +1478,10 @@ tutorial</a>. We assume that your database supports the SQL case-when expression
<p>chown -R apache /path/to/adodb/cache<br>
chgrp -R apache /path/to/adodb/cache </p>
<font color="#000000">
<h3><a name="adodb_ansi_padding_off"></a>$ADODB_ANSI_PADDING_OFF</h3>
<p>Determines whether to right trim CHAR fields (and also VARCHAR for ibase/firebird).
Set to true to trim. Default is false. Currently works for oci8po, ibase and firebird
drivers. Added in ADOdb 4.01.
<h3><font color="#000000"><a name="adodb_lang"></a></font>$ADODB_LANG</h3>
<p>Determines the language used in MetaErrorMsg(). The default is 'en', for English.
To find out what languages are supported, see the files
@@ -1562,7 +1648,7 @@ ADODB_NEVER_PERSIST before you call PConnect.
<p><b>NConnect<a name="nconnect"></a>($host,[$user],[$password],[$database])</b></p>
<p>Always force a new connection. In contrast, PHP sometimes reuses connections
when you use Connect() or PConnect(). Currently works only on mysql (PHP 4.3.0
or later) and oci8-derived drivers. For other drivers, NConnect() works like
or later), postgresql and oci8-derived drivers. For other drivers, NConnect() works like
Connect().
<font color="#000000">
<p><b>Execute<a name="execute"></a>($sql,$inputarr=false)</b></p>
@@ -1587,6 +1673,7 @@ ADODB_NEVER_PERSIST before you call PConnect.
Variable binding speeds the compilation and caching of SQL statements, leading
to higher performance. Currently Oracle, Interbase and ODBC supports variable binding.
Interbase/ODBC style ? binding is emulated in databases that do not support binding.
Note that you do not have to quote strings if you use binding.
<p> Variable binding in the odbc, interbase and oci8po drivers.
<pre>
$rs = $db->Execute('select * from table where val=?', array('10'));
@@ -1654,7 +1741,7 @@ only with SELECT statements.
# $rs is now just like any other ADOdb recordset object<br> rs2html($rs);</pre>
<p>ExecuteCursor() is a helper function that does the following internally:
<pre>
$stmt = $db->Prepare("BEGIN :RS := SP_FOO(); END;");
$stmt = $db->Prepare("BEGIN :RS := SP_FOO(); END;", true);
$db->Parameter($stmt, $cur, 'RS', false, -1, OCI_B_CURSOR);
$rs = $db->Execute($stmt);</pre>
<p><b>SelectLimit<a name="selectlimit"></a>($sql,$numrows=-1,$offset=-1,$inputarr=false)</b></p>
@@ -2048,7 +2135,7 @@ convention.
for ($i=0; $i &lt; $max; $i++)<br></font> $DB-&gt;<font color="#000000">Execute($stmt,array((string) rand(), $i));
</font></pre>
<font color="#000000">
<p>Also see PrepareSP() and Parameter() below. Only supported internally by interbase,
<p>Also see InParameter(), OutParameter() and PrepareSP() below. Only supported internally by interbase,
oci8 and selected ODBC-based drivers, otherwise it is emulated. There is no
performance advantage to using Prepare() with emulation.
<p> Important: Due to limitations or bugs in PHP, if you are getting errors when
@@ -2059,6 +2146,19 @@ for ($i=0; $i &lt; $max; $i++)<br></font> $DB-&gt;<font color="#000000">Execute(
the function that checks whether a $field is null for the given database, and
if null, change the value returned to $nullReplacementValue. Eg.</p>
<pre>$sql = <font color="#993300">'SELECT '</font>.$db-&gt;IfNull('name', <font color="#993300">&quot;'- unknown -'&quot;</font>).<font color="#993300"> ' FROM table'</font>;</pre>
<p><b>length<a name="length"></a></b></p>
<p>This is not a function, but a property. Some databases have "length" and others "len"
as the function to measure the length of a string. To use this property:
<pre>
$sql = <font color="#993300">"SELECT "</font>.$db->length.<font color="#993300">"(field) from table"</font>;
$rs = $db->Execute($sql);
</pre>
<p><b>random<a name="random"></a></b></p>
<p>This is not a function, but a property. This is a string that holds the sql to
generate a random number between 0.0 and 1.0 inclusive.
<p><b>substr<a name="substr"></a></b></p>
<p>This is not a function, but a property. Some databases have "substr" and others "substring"
as the function to retrieve a sub-string. To use this property:
@@ -2068,6 +2168,8 @@ as the function to retrieve a sub-string. To use this property:
</pre>
<p>For all databases, the 1st parameter of <i>substr</i> is the field, the 2nd is the
offset (1-based) to the beginning of the sub-string, and the 3rd is the length of the sub-string.
<p><b>Param<a name="param"></a>($name )</b></p>
<p>Generates a bind placeholder portably. For most databases, the bind placeholder
is "?". However some databases use named bind parameters such as Oracle, eg
@@ -2086,12 +2188,72 @@ $stmt = $DB-&gt;Execute($stmt,array('one','two'));
PrepareSP() allows you to do so.
<p>Returns the same array or $sql string as Prepare( ) above. If you do not need
to bind to return values, you should use Prepare( ) instead.</p>
<p>For examples of usage of PrepareSP( ), see Parameter( ) below.
<p>For examples of usage of PrepareSP( ), see InParameter( ) below.
<p>Note: in the mssql driver, preparing stored procedures requires a special function
call, mssql_init( ), which is called by this function. PrepareSP( ) is available
in all other drivers, and is emulated by calling Prepare( ). </p>
<p><b> InParameter<a name="inparameter"></a>($stmt, $var, $name,
$maxLen = 4000, $type = false )</b></p>
Binds a PHP variable as input to a stored procedure variable. The parameter <i>$stmt</i>
is the value returned by PrepareSP(), <i>$var</i> is the PHP variable you want to bind, $name
is the name of the stored procedure variable. Optional is <i>$maxLen</i>, the maximum length of the
data to bind, and $type which is database dependant.
Consult <a href=http://php.net/mssql_bind>mssql_bind</a> and <a href=http://php.net/ocibindbyname>ocibindbyname</a> docs
at php.net for more info on legal values for $type.
<p>
InParameter() is a wrapper function that calls Parameter() with $isOutput=false.
The advantage of this function is that it is self-documenting, because
the $isOutput parameter is no longer needed. Only for mssql
and oci8 currently.
<p>Here is an example using oci8:
<pre><font color="green"># For oracle, Prepare and PrepareSP are identical</font>
$stmt = $db-&gt;PrepareSP(
<font color="#993300">&quot;declare RETVAL integer;
begin
:RETVAL := </font><font color="#993300">SP_RUNSOMETHING</font><font color="#993300">(:myid,:group);
end;&quot;</font>);
$db-&gt;InParameter($stmt,$id,'myid');
$db-&gt;InParameter($stmt,$group,'group',64);
$db-&gt;OutParameter($stmt,$ret,'RETVAL');<br>$db-&gt;Execute($stmt);
</pre>
<p> The same example using mssql:</p>
</font>
<pre><font color="#000000"><font color="green"># @RETVAL = SP_RUNSOMETHING @myid,@group</font>
$stmt = $db-&gt;PrepareSP(<font color="#993333">'<font color="#993300">SP_RUNSOMETHING</font>'</font>); <br><font color="green"># note that the parameter name does not have @ in front!</font>
$db-&gt;InParameter($stmt,$id,'myid');
$db-&gt;InParameter($stmt,$group,'group',64);
<font color="green"># return value in mssql - RETVAL is hard-coded name</font>
$db-&gt;OutParameter($stmt,$ret,'RETVAL');
$db-&gt;Execute($stmt); </font></pre>
<p>Note that the only difference between the oci8 and mssql implementations is $sql.</p>
<p>
If $type parameter is set to false, in mssql, $type will be dynamicly determined
based on the type of the PHP variable passed <font face="Courier New, Courier, mono">(string
=&gt; SQLCHAR, boolean =&gt;SQLINT1, integer =&gt;SQLINT4 or float/double=&gt;SQLFLT8)</font>.
<p>
In oci8, $type can be set to OCI_B_FILE (Binary-File), OCI_B_CFILE (Character-File),
OCI_B_CLOB (Character-LOB), OCI_B_BLOB (Binary-LOB) and OCI_B_ROWID (ROWID). To
pass in a null, use<font face="Courier New, Courier, mono"> $db-&gt;Parameter($stmt,
$null=null, 'param')</font>.
<p><b> OutParameter<a name="outparameter"></a>($stmt, $var, $name,
$maxLen = 4000, $type = false )</b></p>
Binds a PHP variable as output from a stored procedure variable. The parameter <i>$stmt</i>
is the value returned by PrepareSP(), <i>$var</i> is the PHP variable you want to bind, <i>$name</i>
is the name of the stored procedure variable. Optional is <i>$maxLen</i>, the maximum length of the
data to bind, and <i>$type</i> which is database dependant.
<p>
OutParameter() is a wrapper function that calls Parameter() with $isOutput=true.
The advantage of this function is that it is self-documenting, because
the $isOutput parameter is no longer needed. Only for mssql
and oci8 currently.
<p>
For an example, see <a href=#inparameter>InParameter</a>.
<p><b> Parameter<a name="parameter"></a>($stmt, $var, $name, $isOutput=false,
$maxLen = 4000, $type = false )</b></p>
<p>Note: This function is deprecated, because of the new InParameter() and OutParameter() functions.
These are superior because they are self-documenting, unlike Parameter().
<p>Adds a bind parameter suitable for return values or special data handling (eg.
LOBs) after a statement has been prepared using PrepareSP(). Only for mssql
and oci8 currently. The parameters are:<br>
@@ -2105,25 +2267,6 @@ $stmt = $DB-&gt;Execute($stmt,array('one','two'));
[$<b>type</b>] Consult <a href="http://php.net/mssql_bind">mssql_bind</a> and
<a href="http://php.net/ocibindbyname">ocibindbyname</a> docs at php.net for
more info on legal values for type.</p>
<p> Example:</p>
</font>
<pre><font color="#000000"><font color="green"># @RETVAL = SP_RUNSOMETHING @myid,@group</font><br>$stmt = $db-&gt;PrepareSP(<font color="#993333">'<font color="#993300">SP_RUNSOMETHING</font>'</font>); <br><font color="green"># note that the parameter name does not have @ in front!</font><br>$db-&gt;Parameter($stmt,$id,'myid'); <br>$db-&gt;Parameter($stmt,$group,'group',false,64);<br><font color="green"># return value in mssql - RETVAL is hard-coded name</font> <br>$db-&gt;Parameter($stmt,$ret,'RETVAL',true); <br>$db-&gt;Execute($stmt); </font></pre>
<p><font color="#000000">An oci8 example: </font></p>
<font color="#000000">
<pre><font color="green"># For oracle, Prepare and PrepareSP are identical</font>
$stmt = $db-&gt;PrepareSP(
<font color="#993300">&quot;declare RETVAL integer; <br> begin <br> :RETVAL := </font><font color="#993300">SP_RUNSOMETHING</font><font color="#993300">(:myid,:group); <br> end;&quot;</font>);<br>$db-&gt;Parameter($stmt,$id,'myid');<br>$db-&gt;Parameter($stmt,$group,'group',false,64);
$db-&gt;Parameter($stmt,$ret,'RETVAL',true);<br>$db-&gt;Execute($stmt);
</pre>
<p>Note that the only difference between the oci8 and mssql implementations is
the syntax of $sql.</p>
If $type parameter is set to false, in mssql, $type will be dynamicly determined
based on the type of the PHP variable passed <font face="Courier New, Courier, mono">(string
=&gt; SQLCHAR, boolean =&gt;SQLINT1, integer =&gt;SQLINT4 or float/double=&gt;SQLFLT8)</font>.
In oci8, $type can be set to OCI_B_FILE (Binary-File), OCI_B_CFILE (Character-File),
OCI_B_CLOB (Character-LOB), OCI_B_BLOB (Binary-LOB) and OCI_B_ROWID (ROWID). To
pass in a null, use<font face="Courier New, Courier, mono"> $db-&gt;Parameter($stmt,
$null=null, 'param')</font>.
<p>Lastly, in oci8, bind parameters can be reused without calling PrepareSP( )
or Parameters again. This is not possible with mssql. An oci8 example:</p>
<pre>$id = 0; $i = 0;
@@ -2231,7 +2374,17 @@ Usage:
echo $perf->SuspiciousSQL();
echo $perf->ExpensiveSQL();
</pre>
<p>Also see <a href=docs-perf.htm>Performance Monitor</a>.
<p>One limitation of logging is that rollback also prevents SQL from being logged.
<p>
If you prefer to use another name for the table used to store the SQL, you can override it by calling
adodb_perf::table($tablename), where $tablename is the new table name (you will still need to manually
create the table yourself). An example:
<pre>
include('adodb.inc.php');
include('adodb-perf.inc.php');
adodb_perf::table('my_logsql_table');
</pre>
Also see <a href=docs-perf.htm>Performance Monitor</a>.
<p><font color="#000000"><b>fnExecute and fnCacheExecute properties<a name="fnexecute" id="fnexecute"></a></b></font></p>
<p>These two properties allow you to define bottleneck functions for all sql statements
processed by ADOdb. This allows you to perform statistical analysis and query-rewriting
@@ -2318,8 +2471,18 @@ printf(&quot;&lt;p&gt;Total queries=%d; total cached=%d&lt;/p&gt;&quot;,$EXECS+$
<p>Returns the last autonumbering ID inserted. Returns false if function not supported.
</p>
<p>Only supported by databases that support auto-increment or object id's, such
as PostgreSQL, MySQL and MSSQL currently. PostgreSQL returns the OID, which
as PostgreSQL, MySQL and MS SQL Server currently. PostgreSQL returns the OID, which
can change on a database reload.</p>
<p><b>RowLock<a name="rowlock"></a>($table,$where)</b></p>
<p>Lock a table row for the duration of a transaction. For example to lock record $id in table1:
<pre>
$DB->StartTrans();
$DB->RowLock("table1","rowid=$id");
$DB->Execute($sql1);
$DB->Execute($sql2);
$DB->CompleteTrans();
</pre>
<p>Supported in db2, interbase, informix, mssql, oci8, postgres, sybase.
<p><b>MetaDatabases<a name="metadatabases"></a>()</b></p>
<p>Returns a list of databases available on the server as an array. You have to
connect to the server first. Only available for ODBC, MySQL and ADO.</p>
@@ -2333,10 +2496,15 @@ printf(&quot;&lt;p&gt;Total queries=%d; total cached=%d&lt;/p&gt;&quot;,$EXECS+$
<p>You can define a mask for matching. For example, setting $mask = 'TMP%' will
match all tables that begin with 'TMP'. Currently only mssql, oci8, odbc_mssql
and postgres* support $mask.
<p><b>MetaColumns<a name="metacolumns"></a>($table)</b></p>
<p><b>MetaColumns<a name="metacolumns"></a>($table,$toupper=true)</b></p>
<p>Returns an array of ADOFieldObject's, one field object for every column of
$table. Currently Sybase does not recognise date types, and ADO cannot identify
the correct data type (so we default to varchar).. </p>
$table. A field object is a class instance with (name, type, max_length) defined.
Currently Sybase does not recognise date types, and ADO cannot identify
the correct data type (so we default to varchar).
<p> The $toupper parameter determines whether we uppercase the table name
(required for some databases).
<p>For schema support, pass in the $table parameter, "$schema.$tablename". This is only
supported for selected databases.
<p><b>MetaColumnNames<a name="metacolumnames"></a>($table)</b></p>
<p>Returns an array of column names for $table.
<p><font color="#000000"><b>MetaPrimaryKeys<a name="metaprimarykeys"></a>($table,
@@ -2344,6 +2512,24 @@ printf(&quot;&lt;p&gt;Total queries=%d; total cached=%d&lt;/p&gt;&quot;,$EXECS+$
<p><font color="#000000">Returns an array containing column names that are the
primary keys of $table. Supported by mysql, odbc (including db2, odbc_mssql,
etc), mssql, postgres, interbase/firebird, oci8 currently. </font><font color="#000000">
<p>Views (and some tables) have primary keys, but sometimes this information is not available from the
database. You can define a function ADODB_View_PrimaryKeys($databaseType, $database, $view, $owner) that
should return an array containing the fields that make up the primary key. If that function exists,
it will be called when MetaPrimaryKeys() cannot find a primary key for a table or view.
<pre>
// In this example: dbtype = 'oci8', $db = 'mydb', $view = 'dataView', $owner = false
function ADODB_View_PrimaryKeys($dbtype,$db,$view,$owner)
{
switch(strtoupper($view)) {
case 'DATAVIEW': return array('DATAID');
default: return false;
}
}
$db = NewADOConnection('oci8');
$db->Connect('localhost','root','','mydb');
$db->MetaPrimaryKeys('dataView');
</pre>
<p><font color="#000000"><b>ServerInfo<a name="serverinfo" id="serverinfo"></a>($table)</b></font></font>
<p><font color="#000000">Returns an array of containing two elements 'description'
and 'version'. The 'description' element contains the string description of
@@ -2437,12 +2623,12 @@ for GetArray() for compatibility with Microsoft ADO.
time the selection is based on the 2nd column, which holds the values to return
to the Web server.
<p><b>UserDate<a name="userdate"></a>($str, [$fmt])</b></p>
<p>Converts the date string $<b>str</b> to another format.UserDate calls UnixDate
to parse $<b>str</b>, and $<b>fmt</b> defaults to Y-m-d if not defined.</p>
<p>Converts the date string $<i>str</i> to another format. The date format is Y-m-d,
or Unix timestamp format. The default $<i>fmt</i> is Y-m-d.</p>
<p><b>UserTimeStamp<a name="usertimestamp"></a>($str, [$fmt])</b></p>
<p>Converts the timestamp string $<b>str</b> to another format. The timestamp
format is Y-m-d H:i:s, as in '2002-02-28 23:00:12'. UserTimeStamp calls UnixTimeStamp
to parse $<b>str</b>, and $<b>fmt</b> defaults to Y-m-d H:i:s if not defined.
format is Y-m-d H:i:s, as in '2002-02-28 23:00:12', or Unix timestamp format.
UserTimeStamp calls UnixTimeStamp to parse $<i>str</i>, and $<i>fmt</i> defaults to Y-m-d H:i:s if not defined.
</p>
<p><b>UnixDate<a name="unixdate"></a>($str)</b></p>
<p>Parses the date string $<b>str</b> and returns it in unix mktime format (eg.
@@ -2454,8 +2640,8 @@ for GetArray() for compatibility with Microsoft ADO.
<p><b>UnixTimeStamp<a name="unixtimestamp"></a>($str)</b></p>
<p>Parses the timestamp string $<b>str</b> and returns it in unix mktime format
(eg. a number indicating the seconds after January 1st, 1970). Expects the date
to be in Y-m-d H:i:s format, except for Sybase and Microsoft SQL Server, where
M d Y h:i:sA is also accepted (the 3 letter month strings are controlled by
to be in "Y-m-d, H:i:s" (1970-12-24, 00:00:00) or "Y-m-d H:i:s" (1970-12-24 00:00:00) or "YmdHis" (19701225000000) format, except for Sybase and Microsoft SQL Server, where
"M d Y h:i:sA" (Dec 25 1970 00:00:00AM) is also accepted (the 3 letter month strings are controlled by
a global array, which might need localisation).</p>
</font>
<p><font color="#000000">This function is available in both ADORecordSet and ADOConnection
@@ -2669,7 +2855,12 @@ For example, $db-&gt;MetaType('char') will return 'C'.
parameter, instead of $nativeDBType. </font></p>
<font color="#000000">
<p><b>Close( )<a name="rsclose"></a></b></p>
<p>Close the recordset.</p>
<p>Closes the recordset, cleaning all memory and resources associated with the recordset.
<p>
If memory management is not an issue, you do not need to call this function as recordsets
are closed for you by PHP at the end of the script.
SQL statements such as INSERT/UPDATE/DELETE do not really return a recordset, so you do not have to call Close()
for such SQL statements.</p>
<hr>
<h3>function rs2html<a name="rs2html"></a>($adorecordset,[$tableheader_attributes],
[$col_titles])</h3>
@@ -2778,17 +2969,93 @@ $<font color="#663300">rs</font> = $<font color="#663300">conn</font>->Execute
<p>See the <a href=http://php.weblogs.com/adodb-todo-roadmap>RoadMap</a> article.</p>
<p>Also see the ADOdb <a href=http://php.weblogs.com/adodb_csv>proxy</a> article
for bridging Windows and Unix databases using http remote procedure calls. For
your education, visit <a href=http://palslib.com/>palslib.com for database info,
your education, visit <a href=http://palslib.com/>palslib.com</a> for database info,
and read this article on <a href=http://phplens.com/lens/php-book/optimizing-debugging-php.php>Optimizing
PHP</a>. </p>
</font>
<h2>Change Log<a name="Changes"></a><a name="changelog"></a></h2>
</font>
<h2>Change Log<a name="Changes"></a><a name="changes"></a><a name="changelog"></a></h2>
<p><b>4.11 27 Jan 2004</b>
<p>Table misspelt in perf-oci8.inc.php. Changed v$conn_cache_advice to v$db_cache_advice. Reported by Steve W.
<p>UserTimeStamp and DBTimeStamp did not handle YYYYMMDDHHMMSS format properly. Reported by Mike Muir. Fixed.
<p>Changed oci8 Prepare(). Does not auto-allocate OCINewCursor automatically, unless 2nd param is set to true.
This will break backward compat, if Prepare/Execute is used instead of ExecuteCursor. Reported by Chris Jones.
<p>Added InParameter() and OutParameter(). Wrapper functions to Parameter(), but nicer because they
are self-documenting.
<p>Added 'R' handling in ActualType() to datadict-mysql.inc.php
<p>Added ADOConnection::SerializableRS($rs). Returns a recordset that can be serialized in a session.
<p>Added "Run SQL" to performance UI().
<p>Misc spelling corrections in adodb-mysqli.inc.php, adodb-oci8.inc.php and datadict-oci8.inc.php, from Heinz Hombergs.
<p>MetaIndexes() for ibase contributed by Heinz Hombergs.
<p><b>4.10 12 Jan 2004</b>
<p>Dan Cech contributed extensive changes to data dictionary to support name quoting (with `), and drop table/index.
<p>Informix added cursorType property. Default remains IFX_SCROLL, but you can change to 0 (non-scrollable cursor) for performance.
<p>Added ADODB_View_PrimaryKeys() for returning view primary keys to MetaPrimaryKeys().
<p>Simplified chinese file, adodb-cn.inc.php from cysoft.
<p>Added check for ctype_alnum in adodb-datadict.inc.php. Thx to Jason Judge.
<p>Added connection parameter to ibase Prepare(). Fix by Daniel Hassan.
<p>Added nameQuote for quoting identifiers and names to connection obj. Requested by Jason Judge. Also the
data dictionary parser now detects `field name` and generates column names with spaces correctly.
<p>BOOL type not recognised correctly as L. Fixed.
<p>Fixed paths in ADODB_DIR for session files, and back-ported it to 4.05 (15 Dec 2003)
<p>Added Schema to postgresql MetaTables. Thx to col#gear.hu
<p>Empty postgresql recordsets that had blob fields did not set EOF properly. Fixed.
<p>CacheSelectLimit internal parameters to SelectLimit were wrong. Thx to Nio.
<p>Modified adodb_pr() and adodb_backtrace() to support command-line usage (eg. no html).
<p>Fixed some fr and it lang errors. Thx to Gaetano G.
<p>Added contrib directory, with adodb rs to xmlrpc convertor by Gaetano G.
<p>Fixed array recordset bugs when _skiprow1 is true. Thx to Gaetano G.
<p>Fixed pivot table code when count is false.
<p>
<p><b>4.05 13 Dec 2003 </b>
<p>Added MetaIndexes - thx to Dan Cech.
<p>Rewritten session code by Ross Smith. Moved code to adodb/session directory.
<p>Added function exists check on connecting to most drivers, so we don't crash with the unknown function error.
<p>Smart Transactions failed with GenID() when it no seq table has been created because the sql
statement fails. Fix by Mark Newnham.
<p>Added $db->length, which holds name of function that returns strlen.
<p>Fixed error handling for bad driver in ADONewConnection - passed too few params to error-handler.
<p>Datadict did not handle types like 16.0 properly in _GetSize. Fixed.
<p>Oci8 driver SelectLimit() bug &= instead of =& used. Thx to Swen Thümmler.
<p>Jesse Mullan suggested not flushing outp when output buffering enabled. Due to Apache 2.0 bug. Added.
<p>MetaTables/MetaColumns return ref bug with PHP5 fixed in adodb-datadict.inc.php.
<p>New mysqli driver contributed by Arjen de Rijke. Based on adodb 3.40 driver.
Then jlim added BeginTrans, CommitTrans, RollbackTrans, IfNull, SQLDate. Also fixed return ref bug.
<p>$ADODB_FLUSH added, if true then force flush in debugging outp. Default is false. In earlier
versions, outp defaulted to flush, which is not compat with apache 2.0.
<p>Mysql driver's GenID() function did not work when when sql logging is on. Fixed.
<p>$ADODB_SESSION_TBL not declared as global var. Not available if adodb-session.inc.php included in function. Fixed.
<p>The input array not passed to Execute() in _adodb_getcount(). Fixed.
<p><b>4.04 13 Nov 2003 </b>
<p>Switched back to foreach - faster than list-each.
<p>Fixed bug in ado driver - wiping out $this->fields with date fields.
<p>Performance Monitor, View SQL, Explain Plan did not work if strlen($SQL)>max($_GET length). Fixed.
<p>Performance monitor, oci8 driver added memory sort ratio.
<p>Added random property, returns SQL to generate a floating point number between 0 and 1;
<p><b>4.03 6 Nov 2003 </b>
<p>The path to adodb-php4.inc.php and adodb-iterators.inc.php was not setup properly.
<p>Patched SQLDate in interbase to support hours/mins/secs. Thx to ari kuorikoski.
<p>Force autorollback for pgsql persistent connections -
apparently pgsql did not autorollback properly before 4.3.4. See http://bugs.php.net/bug.php?id=25404
<p><b>4.02 5 Nov 2003 </b>
<p>Some errors in adodb_error_pg() fixed. Thx to Styve.
<p>Spurious Insert_ID() error was generated by LogSQL(). Fixed.
<p>Insert_ID was interfering with Affected_Rows() and Replace() when LogSQL() enabled. Fixed.
<p>More foreach loops optimized with list/each.
<p>Null dates not handled properly in ADO driver (it becomes 31 Dec 1969!).
<p>Heinz Hombergs contributed patches for mysql MetaColumns - adding scale, made
interbase MetaColumns work with firebird/interbase, and added lang/adodb-de.inc.php.
<p>Added INFORMIXSERVER environment variable.
<p>Added $ADODB_ANSI_PADDING_OFF for interbase/firebird.
<p>PHP 5 beta 2 compat check. Foreach (Iterator) support. Exceptions support.
<p><b>4.01 23 Oct 2003 </b>
<p>Informix ErrorNo() fixed.
<p>Modified PostgreSQL _fixblobs to use list/each instead of foreach.
<p>Modified several places to use list/each, including GetRowAssoc().
<p>Fixed bug in rs2html(), tohtml.inc.php, that generated blank table cells.
<p>Fixed insert_id() incorrectly generated when logsql() enabled.
<p>Modified PostgreSQL _fixblobs to use list/each instead of foreach.
<p>Informix ErrorNo() implemented correctly.
<p>Modified several places to use list/each, including GetRowAssoc().
<p>Added UserTimeStamp() to connection class.
<p>Added $ADODB_ANSI_PADDING_OFF for oci8po.
<p><b>4.00 20 Oct 2003 </b>
<p>Upgraded adodb-xmlschema to 1 Oct 2003 snapshot.
<p>Fix to rs2html warning message. Thx to Filo.
+29 -23
View File
@@ -11,7 +11,7 @@
<body bgcolor="#FFFFFF">
<h2>ADOdb Data Dictionary Library for PHP</h2>
<p> V4.01 23 Oct 2003 (c) 2000-2003 John Lim (<a href="mailto:jlim#natsoft.com.my">jlim#natsoft.com.my</a>)</p>
<p> V4.11 27 Jan 2004 (c) 2000-2004 John Lim (<a href="mailto:jlim#natsoft.com.my">jlim#natsoft.com.my</a>)</p>
<p><font size=1>This software is dual licensed using BSD-Style and LGPL. This
means you can use it in compiled proprietary and commercial products.</font></p>
<p>Useful ADOdb links: <a href=http://php.weblogs.com/adodb?dd=1>Download</a> &nbsp; <a href=http://php.weblogs.com/adodb_manual?dd=1>Other Docs</a>
@@ -65,9 +65,10 @@ $dict-><strong>ExecuteSQLArray</strong>($sqlarray);
<p> The older (and still supported) format of $fldarray is a 2-dimensional array, where each row in the
1st dimension represents one field. Each row has this format:
<pre> array($fieldname, $type, [,$colsize] [,$otheroptions]*)</pre>
The first 2 fields must be the field name and the field type. The field type
can be a portable type codes or the actual type for that database.
<p>
<p>The first 2 fields must be the field name and the field type. The field type
can be a portable type codes or the actual type for that database.</p>
<p>
Legal portable type codes include:
<pre>
C: varchar
@@ -97,40 +98,41 @@ N: Numeric or decimal number
<p>
The $otheroptions include the following keywords (case-insensitive):
<pre>
AUTO For autoincrement number. Emulated with triggers if not available.
AUTO For autoincrement number. Emulated with triggers if not available.
Sets NOTNULL also.
AUTOINCREMENT Same as auto.
KEY Primary key field. Sets NOTNULL also. Compound keys are supported.
AUTOINCREMENT Same as auto.
KEY Primary key field. Sets NOTNULL also. Compound keys are supported.
PRIMARY Same as KEY.
DEF Synonym for DEFAULT for lazy typists.
DEFAULT The default value. Character strings are auto-quoted unless
the string begins and ends with spaces, eg ' SYSDATE '.
NOTNULL If field is not null.
DEFDATE Set default value to call function to get today's date.
DEFTIMESTAMP Set default to call function to get today's datetime.
NOQUOTE Prevents autoquoting of default string values.
CONSTRAINTS Additional constraints defined at the end of the field
definition.
DEF Synonym for DEFAULT for lazy typists.
DEFAULT The default value. Character strings are auto-quoted unless
the string begins and ends with spaces, eg ' SYSDATE '.
NOTNULL If field is not null.
DEFDATE Set default value to call function to get today's date.
DEFTIMESTAMP Set default to call function to get today's datetime.
NOQUOTE Prevents autoquoting of default string values.
CONSTRAINTS Additional constraints defined at the end of the field
definition.
</pre>
<p> The Data Dictonary accepts two formats, the older array specification: </p>
<pre>
$flds = array(
array('COLNAME', 'DECIMAL', '8.4', 'DEFAULT' => 0, 'NotNull'),
array('ID', 'I' , 'AUTO'),
array('MYDATE', 'D' , 'DEFDATE'),
array('NAME', 'C' ,'32',
array('COLNAME', 'DECIMAL', '8.4', 'DEFAULT' => 0, 'NotNull'),
array('id', 'I' , 'AUTO'),
array('`MY DATE`', 'D' , 'DEFDATE'),
array('NAME', 'C' , '32',
'CONSTRAINTS' => 'FOREIGN KEY REFERENCES reftable')
); </pre>
Or the simpler declarative format:
<pre> $flds = "
<font color="#660000"><strong> COLNAME DECIMAL(8.4) DEFAULT 0 NotNull,
ID I AUTO,
MYDATE D DEFDATE,
id I AUTO,
`MY DATE` D DEFDATE,
NAME C(32) CONSTRAINTS 'FOREIGN KEY REFERENCES reftable' </strong></font>
";
</pre>
<p>
The $taboptarray is the 3rd parameter of the CreateTableSQL function.
Note that if you have special characters in the field name (e.g. My Date), you should enclose it in back-quotes. Normally field names are not case-sensitive, but if you enclose it in back-quotes, some databases treat the names as case-sensitive, and some don't. So be careful.
<p>The $taboptarray is the 3rd parameter of the CreateTableSQL function.
This contains table specific settings. Legal keywords include:
<ul>
@@ -138,6 +140,9 @@ Or the simpler declarative format:
Indicates that the previous table definition should be removed (dropped)together
with ALL data. See first example below.<br>
</li>
<li>DROP <br>
Drop table. Useful for removing unused tables.<br>
</li>
<li>CONSTRAINTS <br>
Define this as the key, with the constraint as the value. See the postgresql
example below. Additional constraints defined for the whole table. You
@@ -177,6 +182,7 @@ Or the simpler declarative format:
UNIQUE Make unique index
FULLTEXT Make fulltext index (only mysql)
HASH Create hash index (only postgres)
DROP Drop legacy index
</pre>
<p> <strong>function AddColumnSQL($tabname, $flds)</strong>
<p>Add one or more columns. Not guaranteed to work under all situations.
+1 -1
View File
@@ -7,7 +7,7 @@
<body>
<h3>The ADOdb Performance Monitoring Library</h3>
<p>V4.01 23 Oct 2003 (c) 2000-2003 John Lim (jlim#natsoft.com.my)</p>
<p>V4.11 27 Jan 2004 (c) 2000-2004 John Lim (jlim#natsoft.com.my)</p>
<p><font size="1">This software is dual licensed using BSD-Style and LGPL. This
means you can use it in compiled proprietary and commercial products.</font></p>
<p>Useful ADOdb links: <a href=http://php.weblogs.com/adodb?perf=1>Download</a> &nbsp; <a href=http://php.weblogs.com/adodb_manual?perf=1>Other Docs</a>
+152 -98
View File
@@ -3,22 +3,23 @@
<title>ADODB Session Management Manual</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<XSTYLE
body,td {font-family:Arial,Helvetica,sans-serif;font-size:11pt}
pre {font-size:9pt}
.toplink {font-size:8pt}
/>
</head>
body,td {font-family:Arial,Helvetica,sans-serif;font-size:11pt}
pre {font-size:9pt}
.toplink {font-size:8pt}
/>
</head>
<body bgcolor="#FFFFFF">
<h3>ADODB Session Management Manual</h3>
<p>
V4.01 23 Oct 2003 (c) 2000-2003 John Lim (jlim#natsoft.com.my)
V4.11 27 Jan 2004 (c) 2000-2004 John Lim (jlim#natsoft.com.my)
<p> <font size=1>This software is dual licensed using BSD-Style and LGPL. This
means you can use it in compiled proprietary and commercial products. </font>
<p>Useful ADOdb links: <a href=http://php.weblogs.com/adodb>Download</a> &nbsp; <a href=http://php.weblogs.com/adodb_manual>Other Docs</a>
<h3>Introduction</h3>
<p>PHP is packed with good features. One of the most popular is session variables.
These are variables that persist throughout a session, as the user moves from page to page. Session variables are great holders of state information and other useful stuff.
<p>
We store state information specific to a user or web client in session variables. These session variables
persist throughout a session, as the user moves from page to page.
<p>
To use session variables, call session_start() at the beginning of your web page,
before your HTTP headers are sent. Then for every variable you want to keep alive
@@ -35,13 +36,15 @@ the session handler will keep track of the session by using a cookie. You can sa
<p>Then the ADOdb session handler provides you with the above additional capabilities
by storing the session information as records in a database table that can be
shared across multiple servers.
<p><b>Important Upgrade Notice:</b> Since ADOdb 4.05, the session files have been moved to its own folder, adodb/session. This is a rewrite
of the session code by Ross Smith. The old session code is in adodb/session/old.
<h4>ADOdb Session Handler Features</h4>
<ul>
<li>Ability to define a notification function that is called when a session expires. Typically
used to detect session logout and release global resources.
<li>Optimization of database writes. We crc32 the session data and only perform an update
to the session data if there is a data change.
<li>Support for large amounts of session data with CLOBs (see adodb-session-clob.inc.php). Useful
<li>Support for large amounts of session data with CLOBs (see adodb-session-clob.php). Useful
for Oracle.
<li>Support for encrypted session data, see adodb-cryptsession.inc.php. Enabling encryption
is simply a matter of including adodb-cryptsession.inc.php instead of adodb-session.inc.php.
@@ -49,110 +52,161 @@ is simply a matter of including adodb-cryptsession.inc.php instead of adodb-sess
<h3>Setup</h3>
<p>There are 3 session management files that you can use:
<pre>
adodb-session.inc.php : The default
adodb-session-clob.inc.php : Use this if you are storing DATA in clobs
adodb-cryptsession.inc.php : Use this if you want to store encrypted session data in the database
adodb-session.php : The default
adodb-session-clob.php : Use this if you are storing DATA in clobs
adodb-cryptsession.php : Use this if you want to store encrypted session data in the database
<strong>Examples</strong>
GLOBAL $HTTP_SESSION_VARS;
include('adodb.inc.php');
include('adodb-session.php');
session_start();
session_register('AVAR');
$HTTP_SESSION_VARS['AVAR'] += 1;
print "<p>\$HTTP_SESSION_VARS['AVAR']={$HTTP_SESSION_VARS['AVAR']}</p>";
<font color=#004040>
include('adodb/adodb.inc.php');
<b> $ADODB_SESSION_DRIVER='mysql';
$ADODB_SESSION_CONNECT='localhost';
$ADODB_SESSION_USER ='scott';
$ADODB_SESSION_PWD ='tiger';
$ADODB_SESSION_DB ='sessiondb';</b>
<b>include('adodb/session/adodb-session.php');</b>
session_start();
#
# Test session vars, the following should increment on refresh
#
$_SESSION['AVAR'] += 1;
print "&lt;p>\$_SESSION['AVAR']={$_SESSION['AVAR']}&lt;/p>";
</font>
To force non-persistent connections, call adodb_session_open first before session_start():
GLOBAL $HTTP_SESSION_VARS;
include('adodb.inc.php');
include('adodb-session.php');
adodb_sess_open(false,false,false);
session_start();
session_register('AVAR');
$HTTP_SESSION_VARS['AVAR'] += 1;
print "<p>\$HTTP_SESSION_VARS['AVAR']={$HTTP_SESSION_VARS['AVAR']}</p>";
<font color=#004040>
include('adodb/adodb.inc.php');
<b> $ADODB_SESSION_DRIVER='mysql';
$ADODB_SESSION_CONNECT='localhost';
$ADODB_SESSION_USER ='scott';
$ADODB_SESSION_PWD ='tiger';
$ADODB_SESSION_DB ='sessiondb';</b>
<b>include('adodb/session/adodb-session.php');
adodb_sess_open(false,false,false);</b>
session_start();
</font color=#004040>
To use a encrypted sessions, simply replace the file:
GLOBAL $HTTP_SESSION_VARS;
include('adodb.inc.php');
include('adodb-cryptsession.php');
session_start();
And the same technique for adodb-session-clob.inc.php:
GLOBAL $HTTP_SESSION_VARS;
include('adodb.inc.php');
include('adodb-session-clob.php');
session_start();
<font color=#004040>
include('adodb/adodb.inc.php');
<b> $ADODB_SESSION_DRIVER='mysql';
$ADODB_SESSION_CONNECT='localhost';
$ADODB_SESSION_USER ='scott';
$ADODB_SESSION_PWD ='tiger';
$ADODB_SESSION_DB ='sessiondb';
include('adodb/session/adodb-cryptsession.php');</b>
session_start();
</font>
And the same technique for adodb-session-clob.php:
<font color=#004040>
include('adodb/adodb.inc.php');
<b> $ADODB_SESSION_DRIVER='mysql';
$ADODB_SESSION_CONNECT='localhost';
$ADODB_SESSION_USER ='scott';
$ADODB_SESSION_PWD ='tiger';
$ADODB_SESSION_DB ='sessiondb';
include('adodb/session/adodb-session-clob.php');</b>
session_start();
</font>
<h4>Installation</h4>
1. Create this table in your database (syntax might vary depending on your db):
<a name=sessiontab></a>
<a name=sessiontab></a> <font color=#004040>
create table sessions (
SESSKEY char(32) not null,
EXPIRY int(11) unsigned not null,
EXPIREREF varchar(64),
DATA text not null,
primary key (sesskey)
);
SESSKEY char(32) not null,
EXPIRY int(11) unsigned not null,
EXPIREREF varchar(64),
DATA text not null,
primary key (sesskey)
);</font>
For the adodb-session-clob.inc.php version, create this:
create table sessions (
SESSKEY char(32) not null,
EXPIRY int(11) unsigned not null,
EXPIREREF varchar(64),
DATA CLOB,
primary key (sesskey)
);
For the adodb-session-clob.php version, create this:
<font color=#004040>
create table sessions (
SESSKEY char(32) not null,
EXPIRY int(11) unsigned not null,
EXPIREREF varchar(64),
DATA CLOB,
primary key (sesskey)
);</font>
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.6 or later. There are documented
session bugs in earlier versions of PHP.
<font color=#004040>
$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'; # setting this is optional
</font>
When the session is created, $<b>ADODB_SESS_CONN</b> holds the connection object.
3. Recommended is PHP 4.0.6 or later. There are documented session bugs
in earlier versions of PHP.
</pre>
<h4>Notifications</h4>
If you want to receive notifications when a session expires, then
you can tag a session with an <a href="#sessiontab">EXPIREREF</a> tag (see the definition of
the sessions table above), and before the session record is deleted,
we can call a function that will pass the contents of the EXPIREREF
field as the first parameter, and the session key as the 2nd 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
<h3>Notifications</h3>
<p>If you want to receive notification when a session expires, then
tag the session record with a <a href="#sessiontab">EXPIREREF</a> tag (see the
definition of the sessions table above). Before any session record is deleted,
ADOdb will call a notification function, passing in the EXPIREREF.
<p>
When a session is first created, we check a global variable $ADODB_SESSION_EXPIRE_NOTIFY.
This is an array with 2 elements, the first being the name of the session 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).
NOTE: When you want to change the EXPIREREF, you will need to modify a session
variable to force a database record update because we checksum the session
variables, and only perform the update when the checksum changes.
<p>
Suppose we want to be notified when a user's session
has expired, based on the userid. The user id in the global session variable $USERID.
The function name is 'NotifyFn'. So we define:
<pre> <font color=#004040>
$ADODB_SESSION_EXPIRE_NOTIFY = array('USERID','NotifyFn');
</font></pre>
And when the NotifyFn is called (when the session expires), we pass the $USERID
as the first parameter, eg. NotifyFn($userid, $sesskey). The session key (which is
the primary key of the record in the sessions table) is the 2nd parameter.
<p>
Here is an example of a Notification function that deletes some records in the database
and temporary files:
<pre><font color=#004040>
function NotifyFn($expireref, $sesskey)
{
global $ADODB_SESS_CONN; # the session connection object
$user = $ADODB_SESS_CONN->qstr($expireref);
$ADODB_SESS_CONN->Execute("delete from shopping_cart where user=$user");
system("rm /work/tmpfiles/$expireref/*");
}</font>
</pre>
<p>
<p>
NOTE: If you want to change the EXPIREREF after the session record has been
created, you will need to modify any session variable to force a database
record update.
<h4>Compression/Encryption Schemes</h4>
Since ADOdb 4.05, thanks to Ross Smith, multiple encryption and compression schemes are supported.
Currently, supported:
<pre>
MD5Crypt (crypt.inc.php)
MCrypt
Secure (Horde's emulation of MCrypt, if MCrypt module is not available.)
GZip
BZip2
</pre>
These are stackable. E.g.
<pre>
ADODB_Session::filter(new ADODB_Compress_Bzip2());
ADODB_Session::filter(new ADODB_Encrypt_MD5());
</pre>
will compress and then encrypt the record in the database.
<p>
Also see the <a href=docs-adodb.htm>core ADOdb documentation</a>.
</body>
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
+32 -8
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
@@ -193,6 +193,9 @@ class ADODB_ado extends ADOConnection {
return $arr;
}
/* returns queryID or false */
function &_query($sql,$inputarr=false)
{
@@ -543,15 +546,18 @@ class ADORecordSet_ado extends ADORecordSet {
switch($t) {
case 135: // timestamp
$this->fields[] = date('Y-m-d H:i:s',(integer)$f->value);
break;
if (!strlen((string)$f->value)) $this->fields[] = false;
else $this->fields[] = adodb_date('Y-m-d H:i:s',(float)$f->value);
break;
case 133:// A date value (yyyymmdd)
$val = $f->value;
$this->fields[] = substr($val,0,4).'-'.substr($val,4,2).'-'.substr($val,6,2);
if ($val = $f->value) {
$this->fields[] = substr($val,0,4).'-'.substr($val,4,2).'-'.substr($val,6,2);
} else
$this->fields[] = false;
break;
case 7: // adDate
$this->fields[] = date('Y-m-d',(integer)$f->value);
if (!strlen((string)$f->value)) $this->fields[] = false;
else $this->fields[] = adodb_date('Y-m-d',(float)$f->value);
break;
case 1: // null
$this->fields[] = false;
@@ -577,7 +583,25 @@ class ADORecordSet_ado extends ADORecordSet {
return true;
}
function NextRecordSet()
{
$rs = $this->_queryID;
$this->_queryID = $rs->NextRecordSet();
//$this->_queryID = $this->_QueryId->NextRecordSet();
if ($this->_queryID == null) return false;
$this->_currentRow = -1;
$this->_currentPage = -1;
$this->bind = false;
$this->fields = false;
$this->_flds = false;
$this->_tarr = false;
$this->_inited = false;
$this->Init();
return true;
}
function _close() {
$this->_flds = false;
@$this->_queryID->Close();// by Pete Dishman ([email protected])
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
@@ -27,6 +27,9 @@ class ADODB_ado_mssql extends ADODB_ado {
var $leftOuter = '*=';
var $rightOuter = '=*';
var $ansiOuter = true; // for mssql7 or later
var $substr = "substring";
var $length = 'len';
var $upperCase = 'upper';
//var $_inTransaction = 1; // always open recordsets, so no transaction problems.
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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 -3
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
@@ -118,8 +118,6 @@ class ADODB_csv extends ADOConnection {
foreach($inputarr as $v) {
$sql .= $sqlarr[$i];
// from Ron Baldwin <[email protected]>
// Only quote string types
if (gettype($v) == 'string')
$sql .= $this->qstr($v);
else if ($v === null)
+5 -4
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
@@ -84,7 +84,6 @@ class ADODB_DB2 extends ADODB_odbc {
var $identitySQL = 'values IDENTITY_VAL_LOCAL()';
var $_bindInputArray = true;
var $upperCase = 'upper';
var $substr = 'substr';
function ADODB_DB2()
@@ -248,15 +247,17 @@ class ADODB_DB2 extends ADODB_odbc {
if ($offset <= 0) {
// could also use " OPTIMIZE FOR $nrows ROWS "
if ($nrows >= 0) $sql .= " FETCH FIRST $nrows ROWS ONLY ";
return $this->Execute($sql,false);
$rs =& $this->Execute($sql,false);
} else {
if ($offset > 0 && $nrows < 0);
else {
$nrows += $offset;
$sql .= " FETCH FIRST $nrows ROWS ONLY ";
}
return ADOConnection::SelectLimit($sql,-1,$offset);
$rs =& ADOConnection::SelectLimit($sql,-1,$offset);
}
return $rs;
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
@version V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
@version V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
+7 -5
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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,10 +45,12 @@ class ADODB_firebird extends ADODB_ibase {
$str .=($offset>=0) ? "SKIP $offset " : '';
$sql = preg_replace('/^[ \t]*select/i',$str,$sql);
return ($secs) ?
$this->CacheExecute($secs,$sql,$inputarr)
:
$this->Execute($sql,$inputarr);
if ($secs)
$rs =& $this->CacheExecute($secs,$sql,$inputarr);
else
$rs =& $this->Execute($sql,$inputarr);
return $rs;
}
+210 -73
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
@@ -28,13 +28,15 @@ class ADODB_ibase extends ADOConnection {
var $databaseType = "ibase";
var $dataProvider = "ibase";
var $replaceQuote = "''"; // string to use to replace quotes
var $ibase_timefmt = '%Y-%m-%d';
var $ibase_timefmt = '%Y-%m-%d'; // For hours,mins,secs change to '%Y-%m-%d %H:%M:%S';
var $fmtDate = "'Y-m-d'";
var $fmtTimeStamp = "'Y-m-d, H:i:s'";
var $concat_operator='||';
var $_transactionID;
var $metaTablesSQL = "select rdb\$relation_name from rdb\$relations where rdb\$relation_name not like 'RDB\$%'";
var $metaColumnsSQL = "select a.rdb\$field_name,b.rdb\$field_type,b.rdb\$field_length from rdb\$relation_fields a join rdb\$fields b on a.rdb\$field_source=b.rdb\$field_name where rdb\$relation_name ='%s'";
//OPN STUFF start
var $metaColumnsSQL = "select a.rdb\$field_name, a.rdb\$null_flag, a.rdb\$default_source, b.rdb\$field_length, b.rdb\$field_scale, b.rdb\$field_sub_type, b.rdb\$field_precision, b.rdb\$field_type from rdb\$relation_fields a, rdb\$fields b where a.rdb\$field_source = b.rdb\$field_name and a.rdb\$relation_name = '%s' order by a.rdb\$field_position asc";
//OPN STUFF end
var $ibasetrans;
var $hasGenID = true;
var $_bindInputArray = true;
@@ -120,6 +122,60 @@ class ADODB_ibase extends ADOConnection {
return $ret;
}
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);
}
$table = strtoupper($table);
$sql = "SELECT * FROM RDB\$INDICES WHERE RDB\$RELATION_NAME = '".$table."'";
if (!$primary) {
$sql .= " AND RDB\$INDEX_NAME NOT LIKE 'RDB\$%'";
} else {
$sql .= " AND RDB\$INDEX_NAME NOT LIKE 'RDB\$FOREIGN%'";
}
// get index details
$rs = $this->Execute($sql);
if (!is_object($rs)) {
// restore fetchmode
if (isset($savem)) {
$this->SetFetchMode($savem);
}
$ADODB_FETCH_MODE = $save;
return FALSE;
}
$indexes = array ();
while ($row = $rs->FetchRow()) {
$index = $row[0];
if (!isset($indexes[$index])) {
if (is_null($row[3])) {$row[3] = 0;}
$indexes[$index] = array(
'unique' => ($row[3] == 1),
'columns' => array()
);
}
$sql = "SELECT * FROM RDB\$INDEX_SEGMENTS WHERE RDB\$INDEX_NAME = '".$name."' ORDER BY RDB\$FIELD_POSITION ASC";
$rs1 = $this->Execute($sql);
while ($row1 = $rs1->FetchRow()) {
$indexes[$index]['columns'][$row1[2]] = $row1[1];
}
}
// restore fetchmode
if (isset($savem)) {
$this->SetFetchMode($savem);
}
$ADODB_FETCH_MODE = $save;
return $indexes;
}
// See http://community.borland.com/article/0,1410,25844,00.html
function RowLock($tables,$where,$col)
{
@@ -128,52 +184,7 @@ class ADODB_ibase extends ADOConnection {
return 1;
}
/*// use delete and insert instead
function Replace($table, $fieldArray, $keyCol,$autoQuote=false)
{
if (count($fieldArray) == 0) return 0;
if (!is_array($keyCol)) {
$keyCol = array($keyCol);
}
if ($autoQuote)
foreach($fieldArray as $k => $v) {
if (!is_numeric($v) and $v[0] != "'" and strcasecmp($v,'null')!=0) {
$v = $this->qstr($v);
$fieldArray[$k] = $v;
}
}
$first = true;
foreach ($keyCol as $v) {
if ($first) {
$first = false;
$where = "$v=$fieldArray[$v]";
} else {
$where .= " and $v=$fieldArray[$v]";
}
}
$first = true;
foreach($fieldArray as $k => $v) {
if ($first) {
$first = false;
$iCols = "$k";
$iVals = "$v";
} else {
$iCols .= ",$k";
$iVals .= ",$v";
}
}
$this->BeginTrans();
$this->Execute("DELETE FROM $table WHERE $where");
$ok = $this->Execute("INSERT INTO $table ($iCols) VALUES ($iVals)");
$this->CommitTrans();
return ($ok) ? 2 : 0;
}
*/
function CreateSequence($seqname,$startID=1)
{
$ok = $this->Execute(("INSERT INTO RDB\$GENERATORS (RDB\$GENERATOR_NAME) VALUES (UPPER('$seqname'))" ));
@@ -228,6 +239,7 @@ class ADODB_ibase extends ADOConnection {
// returns true or false
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
{
if (!function_exists('ibase_pconnect')) return false;
if ($argDatabasename) $argHostname .= ':'.$argDatabasename;
$this->_connectionID = ibase_connect($argHostname,$argUsername,$argPassword,$this->charSet,$this->buffers,$this->dialect);
if ($this->dialect != 1) { // http://www.ibphoenix.com/ibp_60_del_id_ds.html
@@ -244,6 +256,7 @@ class ADODB_ibase extends ADOConnection {
// returns true or false
function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
{
if (!function_exists('ibase_pconnect')) return false;
if ($argDatabasename) $argHostname .= ':'.$argDatabasename;
$this->_connectionID = ibase_pconnect($argHostname,$argUsername,$argPassword,$this->charSet,$this->buffers,$this->dialect);
if ($this->dialect != 1) { // http://www.ibphoenix.com/ibp_60_del_id_ds.html
@@ -261,7 +274,7 @@ class ADODB_ibase extends ADOConnection {
function Prepare($sql)
{
// return $sql;
$stmt = ibase_prepare($sql);
$stmt = ibase_prepare($this->_connectionID,$sql);
if (!$stmt) return false;
return array($sql,$stmt);
}
@@ -335,6 +348,101 @@ class ADODB_ibase extends ADOConnection {
return @ibase_close($this->_connectionID);
}
//OPN STUFF start
function _ConvertFieldType(&$fld, $ftype, $flen, $fscale, $fsubtype, $fprecision, $isInterbase6)
{
$fscale = abs($fscale);
$fld->max_length = $flen;
$fld->scale = null;
switch($ftype){
case 7:
case 8:
if ($isInterbase6) {
switch($fsubtype){
case 0:
$fld->type = ($ftype == 7 ? 'smallint' : 'integer');
break;
case 1:
$fld->type = 'numeric';
$fld->max_length = $fprecision;
$fld->scale = $fscale;
break;
case 2:
$fld->type = 'decimal';
$fld->max_length = $fprecision;
$fld->scale = $fscale;
break;
} // switch
} else {
if ($fscale !=0) {
$fld->type = 'decimal';
$fld->scale = $fscale;
$fld->max_length = ($ftype == 7 ? 4 : 9);
} else {
$fld->type = ($ftype == 7 ? 'smallint' : 'integer');
}
}
break;
case 16:
if ($isInterbase6) {
switch($fsubtype){
case 0:
$fld->type = 'decimal';
$fld->max_length = 18;
$fld->scale = 0;
break;
case 1:
$fld->type = 'numeric';
$fld->max_length = $fprecision;
$fld->scale = $fscale;
break;
case 2:
$fld->type = 'decimal';
$fld->max_length = $fprecision;
$fld->scale = $fscale;
break;
} // switch
}
break;
case 10:
$fld->type = 'float';
break;
case 14:
$fld->type = 'char';
break;
case 27:
if ($fscale !=0) {
$fld->type = 'decimal';
$fld->max_length = 15;
$fld->scale = 5;
} else {
$fld->type = 'double';
}
break;
case 35:
if ($isInterbase6) {
$fld->type = 'timestamp';
} else {
$fld->type = 'date';
}
break;
case 12:
case 13:
$fld->type = 'date';
break;
case 37:
$fld->type = 'varchar';
break;
case 40:
$fld->type = 'cstring';
break;
case 261:
$fld->type = 'blob';
$fld->max_length = -1;
break;
} // switch
}
//OPN STUFF end
// returns array of ADOFieldObjects for current table
function &MetaColumns($table)
{
@@ -351,31 +459,41 @@ class ADODB_ibase extends ADOConnection {
if ($rs === false) return false;
$retarr = array();
//OPN STUFF start
$isInterbase6 = ($this->dialect==3 ? true : false);
//OPN STUFF end
while (!$rs->EOF) { //print_r($rs->fields);
$fld = new ADOFieldObject();
$fld->name = trim($rs->fields[0]);
$tt = $rs->fields[1];
switch($tt)
{
case 7:
case 8:
case 9:$tt = 'INTEGER'; break;
case 10:
case 27:
case 11:$tt = 'FLOAT'; break;
default:
case 40:
case 14:$tt = 'CHAR'; break;
case 35:$tt = 'DATE'; break;
case 37:$tt = 'VARCHAR'; break;
case 261:$tt = 'BLOB'; break;
case 14: $tt = 'TEXT'; break;
case 13:
case 35:$tt = 'TIMESTAMP'; break;
//OPN STUFF start
$this->_ConvertFieldType($fld, $rs->fields[7], $rs->fields[3], $rs->fields[4], $rs->fields[5], $rs->fields[6], $isInterbase6);
if (isset($rs->fields[1]) && $rs->fields[1]) {
$fld->not_null = true;
}
if (isset($rs->fields[2])) {
$fld->has_default = true;
$d = substr($rs->fields[2],strlen('default '));
switch ($fld->type)
{
case 'smallint':
case 'integer': $fld->default_value = (int) $d; break;
case 'char':
case 'blob':
case 'text':
case 'varchar': $fld->default_value = (string) substr($d,1,strlen($d)-2); break;
case 'double':
case 'float': $fld->default_value = (float) $d; break;
default: $fld->default_value = $d; break;
}
// case 35:$tt = 'TIMESTAMP'; break;
}
$fld->type = $tt;
$fld->max_length = $rs->fields[2];
if ((isset($rs->fields[5])) && ($fld->type == 'blob')) {
$fld->sub_type = $rs->fields[5];
} else {
$fld->sub_type = null;
}
//OPN STUFF end
if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld;
else $retarr[strtoupper($fld->name)] = $fld;
@@ -517,6 +635,19 @@ class ADODB_ibase extends ADOConnection {
case 'd':
$s .= "(extract(day from $col))";
break;
case 'H':
case 'h':
$s .= "(extract(hour from $col))";
break;
case 'I':
case 'i':
$s .= "(extract(minute from $col))";
break;
case 'S':
case 's':
$s .= "CAST((extract(second from $col)) AS INTEGER)";
break;
default:
if ($ch == '\\') {
$i++;
@@ -593,7 +724,11 @@ class ADORecordset_ibase extends ADORecordSet
}
// OPN stuff start - optimized
// fix missing nulls and decode blobs automatically
global $ADODB_ANSI_PADDING_OFF;
//$ADODB_ANSI_PADDING_OFF=1;
$rtrim = !empty($ADODB_ANSI_PADDING_OFF);
for ($i=0, $max = $this->_numOfFields; $i < $max; $i++) {
if ($this->_cacheType[$i]=="BLOB") {
if (isset($f[$i])) {
@@ -604,7 +739,9 @@ class ADORecordset_ibase extends ADORecordSet
} else {
if (!isset($f[$i])) {
$f[$i] = null;
}
} else if ($rtrim && is_string($f[$i])) {
$f[$i] = rtrim($f[$i]);
}
}
}
// OPN stuff end
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/**
* @version V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
* @version V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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 -3
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim. All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 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.
@@ -14,6 +14,8 @@ V4.01 23 Oct 2003 (c) 2000-2003 John Lim. All rights reserved.
*/
if (!defined('IFX_SCROLL')) define('IFX_SCROLL',1);
class ADODB_informix72 extends ADOConnection {
var $databaseType = "informix72";
var $dataProvider = "informix";
@@ -40,6 +42,7 @@ class ADODB_informix72 extends ADOConnection {
var $_bindInputArray = true; // set to true if ADOConnection.Execute() permits binding of array parameters.
var $sysDate = 'TODAY';
var $sysTimeStamp = 'CURRENT';
var $cursorType = IFX_SCROLL; // IFX_SCROLL or IFX_HOLD or 0
function ADODB_informix72()
{
@@ -179,7 +182,11 @@ class ADODB_informix72 extends ADOConnection {
// returns true or false
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
{
if (!function_exists('ifx_connect')) return false;
$dbs = $argDatabasename . "@" . $argHostname;
if ($argHostname) putenv("INFORMIXSERVER=$argHostname");
putenv("INFORMIXSERVER=$argHostname");
$this->_connectionID = ifx_connect($dbs,$argUsername,$argPassword);
if ($this->_connectionID === false) return false;
#if ($argDatabasename) return $this->SelectDB($argDatabasename);
@@ -189,7 +196,10 @@ class ADODB_informix72 extends ADOConnection {
// returns true or false
function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
{
if (!function_exists('ifx_connect')) return false;
$dbs = $argDatabasename . "@" . $argHostname;
if ($argHostname) putenv("INFORMIXSERVER=$argHostname");
$this->_connectionID = ifx_pconnect($dbs,$argUsername,$argPassword);
if ($this->_connectionID === false) return false;
#if ($argDatabasename) return $this->SelectDB($argDatabasename);
@@ -225,10 +235,10 @@ class ADODB_informix72 extends ADOConnection {
// to be able to call "move", or "movefirst" statements
if (!$ADODB_COUNTRECS && preg_match("/^\s*select/is", $sql)) {
if ($inputarr) {
$this->lastQuery = ifx_query($sql,$this->_connectionID, IFX_SCROLL, $tab);
$this->lastQuery = ifx_query($sql,$this->_connectionID, $this->cursorType, $tab);
}
else {
$this->lastQuery = ifx_query($sql,$this->_connectionID, IFX_SCROLL);
$this->lastQuery = ifx_query($sql,$this->_connectionID, $this->cursorType);
}
}
else {
+13 -4
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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,6 +75,7 @@ class ADODB_mssql extends ADOConnection {
var $fmtTimeStamp = "'Y-m-d h:i:sA'";
var $hasInsertID = true;
var $substr = "substring";
var $length = 'len';
var $upperCase = 'upper';
var $hasAffectedRows = true;
var $metaDatabasesSQL = "select name from sysdatabases where name <> 'master'";
@@ -100,6 +101,7 @@ class ADODB_mssql extends ADOConnection {
var $uniqueOrderBy = true;
var $_bindInputArray = true;
function ADODB_mssql()
{
$this->_has_mssql_init = (strnatcmp(PHP_VERSION,'4.1.0')>=0);
@@ -197,11 +199,14 @@ class ADODB_mssql extends ADOConnection {
if ($nrows > 0 && $offset <= 0) {
$sql = preg_replace(
'/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop." $nrows ",$sql);
return $this->Execute($sql,$inputarr);
$rs =& $this->Execute($sql,$inputarr);
} else
return ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
$rs =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
return $rs;
}
// Format date column in sql string given an input format that understands Y M D
function SQLDate($fmt, $col=false)
{
@@ -430,6 +435,7 @@ order by constraint_name, referenced_table_name, keyno";
// returns true or false
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
{
if (!function_exists('mssql_pconnect')) return false;
$this->_connectionID = mssql_connect($argHostname,$argUsername,$argPassword);
if ($this->_connectionID === false) return false;
if ($argDatabasename) return $this->SelectDB($argDatabasename);
@@ -440,6 +446,7 @@ order by constraint_name, referenced_table_name, keyno";
// returns true or false
function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
{
if (!function_exists('mssql_pconnect')) return false;
$this->_connectionID = mssql_pconnect($argHostname,$argUsername,$argPassword);
if ($this->_connectionID === false) return false;
@@ -511,7 +518,9 @@ order by constraint_name, referenced_table_name, keyno";
}
if ($this->debug) {
ADOConnection::outp( "Parameter(\$stmt, \$php_var='$var', \$name='$name'); (type=$type)");
$prefix = ($isOutput) ? 'Out' : 'In';
$ztype = (empty($type)) ? 'false' : $type;
ADOConnection::outp( "{$prefix}Parameter(\$stmt, \$php_var='$var', \$name='$name', \$maxLen=$maxLen, \$type=$ztype);");
}
/*
See http://phplens.com/lens/lensforum/msgs.php?id=7231
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/**
* @version V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
* @version V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
+87 -17
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
@@ -34,9 +34,8 @@ class ADODB_mysql extends ADOConnection {
var $forceNewConnect = false;
var $poorAffectedRows = true;
var $clientFlags = 0;
var $dbxDriver = 1;
var $substr = "substring";
var $lastInsID = false;
var $nameQuote = '`'; /// string to use to quote identifiers and names
function ADODB_mysql()
{
@@ -44,7 +43,7 @@ class ADODB_mysql extends ADOConnection {
function ServerInfo()
{
$arr['description'] = $this->GetOne("select version()");
$arr['description'] = ADOConnection::GetOne("select version()");
$arr['version'] = ADOConnection::_findvers($arr['description']);
return $arr;
}
@@ -69,6 +68,59 @@ class ADODB_mysql extends ADOConnection {
return $ret;
}
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);
}
// get index details
$rs = $this->Execute(sprintf('SHOW INDEXES FROM %s',$table));
// restore fetchmode
if (isset($savem)) {
$this->SetFetchMode($savem);
}
$ADODB_FETCH_MODE = $save;
if (!is_object($rs)) {
return FALSE;
}
$indexes = array ();
// parse index data into array
while ($row = $rs->FetchRow()) {
if ($primary == FALSE AND $row[2] == 'PRIMARY') {
continue;
}
if (!isset($indexes[$row[2]])) {
$indexes[$row[2]] = array(
'unique' => ($row[1] == 0),
'columns' => array()
);
}
$indexes[$row[2]]['columns'][$row[3] - 1] = $row[4];
}
// sort columns by order in the index
foreach ( array_keys ($indexes) as $index )
{
ksort ($indexes[$index]['columns']);
}
return $indexes;
}
// if magic quotes disabled, use mysql_real_escape_string()
function qstr($s,$magic_quotes=false)
{
@@ -128,14 +180,19 @@ class ADODB_mysql extends ADOConnection {
return $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
}
function GenID($seqname='adodbseq',$startID=1)
{
// post-nuke sets hasGenID to false
if (!$this->hasGenID) return false;
$savelog = $this->_logsql;
$this->_logsql = false;
$getnext = sprintf($this->_genIDSQL,$seqname);
$holdtransOK = $this->_transOK; // save the current status
$rs = @$this->Execute($getnext);
if (!$rs) {
if ($holdtransOK) $this->_transOK = true; //if the status was ok before reset
$u = strtoupper($seqname);
$this->Execute(sprintf($this->_genSeqSQL,$seqname));
$this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
@@ -145,6 +202,7 @@ class ADODB_mysql extends ADOConnection {
if ($rs) $rs->Close();
$this->_logsql = $savelog;
return $this->genID;
}
@@ -240,14 +298,6 @@ class ADODB_mysql extends ADOConnection {
{
$s = "";
$arr = func_get_args();
$first = true;
/*
foreach($arr as $a) {
if ($first) {
$s = $a;
$first = false;
} else $s .= ','.$a;
}*/
// suggestion by [email protected]
$s = implode(',',$arr);
@@ -320,6 +370,21 @@ class ADODB_mysql extends ADOConnection {
$fld->name = $rs->fields[0];
$type = $rs->fields[1];
// split type into type(length):
$fld->scale = null;
if (strpos($type,',') && preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) {
$fld->type = $query_array[1];
$fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
$fld->scale = is_numeric($query_array[3]) ? $query_array[3] : -1;
} elseif (preg_match("/^(.+)\((\d+)/", $type, $query_array)) {
$fld->type = $query_array[1];
$fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
} else {
$fld->max_length = -1;
$fld->type = $type;
}
/*
// split type into type(length):
if (preg_match("/^(.+)\((\d+)/", $type, $query_array)) {
$fld->type = $query_array[1];
@@ -327,11 +392,12 @@ class ADODB_mysql extends ADOConnection {
} else {
$fld->max_length = -1;
$fld->type = $type;
}
}*/
$fld->not_null = ($rs->fields[2] != 'YES');
$fld->primary_key = ($rs->fields[3] == 'PRI');
$fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
$fld->binary = (strpos($fld->type,'blob') !== false);
if (!$fld->binary) {
$d = $rs->fields[4];
if ($d != "" && $d != "NULL") {
@@ -366,9 +432,11 @@ class ADODB_mysql extends ADOConnection {
{
$offsetStr =($offset>=0) ? "$offset," : '';
return ($secs) ? $this->CacheExecute($secs,$sql." LIMIT $offsetStr$nrows",$inputarr)
: $this->Execute($sql." LIMIT $offsetStr$nrows",$inputarr);
if ($secs)
$rs =& $this->CacheExecute($secs,$sql." LIMIT $offsetStr$nrows",$inputarr);
else
$rs =& $this->Execute($sql." LIMIT $offsetStr$nrows",$inputarr);
return $rs;
}
@@ -484,7 +552,8 @@ class ADORecordSet_mysql extends ADORecordSet{
function &GetRowAssoc($upper=true)
{
if ($this->fetchMode == MYSQL_ASSOC && !$upper) return $this->fields;
return ADORecordSet::GetRowAssoc($upper);
$row =& ADORecordSet::GetRowAssoc($upper);
return $row;
}
/* Use associative array to get fields array */
@@ -575,6 +644,7 @@ class ADORecordSet_mysql extends ADORecordSet{
case 'BLOB':
case 'MEDIUMBLOB':
return !empty($fieldobj->binary) ? 'B' : 'X';
case 'YEAR':
case 'DATE': return 'D';
+828
View File
@@ -0,0 +1,828 @@
<?php
/*
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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 8.
MySQL code that does not support transactions. Use mysqlt if you need transactions.
Requires mysql client. Works on Windows and Unix.
21 October 2003: MySQLi extension implementation by Arjen de Rijke ([email protected])
Based on adodb 3.40
*/
if (! defined("_ADODB_MYSQL_LAYER")) {
define("_ADODB_MYSQL_LAYER", 1 );
class ADODB_mysqli extends ADOConnection {
var $databaseType = 'mysqli';
var $dataProvider = 'native';
var $hasInsertID = true;
var $hasAffectedRows = true;
var $metaTablesSQL = "SHOW TABLES";
var $metaColumnsSQL = "SHOW COLUMNS FROM %s";
var $fmtTimeStamp = "'Y-m-d H:i:s'";
var $hasLimit = true;
var $hasMoveFirst = true;
var $hasGenID = true;
var $upperCase = 'upper';
var $isoDates = true; // accepts dates in ISO format
var $sysDate = 'CURDATE()';
var $sysTimeStamp = 'NOW()';
var $hasTransactions = false;
var $forceNewConnect = false;
var $poorAffectedRows = true;
var $clientFlags = 0;
var $executeOnly = true;
var $substr = "substring";
var $nameQuote = '`'; /// string to use to quote identifiers and names
//var $_bindInputArray = true;
function ADODB_mysqli()
{
if(!extension_loaded("mysqli"))
{
trigger_error("You must have the MySQLi extension.", E_USER_ERROR);
}
}
function IfNull( $field, $ifNull )
{
return " IFNULL($field, $ifNull) "; // if MySQL
}
function ServerInfo()
{
$arr['description'] = $this->GetOne("select version()");
$arr['version'] = ADOConnection::_findvers($arr['description']);
return $arr;
}
function BeginTrans()
{
if ($this->transOff) return true;
$this->transCnt += 1;
$this->Execute('SET AUTOCOMMIT=0');
$this->Execute('BEGIN');
return true;
}
function CommitTrans($ok=true)
{
if ($this->transOff) return true;
if (!$ok) return $this->RollbackTrans();
if ($this->transCnt) $this->transCnt -= 1;
$this->Execute('COMMIT');
$this->Execute('SET AUTOCOMMIT=1');
return true;
}
function RollbackTrans()
{
if ($this->transOff) return true;
if ($this->transCnt) $this->transCnt -= 1;
$this->Execute('ROLLBACK');
$this->Execute('SET AUTOCOMMIT=1');
return true;
}
// if magic quotes disabled, use mysql_real_escape_string()
// From readme.htm:
// Quotes a string to be sent to the database. The $magic_quotes_enabled
// parameter may look funny, but the idea is if you are quoting a
// string extracted from a POST/GET variable, then
// pass get_magic_quotes_gpc() as the second parameter. This will
// ensure that the variable is not quoted twice, once by qstr and once
// by the magic_quotes_gpc.
//
//Eg. $s = $db->qstr(HTTP_GET_VARS['name'],get_magic_quotes_gpc());
function qstr($s, $magic_quotes = false)
{
if (!$magic_quotes) {
if (ADODB_PHPVER >= 0x5000) {
// $this->_connectionID = $this->mysqli_resolve_link($this->_connectionID);
return "'" . mysqli_real_escape_string($this->_connectionID, $s) . "'";
}
else
{
trigger_error("phpver < 5 not implemented", E_USER_ERROR);
}
if ($this->replaceQuote[0] == '\\')
{
$s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s);
}
return "'".str_replace("'",$this->replaceQuote,$s)."'";
}
// undo magic quotes for "
$s = str_replace('\\"','"',$s);
return "'$s'";
}
function _insertid()
{
// $this->_connectionID = $this->mysqli_resolve_link($this->_connectionID);
$result = @mysqli_insert_id($this->_connectionID);
if ($result == -1){
if ($this->debug) ADOConnection::outp("mysqli_insert_id() failed : " . $this->ErrorMsg());
}
return $result;
}
// Only works for INSERT, UPDATE and DELETE query's
function _affectedrows()
{
// $this->_connectionID = $this->mysqli_resolve_link($this->_connectionID);
$result = @mysqli_affected_rows($this->_connectionID);
if ($result == -1) {
if ($this->debug) ADOConnection::outp("mysqli_affected_rows() failed : " . $this->ErrorMsg());
}
return $result;
}
// See http://www.mysql.com/doc/M/i/Miscellaneous_functions.html
// Reference on Last_Insert_ID on the recommended way to simulate sequences
var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
var $_genSeqSQL = "create table %s (id int not null)";
var $_genSeq2SQL = "insert into %s values (%s)";
var $_dropSeqSQL = "drop table %s";
function CreateSequence($seqname='adodbseq',$startID=1)
{
if (empty($this->_genSeqSQL)) return false;
$u = strtoupper($seqname);
$ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname));
if (!$ok) return false;
return $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
}
function GenID($seqname='adodbseq',$startID=1)
{
// post-nuke sets hasGenID to false
if (!$this->hasGenID) return false;
$getnext = sprintf($this->_genIDSQL,$seqname);
$holdtransOK = $this->_transOK; // save the current status
$rs = @$this->Execute($getnext);
if (!$rs) {
if ($holdtransOK) $this->_transOK = true; //if the status was ok before reset
$u = strtoupper($seqname);
$this->Execute(sprintf($this->_genSeqSQL,$seqname));
$this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
$rs = $this->Execute($getnext);
}
$this->genID = mysqli_insert_id($this->_connectionID);
if ($rs) $rs->Close();
return $this->genID;
}
function &MetaDatabases()
{
$query = "SHOW DATABASES";
$ret =& $this->Execute($query);
return $ret;
}
function &MetaIndexes ($table, $primary = 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);
}
// get index details
$rs = $this->Execute(sprintf('SHOW INDEXES FROM %s',$table));
// restore fetchmode
if (isset($savem)) {
$this->SetFetchMode($savem);
}
$ADODB_FETCH_MODE = $save;
if (!is_object($rs)) {
return FALSE;
}
$indexes = array ();
// parse index data into array
while ($row = $rs->FetchRow()) {
if ($primary == FALSE AND $row[2] == 'PRIMARY') {
continue;
}
if (!isset($indexes[$row[2]])) {
$indexes[$row[2]] = array(
'unique' => ($row[1] == 0),
'columns' => array()
);
}
$indexes[$row[2]]['columns'][$row[3] - 1] = $row[4];
}
// sort columns by order in the index
foreach ( array_keys ($indexes) as $index )
{
ksort ($indexes[$index]['columns']);
}
return $indexes;
}
// Format date column in sql string given an input format that understands Y M D
function SQLDate($fmt, $col=false)
{
if (!$col) $col = $this->sysTimeStamp;
$s = 'DATE_FORMAT('.$col.",'";
$concat = false;
$len = strlen($fmt);
for ($i=0; $i < $len; $i++) {
$ch = $fmt[$i];
switch($ch) {
case 'Y':
case 'y':
$s .= '%Y';
break;
case 'Q':
case 'q':
$s .= "'),Quarter($col)";
if ($len > $i+1) $s .= ",DATE_FORMAT($col,'";
else $s .= ",('";
$concat = true;
break;
case 'M':
$s .= '%b';
break;
case 'm':
$s .= '%m';
break;
case 'D':
case 'd':
$s .= '%d';
break;
case 'H':
$s .= '%H';
break;
case 'h':
$s .= '%I';
break;
case 'i':
$s .= '%i';
break;
case 's':
$s .= '%s';
break;
case 'a':
case 'A':
$s .= '%p';
break;
default:
if ($ch == '\\') {
$i++;
$ch = substr($fmt,$i,1);
}
$s .= $ch;
break;
}
}
$s.="')";
if ($concat) $s = "CONCAT($s)";
return $s;
}
// returns concatenated string
// much easier to run "mysqld --ansi" or "mysqld --sql-mode=PIPES_AS_CONCAT" and use || operator
function Concat()
{
$s = "";
$arr = func_get_args();
// suggestion by [email protected]
$s = implode(',',$arr);
if (strlen($s) > 0) return "CONCAT($s)";
else return '';
}
// 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)";
}
// returns true or false
// To add: parameter int $port,
// parameter string $socket
function _connect($argHostname = NULL,
$argUsername = NULL,
$argPassword = NULL,
$argDatabasename = NULL)
{
// @ means: error surpression on
$this->_connectionID = @mysqli_init();
if (is_null($this->_connectionID))
{
// mysqli_init only fails if insufficient memory
if ($this->debug)
ADOConnection::outp("mysqli_init() failed : " . $this->ErrorMsg());
return false;
}
// Set connection options
// Not implemented now
// mysqli_options($this->_connection,,);
if (mysqli_real_connect($this->_connectionID,
$argHostname,
$argUsername,
$argPassword,
$argDatabasename))
{
if ($argDatabasename)
{
return $this->SelectDB($argDatabasename);
}
return true;
}
else
{
if ($this->debug)
ADOConnection::outp("Could't connect : " . $this->ErrorMsg());
return false;
}
}
// returns true or false
// How to force a persistent connection
function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
{
// not implemented in mysqli (yet)?
$this->_connectionID = mysqli_connect($argHostname,
$argUsername,
$argPassword,
$argDatabasename);
if ($this->_connectionID === false) return false;
// if ($this->autoRollback) $this->RollbackTrans();
if ($argDatabasename) return $this->SelectDB($argDatabasename);
return true;
}
// When is this used? Close old connection first?
// In _connect(), check $this->forceNewConnect?
function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
{
$this->forceNewConnect = true;
$this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename);
}
function &MetaColumns($table)
{
if ($this->metaColumnsSQL) {
global $ADODB_FETCH_MODE;
$save = $ADODB_FETCH_MODE;
$rs = false;
switch($ADODB_FETCH_MODE)
{
case ADODB_FETCH_NUM:
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
$rs = $this->Execute(sprintf($this->metaColumnsSQL,
$table));
$ADODB_FETCH_MODE = $save;
if ($rs === false) break;
$retarr = array();
while (!$rs->EOF){
$fld = new ADOFieldObject();
$fld->name = $rs->fields[0];
$fld->type = $rs->fields[1];
// split type into type(length):
if (preg_match("/^(.+)\((\d+)\)$/", $fld->type, $query_array))
{
$fld->type = $query_array[1];
$fld->max_length = $query_array[2];
}
else
{
$fld->max_length = -1;
}
$fld->not_null = ($rs->fields[2] != 'YES');
$fld->primary_key = ($rs->fields[3] == 'PRI');
$fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
$fld->binary = (strpos($fld->type,'blob') !== false);
if (!$fld->binary)
{
$d = $rs->fields[4];
$d = $rs->fields['Default'];
if ($d != "" && $d != "NULL")
{
$fld->has_default = true;
$fld->default_value = $d;
}
else
{
$fld->has_default = false;
}
}
$retarr[strtoupper($fld->name)] = $fld;
$rs->MoveNext();
}
break;
case ADODB_FETCH_ASSOC:
case ADODB_FETCH_DEFAULT:
case ADODB_FETCH_BOTH:
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$rs = $this->Execute(sprintf($this->metaColumnsSQL,
$table));
$ADODB_FETCH_MODE = $save;
if ($rs === false) break;
$retarr = array();
while (!$rs->EOF){
$fld = new ADOFieldObject();
$fld->name = $rs->fields['Field'];
$fld->type = $rs->fields['Type'];
// split type into type(length):
if (preg_match("/^(.+)\((\d+)\)$/", $fld->type, $query_array))
{
$fld->type = $query_array[1];
$fld->max_length = $query_array[2];
}
else
{
$fld->max_length = -1;
}
$fld->not_null = ($rs->fields['Null'] != 'YES');
$fld->primary_key = ($rs->fields['Key'] == 'PRI');
$fld->auto_increment = (strpos($rs->fields['Extra'], 'auto_increment') !== false);
$fld->binary = (strpos($fld->type,'blob') !== false);
if (!$fld->binary)
{
$d = $rs->fields['Default'];
if ($d != "" && $d != "NULL")
{
$fld->has_default = true;
$fld->default_value = $d;
}
else
{
$fld->has_default = false;
}
}
$retarr[strtoupper($fld->name)] = $fld;
$rs->MoveNext();
}
break;
default:
}
if ($rs === false) return false;
$rs->Close();
return $retarr;
}
return false;
}
// returns true or false
function SelectDB($dbName)
{
// $this->_connectionID = $this->mysqli_resolve_link($this->_connectionID);
$this->databaseName = $dbName;
if ($this->_connectionID) {
$result = @mysqli_select_db($this->_connectionID, $dbName);
if (!$result) {
ADOConnection::outp("Select of database " . $dbName . " failed. " . $this->ErrorMsg());
}
return $result;
}
return false;
}
// parameters use PostgreSQL convention, not MySQL
function &SelectLimit($sql,
$nrows = -1,
$offset = -1,
$inputarr = false,
$arg3 = false,
$secs = 0)
{
$offsetStr = ($offset >= 0) ? "$offset," : '';
if ($secs)
$rs =& $this->CacheExecute($secs, $sql . " LIMIT $offsetStr$nrows" , $inputarr , $arg3);
else
$rs =& $this->Execute($sql . " LIMIT $offsetStr$nrows" , $inputarr , $arg3);
return $rs;
}
function Prepare($sql)
{
return $sql;
$stmt = mysqli_prepare($this->_connectionID,$sql);
if (!$stmt) return false;
return array($sql,$stmt);
}
// returns queryID or false
function _query($sql, $inputarr)
{
global $ADODB_COUNTRECS;
if (is_array($sql)) {
$stmt = $sql[1];
foreach($inputarr as $k => $v) {
if (is_string($v)) $a[] = MYSQLI_BIND_STRING;
else if (is_integer($v)) $a[] = MYSQLI_BIND_INT;
else $a[] = MYSQLI_BIND_DOUBLE;
$fnarr =& array_merge( array($stmt,$a) , $inputarr);
$ret = call_user_func_array('mysqli_bind_param',$fnarr);
}
$ret = mysqli_execute($stmt);
return $ret;
}
if (!$mysql_res = mysqli_query($this->_connectionID, $sql, ($ADODB_COUNTRECS) ? MYSQLI_STORE_RESULT : MYSQLI_USE_RESULT)) {
if ($this->debug) ADOConnection::outp("Query: " . $sql . " failed. " . $this->ErrorMsg());
return false;
}
return $mysql_res;
}
/* Returns: the last error message from previous database operation */
function ErrorMsg()
{
if (empty($this->_connectionID))
$this->_errorMsg = @mysqli_error();
else
$this->_errorMsg = @mysqli_error($this->_connectionID);
return $this->_errorMsg;
}
/* Returns: the last error number from previous database operation */
function ErrorNo()
{
if (empty($this->_connectionID))
return @mysqli_errno();
else
return @mysqli_errno($this->_connectionID);
}
// returns true or false
function _close()
{
@mysqli_close($this->_connectionID);
$this->_connectionID = false;
}
/*
* Maximum size of C field
*/
function CharMax()
{
return 255;
}
/*
* Maximum size of X field
*/
function TextMax()
{
return 4294967295;
}
}
/*--------------------------------------------------------------------------------------
Class Name: Recordset
--------------------------------------------------------------------------------------*/
class ADORecordSet_mysqli extends ADORecordSet{
var $databaseType = "mysqli";
var $canSeek = true;
function ADORecordSet_mysqli($queryID, $mode = false)
{
if ($mode === false)
{
global $ADODB_FETCH_MODE;
$mode = $ADODB_FETCH_MODE;
}
switch ($mode)
{
case ADODB_FETCH_NUM:
$this->fetchMode = MYSQLI_NUM;
break;
case ADODB_FETCH_ASSOC:
$this->fetchMode = MYSQLI_ASSOC;
break;
case ADODB_FETCH_DEFAULT:
case ADODB_FETCH_BOTH:
default:
$this->fetchMode = MYSQLI_ASSOC;
break;
}
$this->ADORecordSet($queryID);
}
function _initrs()
{
// mysqli_num_rows only return correct number, depens
// on the use of mysql_store_result and mysql_use_result
if (!$this->Connection->executeOnly) {
$this->_numOfRows = @mysqli_num_rows($this->_queryID);
$this->_numOfFields = @mysqli_num_fields($this->_queryID);
}
else {
$this->_numOfRows = 0;
$this->_numOfFields = 0;
}
}
function &FetchField($fieldOffset = -1)
{
$fieldnr = $fieldOffset;
if ($fieldOffset != -1) {
$fieldOffset = mysqi_field_seek($this->_queryID, $fieldnr);
}
$o = mysqli_fetch_field($this->_queryID);
return $o;
}
function &GetRowAssoc($upper = true)
{
if ($this->fetchMode == MYSQLI_ASSOC && !$upper)
return $this->fields;
$row =& ADORecordSet::GetRowAssoc($upper);
return $row;
}
/* Use associative array to get fields array */
function Fields($colname)
{
if ($this->fetchMode != MYSQLI_NUM)
return @$this->fields[$colname];
if (!$this->bind) {
$this->bind = array();
for ($i = 0; $i < $this->_numOfFields; $i++) {
$o = $this->FetchField($i);
$this->bind[strtoupper($o->name)] = $i;
}
}
return $this->fields[$this->bind[strtoupper($colname)]];
}
function _seek($row)
{
if ($this->_numOfRows == 0)
return false;
if ($row < 0)
return false;
mysqli_data_seek($this->_queryID, $row);
$this->EOF = false;
return true;
}
// 10% speedup to move MoveNext to child class
// This is the only implementation that works now (23-10-2003).
// Other functions return no or the wrong results.
function MoveNext()
{
if ($this->EOF)
return false;
$this->_currentRow++;
switch($this->fetchMode)
{
case MYSQLI_NUM:
$this->fields = mysqli_fetch_array($this->_queryID);
break;
case MYSQLI_ASSOC:
case MYSQLI_BOTH:
$this->fields = mysqli_fetch_assoc($this->_queryID);
break;
default:
}
if (is_array($this->fields))
return true;
$this->EOF = true;
return false;
}
function _fetch()
{
// mysqli_fetch_array($this->_queryID, MYSQLI_NUM) does not
// work (22-10-2003). But mysqli_fetch_array($this->_queryID) gives
// int resulttype should default to MYSQLI_BOTH,but give MYSQLI_NUM.
// $this->fields = mysqli_fetch_fields($this->_queryID);
// $this->fields = mysqli_fetch_array($this->_queryID); //, $this->fetchMode);
$this->fields = mysqli_fetch_assoc($this->_queryID); // $this->fetchMode);
return is_array($this->fields);
}
function _close()
{
mysqli_free_result($this->_queryID);
$this->_queryID = false;
}
function MetaType($t, $len = -1, $fieldobj = false)
{
if (is_object($t))
{
$fieldobj = $t;
$t = $fieldobj->type;
$len = $fieldobj->max_length;
}
$len = -1; // mysql max_length is not accurate
switch (strtoupper($t)) {
case 'STRING':
case 'CHAR':
case 'VARCHAR':
case 'TINYBLOB':
case 'TINYTEXT':
case 'ENUM':
case 'SET':
if ($len <= $this->blobSize) return 'C';
case 'TEXT':
case 'LONGTEXT':
case 'MEDIUMTEXT':
return 'X';
// php_mysql extension always returns 'blob' even if 'text'
// so we have to check whether binary...
case 'IMAGE':
case 'LONGBLOB':
case 'BLOB':
case 'MEDIUMBLOB':
return !empty($fieldobj->binary) ? 'B' : 'X';
case 'YEAR':
case 'DATE':
return 'D';
case 'TIME':
case 'DATETIME':
case 'TIMESTAMP': return 'T';
case 'INT':
case 'INTEGER':
case 'BIGINT':
case 'TINYINT':
case 'MEDIUMINT':
case 'SMALLINT':
if (!empty($fieldobj->primary_key)) return 'R';
else return 'I';
// Added floating-point types
// Maybe not necessery.
case 'FLOAT':
case 'DOUBLE':
// case 'DOUBLE PRECISION':
case 'DECIMAL':
case 'DEC':
case 'FIXED':
default:
return 'N';
}
}
}
}
?>
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
+35 -28
View File
@@ -1,7 +1,7 @@
<?php
/*
version V4.01 23 Oct 2003 (c) 2000-2003 John Lim. All rights reserved.
version V4.11 27 Jan 2004 (c) 2000-2004 John Lim. All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
@@ -33,9 +33,8 @@ year entries allows you to become year-2000 compliant. For example:
NLS_DATE_FORMAT='RR-MM-DD'
You can also modify the date format using the ALTER SESSION command.
*/
class ADODB_oci8 extends ADOConnection {
var $databaseType = 'oci8';
var $dataProvider = 'oci8';
@@ -55,8 +54,7 @@ class ADODB_oci8 extends ADOConnection {
var $_genSeqSQL = "CREATE SEQUENCE %s START WITH %s";
var $_dropSeqSQL = "DROP SEQUENCE %s";
var $hasAffectedRows = true;
var $upperCase = 'upper';
var $substr = 'substr';
var $random = "abs(mod(DBMS_RANDOM.RANDOM,10000001)/10000000)";
var $noNullStrings = false;
var $connectSID = false;
var $_bind = false;
@@ -150,6 +148,9 @@ NATSOFT.DOMAIN =
*/
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename,$mode=0)
{
if (!function_exists('OCIPLogon')) return false;
$this->_errorMsg = false;
$this->_errorCode = false;
@@ -207,6 +208,8 @@ NATSOFT.DOMAIN =
return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename,1);
}
// returns true or false
function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
{
@@ -438,7 +441,9 @@ NATSOFT.DOMAIN =
}
// note that $nrows = 0 still has to work ==> no rows returned
return ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
$rs =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
return $rs;
} else {
// Algorithm by Tomas V V Cox, from PEAR DB oci8.php
@@ -449,8 +454,7 @@ NATSOFT.DOMAIN =
}
if (is_array($inputarr)) {
reset($inputarr);
while (list($k,$v) = each($inputarr)) {
foreach($inputarr as $k => $v) {
if (is_array($v)) {
if (sizeof($v) == 2) // suggested by g.giunta@libero.
OCIBindByName($stmt,":$k",$inputarr[$k][0],$v[1]);
@@ -498,8 +502,9 @@ NATSOFT.DOMAIN =
$inputarr['adodb_nrows'] = $nrows;
$inputarr['adodb_offset'] = $offset;
if ($secs2cache>0) return $this->CacheExecute($secs2cache, $sql,$inputarr);
else return $this->Execute($sql,$inputarr);
if ($secs2cache>0) $rs =& $this->CacheExecute($secs2cache, $sql,$inputarr);
else $rs =& $this->Execute($sql,$inputarr);
return $rs;
}
}
@@ -589,7 +594,7 @@ NATSOFT.DOMAIN =
$stmt = $this->Prepare('insert into emp (empno, ename) values (:empno, :ename)');
*/
function Prepare($sql)
function Prepare($sql,$cursor=false)
{
static $BINDNUM = 0;
@@ -600,7 +605,7 @@ NATSOFT.DOMAIN =
$BINDNUM += 1;
if (@OCIStatementType($stmt) == 'BEGIN') {
return array($sql,$stmt,0,$BINDNUM,OCINewCursor($this->_connectionID));
return array($sql,$stmt,0,$BINDNUM, ($cursor) ? false : OCINewCursor($this->_connectionID));
}
return array($sql,$stmt,0,$BINDNUM);
@@ -623,13 +628,12 @@ NATSOFT.DOMAIN =
*/
function &ExecuteCursor($sql,$cursorName='rs',$params=false)
{
$stmt = ADODB_oci8::Prepare($sql);
$stmt = ADODB_oci8::Prepare($sql,true); # true to allocate OCINewCursor
if (is_array($stmt) && sizeof($stmt) >= 5) {
$this->Parameter($stmt, $ignoreCur, $cursorName, false, -1, OCI_B_CURSOR);
if ($params) {
reset($params);
while (list($k,$v) = each($params)) {
foreach($params as $k => $v) {
$this->Parameter($stmt,$params[$k], $k);
}
}
@@ -711,7 +715,9 @@ NATSOFT.DOMAIN =
function Parameter(&$stmt,&$var,$name,$isOutput=false,$maxLen=4000,$type=false)
{
if ($this->debug) {
ADOConnection::outp( "Parameter(\$stmt, \$php_var='$var', \$name='$name');");
$prefix = ($isOutput) ? 'Out' : 'In';
$ztype = (empty($type)) ? 'false' : $type;
ADOConnection::outp( "{$prefix}Parameter(\$stmt, \$php_var='$var', \$name='$name', \$maxLen=$maxLen, \$type=$ztype);");
}
return $this->Bind($stmt,$var,$maxLen,$type,$name);
}
@@ -747,8 +753,7 @@ NATSOFT.DOMAIN =
} else {
// one statement to bind them all
$bindarr = array();
reset($inputarr);
while(list($k,$v) = each($inputarr)) {
foreach($inputarr as $k => $v) {
$bindarr[$k] = $v;
OCIBindByName($stmt,":$k",$bindarr[$k],4000);
}
@@ -765,8 +770,7 @@ NATSOFT.DOMAIN =
if (defined('ADODB_PREFETCH_ROWS')) @OCISetPrefetch($stmt,ADODB_PREFETCH_ROWS);
if (is_array($inputarr)) {
reset($inputarr);
while(list($k,$v) = each($inputarr)) {
foreach($inputarr as $k => $v) {
if (is_array($v)) {
if (sizeof($v) == 2) // suggested by g.giunta@libero.
OCIBindByName($stmt,":$k",$inputarr[$k][0],$v[1]);
@@ -795,17 +799,17 @@ NATSOFT.DOMAIN =
return $stmt;
case "BEGIN":
if (is_array($sql) && isset($sql[4])) {
if (is_array($sql) && !empty($sql[4])) {
$cursor = $sql[4];
if (is_resource($cursor)) {
OCIExecute($cursor);
$ok = OCIExecute($cursor);
return $cursor;
}
return $stmt;
} else {
if (is_resource($stmt)) {
OCIFreeStatement($stmt);
return true;
OCIFreeStatement($stmt);
return true;
}
return $stmt;
}
@@ -984,10 +988,10 @@ class ADORecordset_oci8 extends ADORecordSet {
$this->_inited = true;
if ($this->_queryID) {
$this->_currentRow = 0;
@$this->_initrs();
$this->EOF = !$this->_fetch();
$this->EOF = !$this->_fetch();
/*
// based on idea by Gaetano Giunta to detect unusual oracle errors
@@ -1065,7 +1069,10 @@ class ADORecordset_oci8 extends ADORecordSet {
/* Optimize SelectLimit() by using OCIFetch() instead of OCIFetchInto() */
function &GetArrayLimit($nrows,$offset=-1)
{
if ($offset <= 0) return $this->GetArray($nrows);
if ($offset <= 0) {
$arr =& $this->GetArray($nrows);
return $arr;
}
for ($i=1; $i < $offset; $i++)
if (!@OCIFetch($this->_queryID)) return array();
@@ -1139,7 +1146,7 @@ class ADORecordset_oci8 extends ADORecordSet {
case 'NCLOB':
case 'LONG':
case 'LONG VARCHAR':
case 'CLOB';
case 'CLOB':
return 'X';
case 'LONG RAW':
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/**
* @version V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
* @version V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
+18 -3
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim. All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 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.
@@ -112,10 +112,18 @@ class ADORecordset_oci8po extends ADORecordset_oci8 {
// 10% speedup to move MoveNext to child class
function MoveNext()
{
if (!$this->EOF) {
$this->_currentRow++;
if(@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) {
global $ADODB_ANSI_PADDING_OFF;
if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();
if (!empty($ADODB_ANSI_PADDING_OFF)) {
foreach($this->fields as $k => $v) {
if (is_string($v)) $this->fields[$k] = rtrim($v);
}
}
return true;
}
$this->EOF = true;
@@ -150,7 +158,7 @@ class ADORecordset_oci8po extends ADORecordset_oci8 {
$arr = array();
$lowercase = (ADODB_ASSOC_CASE == 0);
foreach ($this->fields as $k => $v) {
foreach($this->fields as $k => $v) {
if (is_integer($k)) $arr[$k] = $v;
else {
if ($lowercase)
@@ -166,7 +174,14 @@ class ADORecordset_oci8po extends ADORecordset_oci8 {
{
$ret = @OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode);
if ($ret) {
if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();
global $ADODB_ANSI_PADDING_OFF;
if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();
if (!empty($ADODB_ANSI_PADDING_OFF)) {
foreach($this->fields as $k => $v) {
if (is_string($v)) $this->fields[$k] = rtrim($v);
}
}
}
return $ret;
}
+16 -6
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
@@ -156,6 +156,9 @@ class ADODB_odbc extends ADOConnection {
function _connect($argDSN, $argUsername, $argPassword, $argDatabasename)
{
global $php_errormsg;
if (!function_exists('odbc_connect')) return false;
if ($this->debug && $argDatabasename) {
ADOConnection::outp("For odbc Connect(), $argDatabasename is not used. Place dsn in 1st parameter.");
}
@@ -173,6 +176,9 @@ class ADODB_odbc extends ADOConnection {
function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename)
{
global $php_errormsg;
if (!function_exists('odbc_connect')) return false;
$php_errormsg = '';
if ($this->debug && $argDatabasename) {
ADOConnection::outp("For odbc PConnect(), $argDatabasename is not used. Place dsn in 1st parameter.");
@@ -352,7 +358,9 @@ class ADODB_odbc extends ADOConnection {
global $ADODB_FETCH_MODE;
$table = strtoupper($table);
$schema = false;
$this->_findschema($table,$schema);
$savem = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
@@ -394,7 +402,6 @@ class ADODB_odbc extends ADOConnection {
if (!$rs) return false;
//print_r($rs);
$rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change;
$rs->_fetch();
$retarr = array();
@@ -415,8 +422,8 @@ class ADODB_odbc extends ADOConnection {
11 REMARKS
*/
while (!$rs->EOF) {
//print_r($rs->fields);
if (strtoupper($rs->fields[2]) == $table) {
//adodb_pr($rs->fields);
if (strtoupper($rs->fields[2]) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) {
$fld = new ADOFieldObject();
$fld->name = $rs->fields[3];
$fld->type = $this->ODBCTypes($rs->fields[4]);
@@ -632,7 +639,10 @@ class ADORecordSet_odbc extends ADORecordSet {
// speed up SelectLimit() by switching to ADODB_FETCH_NUM as ADODB_FETCH_ASSOC is emulated
function &GetArrayLimit($nrows,$offset=-1)
{
if ($offset <= 0) return $this->GetArray($nrows);
if ($offset <= 0) {
$rs =& $this->GetArray($nrows);
return $rs;
}
$savem = $this->fetchMode;
$this->fetchMode = ADODB_FETCH_NUM;
$this->Move($offset);
+6 -3
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
@@ -31,6 +31,7 @@ class ADODB_odbc_mssql extends ADODB_odbc {
var $rightOuter = '=*';
var $upperCase = 'upper';
var $substr = 'substring';
var $length = 'len';
var $ansiOuter = true; // for mssql7 or later
var $identitySQL = 'select @@IDENTITY'; // 'select SCOPE_IDENTITY'; # for mssql 2000
var $hasInsertID = true;
@@ -157,9 +158,11 @@ order by constraint_name, referenced_table_name, keyno";
if ($nrows > 0 && $offset <= 0) {
$sql = preg_replace(
'/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop." $nrows ",$sql);
return $this->Execute($sql,$inputarr);
$rs =& $this->Execute($sql,$inputarr);
} else
return ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
$rs =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
return $rs;
}
// Format date column in sql string given an input format that understands Y M D
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
+192 -111
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
@@ -69,8 +69,17 @@ class ADODB_postgres64 extends ADOConnection{
FROM pg_class c, pg_attribute a,pg_type t
WHERE relkind = 'r' AND (c.relname='%s' or c.relname = lower('%s')) and a.attname not like '....%%'
AND a.attnum > 0 AND a.atttypid = t.oid AND a.attrelid = c.oid ORDER BY a.attnum";
var $metaColumnsSQL1 = "SELECT a.attname, t.typname, a.attlen, a.atttypmod, a.attnotnull, a.atthasdef, a.attnum
FROM pg_class c, pg_attribute a, pg_type t, pg_namespace n
WHERE relkind = 'r' AND (c.relname='%s' or c.relname = lower('%s'))
and c.relnamespace=n.oid and n.nspname='%s'
and a.attname not like '....%%' AND a.attnum > 0
AND a.atttypid = t.oid AND a.attrelid = c.oid ORDER BY a.attnum";
// get primary key etc -- from Freek Dijkstra
var $metaKeySQL = "SELECT ic.relname AS index_name, a.attname AS column_name,i.indisunique AS unique_key, i.indisprimary AS primary_key FROM pg_class bc, pg_class ic, pg_index i, pg_attribute a WHERE bc.oid = i.indrelid AND ic.oid = i.indexrelid AND (i.indkey[0] = a.attnum OR i.indkey[1] = a.attnum OR i.indkey[2] = a.attnum OR i.indkey[3] = a.attnum OR i.indkey[4] = a.attnum OR i.indkey[5] = a.attnum OR i.indkey[6] = a.attnum OR i.indkey[7] = a.attnum) AND a.attrelid = bc.oid AND bc.relname = '%s'";
var $metaKeySQL = "SELECT ic.relname AS index_name, a.attname AS column_name,i.indisunique AS unique_key, i.indisprimary AS primary_key
FROM pg_class bc, pg_class ic, pg_index i, pg_attribute a WHERE bc.oid = i.indrelid AND ic.oid = i.indexrelid AND (i.indkey[0] = a.attnum OR i.indkey[1] = a.attnum OR i.indkey[2] = a.attnum OR i.indkey[3] = a.attnum OR i.indkey[4] = a.attnum OR i.indkey[5] = a.attnum OR i.indkey[6] = a.attnum OR i.indkey[7] = a.attnum) AND a.attrelid = bc.oid AND bc.relname = '%s'";
var $hasAffectedRows = true;
var $hasLimit = false; // set to true for pgsql 7 only. support pgsql/mysql SELECT * FROM TABLE LIMIT 10
@@ -85,8 +94,9 @@ AND a.attnum > 0 AND a.atttypid = t.oid AND a.attrelid = c.oid ORDER BY a.attnum
var $_genSeqSQL = "CREATE SEQUENCE %s START %s";
var $_dropSeqSQL = "DROP SEQUENCE %s";
var $metaDefaultsSQL = "SELECT d.adnum as num, d.adsrc as def from pg_attrdef d, pg_class c where d.adrelid=c.oid and c.relname='%s' order by d.adnum";
var $upperCase = 'upper';
var $substr = "substr";
var $random = 'random()'; /// random function
var $autoRollback = true; // apparently pgsql does not autorollback properly before 4.3.4
// http://bugs.php.net/bug.php?id=25404
// The last (fmtTimeStamp is not entirely correct:
// PostgreSQL also has support for time zones,
@@ -145,7 +155,7 @@ a different OID if a database must be reloaded. */
if (!is_resource($this->_resultid) || get_resource_type($this->_resultid) !== 'pgsql result') return false;
return pg_cmdtuples($this->_resultid);
}
// returns true/false
function BeginTrans()
@@ -348,6 +358,8 @@ select viewname,'V' from pg_views where viewname like $mask";
function BlobEncode($blob)
{
if (ADODB_PHPVER >= 0x4200) return pg_escape_bytea($blob);
/*92=backslash, 0=null, 39=single-quote*/
$badch = array(chr(92),chr(0),chr(39)); # \ null '
$fixch = array('\\\\134','\\\\000','\\\\047');
return adodb_str_replace($badch,$fixch,$blob);
@@ -357,8 +369,8 @@ select viewname,'V' from pg_views where viewname like $mask";
function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB')
{
return $this->Execute("UPDATE $table SET $column=? WHERE $where",
array($this->BlobEncode($val))) != false;
// do not use bind params which uses qstr(), as blobencode() already quotes data
return $this->Execute("UPDATE $table SET $column='".$this->BlobEncode($val)."'::bytea WHERE $where");
}
function OffsetDate($dayFraction,$date=false)
@@ -368,111 +380,177 @@ select viewname,'V' from pg_views where viewname like $mask";
}
// converts field names to lowercase
function &MetaColumns($table)
// for schema support, pass in the $table param "$schema.$tabname".
// converts field names to lowercase, $upper is ignored
function &MetaColumns($table,$upper=true)
{
global $ADODB_FETCH_MODE;
//if (strncmp(PHP_OS,'WIN',3) === 0);
$schema = false;
$this->_findschema($table,$schema);
$table = strtolower($table);
if (!empty($this->metaColumnsSQL)) {
$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
$rs = $this->Execute(sprintf($this->metaColumnsSQL,$table,$table));
$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
if ($schema) $rs =& $this->Execute(sprintf($this->metaColumnsSQL1,$table,$table,$schema));
else $rs =& $this->Execute(sprintf($this->metaColumnsSQL,$table,$table));
if (isset($savem)) $this->SetFetchMode($savem);
$ADODB_FETCH_MODE = $save;
if ($rs === false) return false;
if (!empty($this->metaKeySQL)) {
// If we want the primary keys, we have to issue a separate query
// Of course, a modified version of the metaColumnsSQL query using a
// LEFT JOIN would have been much more elegant, but postgres does
// not support OUTER JOINS. So here is the clumsy way.
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$rskey = $this->Execute(sprintf($this->metaKeySQL,($table)));
// fetch all result in once for performance.
$keys =& $rskey->GetArray();
if (isset($savem)) $this->SetFetchMode($savem);
$ADODB_FETCH_MODE = $save;
if ($rs === false) return false;
if (!empty($this->metaKeySQL)) {
// If we want the primary keys, we have to issue a separate query
// Of course, a modified version of the metaColumnsSQL query using a
// LEFT JOIN would have been much more elegant, but postgres does
// not support OUTER JOINS. So here is the clumsy way.
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$rskey = $this->Execute(sprintf($this->metaKeySQL,($table)));
// fetch all result in once for performance.
$keys =& $rskey->GetArray();
if (isset($savem)) $this->SetFetchMode($savem);
$ADODB_FETCH_MODE = $save;
$rskey->Close();
unset($rskey);
}
$rsdefa = array();
if (!empty($this->metaDefaultsSQL)) {
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$sql = sprintf($this->metaDefaultsSQL, ($table));
$rsdef = $this->Execute($sql);
if (isset($savem)) $this->SetFetchMode($savem);
$ADODB_FETCH_MODE = $save;
if ($rsdef) {
while (!$rsdef->EOF) {
$num = $rsdef->fields['num'];
$s = $rsdef->fields['def'];
if (substr($s, 0, 1) == "'") { /* quoted strings hack... for now... fixme */
$s = substr($s, 1);
$s = substr($s, 0, strlen($s) - 1);
}
$rsdefa[$num] = $s;
$rsdef->MoveNext();
}
} else {
ADOConnection::outp( "==> SQL => " . $sql);
}
unset($rsdef);
}
$retarr = array();
while (!$rs->EOF) {
$fld = new ADOFieldObject();
$fld->name = $rs->fields[0];
$fld->type = $rs->fields[1];
$fld->max_length = $rs->fields[2];
if ($fld->max_length <= 0) $fld->max_length = $rs->fields[3]-4;
if ($fld->max_length <= 0) $fld->max_length = -1;
// dannym
// 5 hasdefault; 6 num-of-column
$fld->has_default = ($rs->fields[5] == 't');
if ($fld->has_default) {
$fld->default_value = $rsdefa[$rs->fields[6]];
}
//Freek
if ($rs->fields[4] == $this->true) {
$fld->not_null = true;
}
// Freek
if (is_array($keys)) {
reset ($keys);
while (list($x,$key) = each($keys)) {
if ($fld->name == $key['column_name'] AND $key['primary_key'] == $this->true)
$fld->primary_key = true;
if ($fld->name == $key['column_name'] AND $key['unique_key'] == $this->true)
$fld->unique = true; // What name is more compatible?
}
}
if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld;
else $retarr[strtoupper($fld->name)] = $fld;
$rs->MoveNext();
}
$rs->Close();
return $retarr;
$rskey->Close();
unset($rskey);
}
return false;
$rsdefa = array();
if (!empty($this->metaDefaultsSQL)) {
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$sql = sprintf($this->metaDefaultsSQL, ($table));
$rsdef = $this->Execute($sql);
if (isset($savem)) $this->SetFetchMode($savem);
$ADODB_FETCH_MODE = $save;
if ($rsdef) {
while (!$rsdef->EOF) {
$num = $rsdef->fields['num'];
$s = $rsdef->fields['def'];
if (substr($s, 0, 1) == "'") { /* quoted strings hack... for now... fixme */
$s = substr($s, 1);
$s = substr($s, 0, strlen($s) - 1);
}
$rsdefa[$num] = $s;
$rsdef->MoveNext();
}
} else {
ADOConnection::outp( "==> SQL => " . $sql);
}
unset($rsdef);
}
$retarr = array();
while (!$rs->EOF) {
$fld = new ADOFieldObject();
$fld->name = $rs->fields[0];
$fld->type = $rs->fields[1];
$fld->max_length = $rs->fields[2];
if ($fld->max_length <= 0) $fld->max_length = $rs->fields[3]-4;
if ($fld->max_length <= 0) $fld->max_length = -1;
// dannym
// 5 hasdefault; 6 num-of-column
$fld->has_default = ($rs->fields[5] == 't');
if ($fld->has_default) {
$fld->default_value = $rsdefa[$rs->fields[6]];
}
//Freek
if ($rs->fields[4] == $this->true) {
$fld->not_null = true;
}
// Freek
if (is_array($keys)) {
foreach($keys as $key) {
if ($fld->name == $key['column_name'] AND $key['primary_key'] == $this->true)
$fld->primary_key = true;
if ($fld->name == $key['column_name'] AND $key['unique_key'] == $this->true)
$fld->unique = true; // What name is more compatible?
}
}
if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld;
else $retarr[($upper) ? strtoupper($fld->name) : $fld->name] = $fld;
$rs->MoveNext();
}
$rs->Close();
return $retarr;
}
function &MetaIndexes ($table, $primary = FALSE)
{
global $ADODB_FETCH_MODE;
$schema = false;
$this->_findschema($table,$schema);
if ($schema) { // requires pgsql 7.3+ - pg_namespace used.
$sql = '
SELECT c.relname as "Name", i.indisunique as "Unique", i.indkey as "Columns"
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_index i ON i.indexrelid=c.oid
JOIN pg_catalog.pg_class c2 ON c2.oid=i.indrelid
,pg_namespace n
WHERE c2.relname=\'%s\' and c.relnamespace=c2.relnamespace and c.relnamespace=n.oid and n.nspname=\'%s\' AND i.indisprimary=false';
} else {
$sql = '
SELECT c.relname as "Name", i.indisunique as "Unique", i.indkey as "Columns"
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_index i ON i.indexrelid=c.oid
JOIN pg_catalog.pg_class c2 ON c2.oid=i.indrelid
WHERE c2.relname=\'%s\'';
}
if ($primary == FALSE) {
$sql .= ' AND i.indisprimary=false;';
}
$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
if ($this->fetchMode !== FALSE) {
$savem = $this->SetFetchMode(FALSE);
}
$rs = $this->Execute(sprintf($sql,$table,$schema));
if (isset($savem)) {
$this->SetFetchMode($savem);
}
$ADODB_FETCH_MODE = $save;
if (!is_object($rs)) {
return FALSE;
}
$col_names = $this->MetaColumnNames($table);
$indexes = array();
while ($row = $rs->FetchRow()) {
$columns = array();
foreach (explode(' ', $row[2]) as $col) {
$columns[] = $col_names[$col - 1];
}
$indexes[$row[0]] = array(
'unique' => ($row[1] == 't'),
'columns' => $columns
);
}
return $indexes;
}
// returns true or false
//
// examples:
@@ -480,6 +558,9 @@ select viewname,'V' from pg_views where viewname like $mask";
// $db->Connect('host1','user1','secret');
function _connect($str,$user='',$pwd='',$db='',$ctype=0)
{
if (!function_exists('pg_pconnect')) return false;
$this->_errorMsg = false;
if ($user || $pwd || $db) {
@@ -687,7 +768,8 @@ class ADORecordSet_postgres64 extends ADORecordSet{
function &GetRowAssoc($upper=true)
{
if ($this->fetchMode == PGSQL_ASSOC && !$upper) return $this->fields;
return ADORecordSet::GetRowAssoc($upper);
$row =& ADORecordSet::GetRowAssoc($upper);
return $row;
}
function _initrs()
@@ -746,14 +828,12 @@ class ADORecordSet_postgres64 extends ADORecordSet{
function _fixblobs()
{
if ($this->fetchMode == PGSQL_NUM || $this->fetchMode == PGSQL_BOTH) {
reset($this->_blobArr);
while(list($k,$v) = each($this->_blobArr)) {
foreach($this->_blobArr as $k => $v) {
$this->fields[$k] = ADORecordSet_postgres64::_decode($this->fields[$k]);
}
}
if ($this->fetchMode == PGSQL_ASSOC || $this->fetchMode == PGSQL_BOTH) {
reset($this->_blobArr);
while(list($k,$v) = each($this->_blobArr)) {
foreach($this->_blobArr as $k => $v) {
$this->fields[$v] = ADORecordSet_postgres64::_decode($this->fields[$v]);
}
}
@@ -766,9 +846,8 @@ class ADORecordSet_postgres64 extends ADORecordSet{
$this->_currentRow++;
if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) {
$this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);
if (is_array($this->fields)) {
if (isset($this->_blobArr)) $this->_fixblobs();
if (is_array($this->fields) && $this->fields) {
if ($this->fields && isset($this->_blobArr)) $this->_fixblobs();
return true;
}
}
@@ -780,11 +859,13 @@ class ADORecordSet_postgres64 extends ADORecordSet{
function _fetch()
{
if ($this->_currentRow >= $this->_numOfRows && $this->_numOfRows >= 0)
return false;
$this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);
if (isset($this->_blobArr)) $this->_fixblobs();
if ($this->fields && isset($this->_blobArr)) $this->_fixblobs();
return (is_array($this->fields));
}
+10 -8
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
@@ -28,12 +28,14 @@ class ADODB_postgres7 extends ADODB_postgres64 {
// which makes obsolete the LIMIT limit,offset syntax
function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0)
{
$offsetStr = ($offset >= 0) ? " OFFSET $offset" : '';
$limitStr = ($nrows >= 0) ? " LIMIT $nrows" : '';
return $secs2cache ?
$this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr)
:
$this->Execute($sql."$limitStr$offsetStr",$inputarr);
$offsetStr = ($offset >= 0) ? " OFFSET $offset" : '';
$limitStr = ($nrows >= 0) ? " LIMIT $nrows" : '';
if ($secs2cache)
$rs =& $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr);
else
$rs =& $this->Execute($sql."$limitStr$offsetStr",$inputarr);
return $rs;
}
/*
function Prepare($sql)
@@ -135,7 +137,7 @@ class ADORecordSet_postgres7 extends ADORecordSet_postgres64{
$this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);
if (is_array($this->fields)) {
if (isset($this->_blobArr)) $this->_fixblobs();
if ($this->fields && isset($this->_blobArr)) $this->_fixblobs();
return true;
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights
version V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). All rights
reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
+11 -5
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
@@ -126,6 +126,8 @@ class ADODB_sqlite extends ADOConnection {
// returns true or false
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
{
if (!function_exists('sqlite_open')) return false;
$this->_connectionID = sqlite_open($argHostname);
if ($this->_connectionID === false) return false;
$this->_createFunctions();
@@ -135,6 +137,8 @@ class ADODB_sqlite extends ADOConnection {
// returns true or false
function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
{
if (!function_exists('sqlite_open')) return false;
$this->_connectionID = sqlite_popen($argHostname);
if ($this->_connectionID === false) return false;
$this->_createFunctions();
@@ -156,10 +160,12 @@ class ADODB_sqlite extends ADOConnection {
{
$offsetStr = ($offset >= 0) ? " OFFSET $offset" : '';
$limitStr = ($nrows >= 0) ? " LIMIT $nrows" : ($offset >= 0 ? ' LIMIT 999999999' : '');
return $secs2cache ?
$this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr)
:
$this->Execute($sql."$limitStr$offsetStr",$inputarr);
if ($secs2cache)
$rs =& $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr);
else
$rs =& $this->Execute($sql."$limitStr$offsetStr",$inputarr);
return $rs;
}
/*
+10 -5
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim. All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 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.
@@ -115,6 +115,8 @@ class ADODB_sybase extends ADOConnection {
// returns true or false
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
{
if (!function_exists('sybase_connect')) return false;
$this->_connectionID = sybase_connect($argHostname,$argUsername,$argPassword);
if ($this->_connectionID === false) return false;
if ($argDatabasename) return $this->SelectDB($argDatabasename);
@@ -123,6 +125,8 @@ class ADODB_sybase extends ADOConnection {
// returns true or false
function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
{
if (!function_exists('sybase_connect')) return false;
$this->_connectionID = sybase_pconnect($argHostname,$argUsername,$argPassword);
if ($this->_connectionID === false) return false;
if ($argDatabasename) return $this->SelectDB($argDatabasename);
@@ -143,14 +147,15 @@ class ADODB_sybase extends ADOConnection {
// See http://www.isug.com/Sybase_FAQ/ASE/section6.2.html#6.2.12
function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0)
{
if ($secs2cache > 0) // we do not cache rowcount, so we have to load entire recordset
return ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
if ($secs2cache > 0) {// we do not cache rowcount, so we have to load entire recordset
$rs =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
return $rs;
}
$cnt = ($nrows > 0) ? $nrows : 0;
if ($offset > 0 && $cnt) $cnt += $offset;
$this->Execute("set rowcount $cnt");
$rs = &ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
$rs =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
$this->Execute("set rowcount 0");
return $rs;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
+35
View File
@@ -0,0 +1,35 @@
<?php
// Catalan language
// contributed by "Josep Lladonosa" jlladono#pie.xtec.es
$ADODB_LANG_ARRAY = array (
'LANG' => 'ca',
DB_ERROR => 'error desconegut',
DB_ERROR_ALREADY_EXISTS => 'ja existeix',
DB_ERROR_CANNOT_CREATE => 'no es pot crear',
DB_ERROR_CANNOT_DELETE => 'no es pot esborrar',
DB_ERROR_CANNOT_DROP => 'no es pot eliminar',
DB_ERROR_CONSTRAINT => 'violació de constraint',
DB_ERROR_DIVZERO => 'divisió per zero',
DB_ERROR_INVALID => 'no és vàlid',
DB_ERROR_INVALID_DATE => 'la data o l\'hora no són vàlides',
DB_ERROR_INVALID_NUMBER => 'el nombre no és vàlid',
DB_ERROR_MISMATCH => 'no hi ha coincidència',
DB_ERROR_NODBSELECTED => 'cap base de dades seleccionada',
DB_ERROR_NOSUCHFIELD => 'camp inexistent',
DB_ERROR_NOSUCHTABLE => 'taula inexistent',
DB_ERROR_NOT_CAPABLE => 'l\'execució secundària de DB no pot',
DB_ERROR_NOT_FOUND => 'no trobat',
DB_ERROR_NOT_LOCKED => 'no blocat',
DB_ERROR_SYNTAX => 'error de sintaxi',
DB_ERROR_UNSUPPORTED => 'no suportat',
DB_ERROR_VALUE_COUNT_ON_ROW => 'el nombre de columnes no coincideix amb el nombre de valors en la fila',
DB_ERROR_INVALID_DSN => 'el DSN no és vàlid',
DB_ERROR_CONNECT_FAILED => 'connexió fallida',
0 => 'cap error', // DB_OK
DB_ERROR_NEED_MORE_DATA => 'les dades subministrades són insuficients',
DB_ERROR_EXTENSION_NOT_FOUND=> 'extensió no trobada',
DB_ERROR_NOSUCHDB => 'base de dades inexistent',
DB_ERROR_ACCESS_VIOLATION => 'permisos insuficients'
);
?>
+35
View File
@@ -0,0 +1,35 @@
<?php
// Chinese language file contributed by "Cuiyan (cysoft)" cysoft#php.net.
// Encode by GB2312
// Simplified Chinese
$ADODB_LANG_ARRAY = array (
'LANG' => 'cn',
DB_ERROR => '未知错误',
DB_ERROR_ALREADY_EXISTS => '已经存在',
DB_ERROR_CANNOT_CREATE => '不能创建',
DB_ERROR_CANNOT_DELETE => '不能删除',
DB_ERROR_CANNOT_DROP => '不能丢弃',
DB_ERROR_CONSTRAINT => '约束限制',
DB_ERROR_DIVZERO => '被0除',
DB_ERROR_INVALID => '无效',
DB_ERROR_INVALID_DATE => '无效的日期或者时间',
DB_ERROR_INVALID_NUMBER => '无效的数字',
DB_ERROR_MISMATCH => '不匹配',
DB_ERROR_NODBSELECTED => '没有数据库被选择',
DB_ERROR_NOSUCHFIELD => '没有相应的字段',
DB_ERROR_NOSUCHTABLE => '没有相应的表',
DB_ERROR_NOT_CAPABLE => '数据库后台不兼容',
DB_ERROR_NOT_FOUND => '没有发现',
DB_ERROR_NOT_LOCKED => '没有被锁定',
DB_ERROR_SYNTAX => '语法错误',
DB_ERROR_UNSUPPORTED => '不支持',
DB_ERROR_VALUE_COUNT_ON_ROW => '在行上累计值',
DB_ERROR_INVALID_DSN => '无效的数据源 (DSN)',
DB_ERROR_CONNECT_FAILED => '连接失败',
0 => '没有错误', // DB_OK
DB_ERROR_NEED_MORE_DATA => '提供的数据不能符合要求',
DB_ERROR_EXTENSION_NOT_FOUND=> '扩展没有被发现',
DB_ERROR_NOSUCHDB => '没有相应的数据库',
DB_ERROR_ACCESS_VIOLATION => '没有合适的权限'
);
?>
+33
View File
@@ -0,0 +1,33 @@
<?php
// contributed by "Heinz Hombergs" <[email protected]>
$ADODB_LANG_ARRAY = array (
'LANG' => 'de',
DB_ERROR => 'Unbekannter Fehler',
DB_ERROR_ALREADY_EXISTS => 'existiert bereits',
DB_ERROR_CANNOT_CREATE => 'kann nicht erstellen',
DB_ERROR_CANNOT_DELETE => 'kann nicht l&ouml;schen',
DB_ERROR_CANNOT_DROP => 'Tabelle oder Index konnte nicht gel&ouml;scht werden',
DB_ERROR_CONSTRAINT => 'Constraint Verletzung',
DB_ERROR_DIVZERO => 'Division durch Null',
DB_ERROR_INVALID => 'ung&uml;ltig',
DB_ERROR_INVALID_DATE => 'ung&uml;ltiges Datum oder Zeit',
DB_ERROR_INVALID_NUMBER => 'ung&uml;ltige Zahl',
DB_ERROR_MISMATCH => 'Unvertr&auml;glichkeit',
DB_ERROR_NODBSELECTED => 'keine Dantebank ausgew&auml;hlt',
DB_ERROR_NOSUCHFIELD => 'Feld nicht vorhanden',
DB_ERROR_NOSUCHTABLE => 'Tabelle nicht vorhanden',
DB_ERROR_NOT_CAPABLE => 'Funktion nicht installiert',
DB_ERROR_NOT_FOUND => 'nicht gefunden',
DB_ERROR_NOT_LOCKED => 'nicht gesperrt',
DB_ERROR_SYNTAX => 'Syntaxfehler',
DB_ERROR_UNSUPPORTED => 'nicht Unterst&uml;tzt',
DB_ERROR_VALUE_COUNT_ON_ROW => 'Anzahl der zur&uml;ckgelieferten Felder entspricht nicht der Anzahl der Felder in der Abfrage',
DB_ERROR_INVALID_DSN => 'ung&uml;ltiger DSN',
DB_ERROR_CONNECT_FAILED => 'Verbindung konnte nicht hergestellt werden',
0 => 'kein Fehler', // DB_OK
DB_ERROR_NEED_MORE_DATA => 'Nicht gen&uml;gend Daten geliefert',
DB_ERROR_EXTENSION_NOT_FOUND=> 'erweiterung nicht gefunden',
DB_ERROR_NOSUCHDB => 'keine Datenbank',
DB_ERROR_ACCESS_VIOLATION => 'ungen&uml;gende Rechte'
);
?>
+1 -1
View File
@@ -28,6 +28,6 @@ $ADODB_LANG_ARRAY = array (
DB_ERROR_NEED_MORE_DATA => 'donn&eacute;es fournies insuffisantes',
DB_ERROR_EXTENSION_NOT_FOUND=> 'extension non trouv&eacute;e',
DB_ERROR_NOSUCHDB => 'base de donn&eacute;es inconnue',
DB_ERROR_ACCESS_VIOLATION => 'droits ynsuffisants'
DB_ERROR_ACCESS_VIOLATION => 'droits insuffisants'
);
?>
+4 -4
View File
@@ -8,10 +8,10 @@ $ADODB_LANG_ARRAY = array (
DB_ERROR_CANNOT_CREATE => 'non posso creare',
DB_ERROR_CANNOT_DELETE => 'non posso cancellare',
DB_ERROR_CANNOT_DROP => 'non posso eliminare',
DB_ERROR_CONSTRAINT => 'viiolazione constraint',
DB_ERROR_CONSTRAINT => 'violazione constraint',
DB_ERROR_DIVZERO => 'divisione per zero',
DB_ERROR_INVALID => 'non valido',
DB_ERROR_INVALID_DATE => 'date od ora non valido',
DB_ERROR_INVALID_DATE => 'data od ora non valida',
DB_ERROR_INVALID_NUMBER => 'numero non valido',
DB_ERROR_MISMATCH => 'diversi',
DB_ERROR_NODBSELECTED => 'nessun database selezionato',
@@ -26,9 +26,9 @@ $ADODB_LANG_ARRAY = array (
DB_ERROR_INVALID_DSN => 'DSN non valido',
DB_ERROR_CONNECT_FAILED => 'connessione fallita',
0 => 'nessun errore', // DB_OK
DB_ERROR_NEED_MORE_DATA => 'dati inseriti insufficenti',
DB_ERROR_NEED_MORE_DATA => 'dati inseriti insufficienti',
DB_ERROR_EXTENSION_NOT_FOUND=> 'estensione non trovata',
DB_ERROR_NOSUCHDB => 'database non trovato',
DB_ERROR_ACCESS_VIOLATION => 'permessi insufficenti'
DB_ERROR_ACCESS_VIOLATION => 'permessi insufficienti'
);
?>
+19 -4
View File
@@ -13,12 +13,27 @@ All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the John Lim nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list
of conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.
Neither the name of the John Lim nor the names of its contributors may be used to
endorse or promote products derived from this software without specific prior written
permission.
DISCLAIMER:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
JOHN LIM OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
==========================================================
GNU LESSER GENERAL PUBLIC LICENSE
+12 -2
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
@@ -59,9 +59,19 @@ class perf_db2 extends adodb_perf{
$this->conn =& $conn;
}
function Explain($sql)
function Explain($sql,$partial=false)
{
$save = $this->conn->LogSQL(false);
if ($partial) {
$sqlq = $this->conn->qstr($sql.'%');
$arr = $this->conn->GetArray("select distinct sql1 from adodb_logsql where sql1 like $sqlq");
if ($arr) {
foreach($arr as $row) {
$sql = reset($row);
if (crc32($sql) == $partial) break;
}
}
}
$qno = rand();
$ok = $this->conn->Execute("EXPLAIN PLAN SET QUERYNO=$qno FOR $sql");
ob_start();
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
+16 -3
View File
@@ -1,7 +1,7 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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,8 +71,21 @@ class perf_mssql extends adodb_perf{
$this->conn =& $conn;
}
function Explain($sql)
function Explain($sql,$partial=false)
{
$save = $this->conn->LogSQL(false);
if ($partial) {
$sqlq = $this->conn->qstr($sql.'%');
$arr = $this->conn->GetArray("select distinct sql1 from adodb_logsql where sql1 like $sqlq");
if ($arr) {
foreach($arr as $row) {
$sql = reset($row);
if (crc32($sql) == $partial) break;
}
}
}
$s = '<p><b>Explain</b>: '.htmlspecialchars($sql).'</p>';
$this->conn->Execute("SET SHOWPLAN_ALL ON;");
$sql = str_replace('?',"''",$sql);
@@ -96,7 +109,7 @@ class perf_mssql extends adodb_perf{
}
$this->conn->Execute("SET SHOWPLAN_ALL OFF;");
$this->conn->LogSQL($save);
$s .= $this->Tracer($sql);
return $s;
}
+24 -3
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
@@ -83,13 +83,32 @@ class perf_mysql extends adodb_perf{
$this->conn =& $conn;
}
function Explain($sql)
function Explain($sql,$partial=false)
{
if (strtoupper(substr(trim($sql),0,6)) !== 'SELECT') return '<p>Unable to EXPLAIN non-select statement</p>';
$save = $this->conn->LogSQL(false);
if ($partial) {
$sqlq = $this->conn->qstr($sql.'%');
$arr = $this->conn->GetArray("select distinct sql1 from adodb_logsql where sql1 like $sqlq");
if ($arr) {
foreach($arr as $row) {
$sql = reset($row);
if (crc32($sql) == $partial) break;
}
}
}
$sql = str_replace('?',"''",$sql);
if ($partial) {
$sqlq = $this->conn->qstr($sql.'%');
$sql = $this->conn->GetOne("select sql1 from adodb_logsql where sql1 like $sqlq");
}
$s = '<p><b>Explain</b>: '.htmlspecialchars($sql).'</p>';
$rs = $this->conn->Execute('EXPLAIN '.$sql);
$s .= rs2html($rs,false,false,false,false);
$this->conn->LogSQL($save);
$s .= $this->Tracer($sql);
return $s;
}
@@ -207,7 +226,9 @@ class perf_mysql extends adodb_perf{
{
global $HTTP_SESSION_VARS;
$stat = $this->conn->GetOne('show innodb status');
$rs = $this->conn->Execute('show innodb status');
if (!$rs || $rs->EOF) return 0;
$stat = $rs->fields[0];
$at = strpos($stat,'Buffer pool hit rate');
$stat = substr($stat,$at,200);
if (preg_match('!Buffer pool hit rate\s*([0-9]*) / ([0-9]*)!',$stat,$arr)) {
+36 -11
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
@@ -47,6 +47,15 @@ class perf_oci8 extends ADODB_perf{
sum(getmisses))))*100,2)
from v\$rowcache",
'increase <i>shared_pool_size</i> if too ratio low'),
'memory sort ratio' => array('RATIOH',
"SELECT ROUND((100 * b.VALUE) /DECODE ((a.VALUE + b.VALUE),
0,1,(a.VALUE + b.VALUE)),2)
FROM v\$sysstat a,
v\$sysstat b
WHERE a.name = 'sorts (disk)'
AND b.name = 'sorts (memory)'",
"% of memory sorts compared to disk sorts - should be over 95%"),
'IO',
'data reads' => array('IO',
@@ -176,7 +185,7 @@ class perf_oci8 extends ADODB_perf{
return reset($rs->fields);
}
function Explain($sql)
function Explain($sql,$partial=false)
{
$savelog = $this->conn->LogSQL(false);
$rs =& $this->conn->SelectLimit("select ID FROM PLAN_TABLE");
@@ -216,6 +225,17 @@ CREATE TABLE PLAN_TABLE (
$rs->Close();
// $this->conn->debug=1;
if ($partial) {
$sqlq = $this->conn->qstr($sql.'%');
$arr = $this->conn->GetArray("select distinct distinct sql1 from adodb_logsql where sql1 like $sqlq");
if ($arr) {
foreach($arr as $row) {
$sql = reset($row);
if (crc32($sql) == $partial) break;
}
}
}
$s = "<p><b>Explain</b>: ".htmlspecialchars($sql)."</p>";
$this->conn->BeginTrans();
@@ -239,7 +259,7 @@ CONNECT BY prior id=parent_id and statement_id='$id'");
$s .= rs2html($rs,false,false,false,false);
$this->conn->RollbackTrans();
$this->conn->LogSQL($savelog);
$s .= $this->Tracer($sql);
$s .= $this->Tracer($sql,$partial);
return $s;
}
@@ -256,17 +276,18 @@ select a.size_for_estimate as cache_mb_estimate,
'- BETTER - '
else ' ' end as currsize,
a.estd_physical_read_factor-b.estd_physical_read_factor as best_when_0
from (select size_for_estimate,size_factor,estd_physical_read_factor,rownum r from v\$conn_cache_advice) a ,
(select size_for_estimate,size_factor,estd_physical_read_factor,rownum r from v\$conn_cache_advice) b where a.r = b.r-1");
from (select size_for_estimate,size_factor,estd_physical_read_factor,rownum r from v\$db_cache_advice) a ,
(select size_for_estimate,size_factor,estd_physical_read_factor,rownum r from v\$db_cache_advice) b where a.r = b.r-1");
if (!$rs) return false;
/*
The v$conn_cache_advice utility show the marginal changes in physical data block reads for different sizes of db_cache_size
The v$db_cache_advice utility show the marginal changes in physical data block reads for different sizes of db_cache_size
*/
$s = "<h3>Data Cache Estimate</h3>";
if ($rs->EOF) {
$s .= "<p>Cache that is 50% of current size is still too big</p>";
} else {
$s .= "Ideal size of Data Cache is when \"best_when_0\" changes from a positive number and becomes zero.";
$s .= rs2html($rs,false,false,false,false);
}
return $s;
@@ -360,7 +381,8 @@ order by
global $ADODB_CACHE_MODE,$HTTP_GET_VARS;
if (isset($HTTP_GET_VARS['expsixora']) && isset($HTTP_GET_VARS['sql'])) {
echo "<a name=explain></a>".$this->Explain($HTTP_GET_VARS['sql'])."\n";
$partial = empty($HTTP_GET_VARS['part']);
echo "<a name=explain></a>".$this->Explain($HTTP_GET_VARS['sql'],$partial)."\n";
}
if (isset($HTTP_GET_VARS['sql'])) return $this->_SuspiciousSQL();
@@ -385,7 +407,7 @@ order by
// code thanks to Ixora.
// http://www.ixora.com.au/scripts/query_opt.htm
// requires oracle 8.1.7 or later
function& ExpensiveSQL($numsql = 10)
function ExpensiveSQL($numsql = 10)
{
$sql = "
select
@@ -424,11 +446,14 @@ order by
";
global $ADODB_CACHE_MODE,$HTTP_GET_VARS;
if (isset($HTTP_GET_VARS['expeixora']) && isset($HTTP_GET_VARS['sql'])) {
echo "<a name=explain></a>".$this->Explain($HTTP_GET_VARS['sql'])."\n";
$partial = empty($HTTP_GET_VARS['part']);
echo "<a name=explain></a>".$this->Explain($HTTP_GET_VARS['sql'],$partial)."\n";
}
if (isset($HTTP_GET_VARS['sql'])) return $this->_ExpensiveSQL();
if (isset($HTTP_GET_VARS['sql'])) {
$var =& $this->_ExpensiveSQL();
return $var;
}
$save = $ADODB_CACHE_MODE;
$ADODB_CACHE_MODE = ADODB_FETCH_NUM;
$savelog = $this->conn->LogSQL(false);
+15 -4
View File
@@ -1,7 +1,7 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
@@ -88,10 +88,21 @@ class perf_postgres extends adodb_perf{
$this->conn =& $conn;
}
function Explain($sql)
function Explain($sql,$partial=false)
{
$sql = str_replace('?',"''",$sql);
$save = $this->conn->LogSQL(false);
if ($partial) {
$sqlq = $this->conn->qstr($sql.'%');
$arr = $this->conn->GetArray("select distinct distinct sql1 from adodb_logsql where sql1 like $sqlq");
if ($arr) {
foreach($arr as $row) {
$sql = reset($row);
if (crc32($sql) == $partial) break;
}
}
}
$sql = str_replace('?',"''",$sql);
$s = '<p><b>Explain</b>: '.htmlspecialchars($sql).'</p>';
$rs = $this->conn->Execute('EXPLAIN '.$sql);
$this->conn->LogSQL($save);
@@ -102,7 +113,7 @@ class perf_postgres extends adodb_perf{
$rs->MoveNext();
}
$s .= '</pre>';
$s .= $this->Tracer($sql);
$s .= $this->Tracer($sql,$partial);
return $s;
}
}
+3 -2
View File
@@ -1,6 +1,6 @@
<?php
/**
* @version V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
* @version V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
@@ -71,7 +71,8 @@
if ($showcount)
$sel .= "\n\tSUM(1) as Total";
else
$sel = substr($sel,0,strlen($sel)-2);
$sql = "SELECT $sel \nFROM $tables $where \nGROUP BY $rowfields";
return $sql;
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/**
* @version V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
* @version V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
* @version V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
+120
View File
@@ -0,0 +1,120 @@
<?php
// $CVSHeader$
/*
V4.01 23 Oct 2003 (c) 2000-2004 John Lim ([email protected]). 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.
*/
if (!function_exists('bzcompress')) {
trigger_error('bzip2 functions are not available', E_USER_ERROR);
return 0;
}
/*
*/
class ADODB_Compress_Bzip2 {
/**
*/
var $_block_size = null;
/**
*/
var $_work_level = null;
/**
*/
var $_min_length = 1;
/**
*/
function getBlockSize() {
return $this->_block_size;
}
/**
*/
function setBlockSize($block_size) {
assert('$block_size >= 1');
assert('$block_size <= 9');
$this->_block_size = (int) $block_size;
}
/**
*/
function getWorkLevel() {
return $this->_work_level;
}
/**
*/
function setWorkLevel($work_level) {
assert('$work_level >= 0');
assert('$work_level <= 250');
$this->_work_level = (int) $work_level;
}
/**
*/
function getMinLength() {
return $this->_min_length;
}
/**
*/
function setMinLength($min_length) {
assert('$min_length >= 0');
$this->_min_length = (int) $min_length;
}
/**
*/
function ADODB_Compress_Bzip2($block_size = null, $work_level = null, $min_length = null) {
if (!is_null($block_size)) {
$this->setBlockSize($block_size);
}
if (!is_null($work_level)) {
$this->setWorkLevel($work_level);
}
if (!is_null($min_length)) {
$this->setMinLength($min_length);
}
}
/**
*/
function write($data, $key) {
if (strlen($data) < $this->_min_length) {
return $data;
}
if (!is_null($this->_block_size)) {
if (!is_null($this->_work_level)) {
return bzcompress($data, $this->_block_size, $this->_work_level);
} else {
return bzcompress($data, $this->_block_size);
}
}
return bzcompress($data);
}
/**
*/
function read($data, $key) {
return $data ? bzdecompress($data) : $data;
}
}
return 1;
?>
+94
View File
@@ -0,0 +1,94 @@
<?php
// $CVSHeader$
/*
V4.01 23 Oct 2003 (c) 2000-2004 John Lim ([email protected]). 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.
*/
if (!function_exists('gzcompress')) {
trigger_error('gzip functions are not available', E_USER_ERROR);
return 0;
}
/*
*/
class ADODB_Compress_Gzip {
/**
*/
var $_level = null;
/**
*/
var $_min_length = 1;
/**
*/
function getLevel() {
return $this->_level;
}
/**
*/
function setLevel($level) {
assert('$level >= 0');
assert('$level <= 9');
$this->_level = (int) $level;
}
/**
*/
function getMinLength() {
return $this->_min_length;
}
/**
*/
function setMinLength($min_length) {
assert('$min_length >= 0');
$this->_min_length = (int) $min_length;
}
/**
*/
function ADODB_Compress_Gzip($level = null, $min_length = null) {
if (!is_null($level)) {
$this->setLevel($level);
}
if (!is_null($min_length)) {
$this->setMinLength($min_length);
}
}
/**
*/
function write($data, $key) {
if (strlen($data) < $this->_min_length) {
return $data;
}
if (!is_null($this->_level)) {
return gzcompress($data, $this->_level);
} else {
return gzcompress($data);
}
}
/**
*/
function read($data, $key) {
return $data ? gzuncompress($data) : $data;
}
}
return 1;
?>
+25
View File
@@ -0,0 +1,25 @@
<?php
// $CVSHeader$
/*
V4.01 23 Oct 2003 (c) 2000-2004 John Lim ([email protected]). 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
*/
require_once dirname(__FILE__) . '/adodb-session.php';
require_once ADODB_SESSION . '/adodb-encrypt-md5.php';
ADODB_Session::filter(new ADODB_Encrypt_MD5());
?>
+110
View File
@@ -0,0 +1,110 @@
<?php
// $CVSHeader$
/*
V4.01 23 Oct 2003 (c) 2000-2004 John Lim ([email protected]). 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.
*/
if (!function_exists('mcrypt_encrypt')) {
trigger_error('Mcrypt functions are not available', E_USER_ERROR);
return 0;
}
/**
*/
class ADODB_Encrypt_MCrypt {
/**
*/
var $_cipher;
/**
*/
var $_mode;
/**
*/
var $_source;
/**
*/
function getCipher() {
return $this->_cipher;
}
/**
*/
function setCipher($cipher) {
$this->_cipher = $cipher;
}
/**
*/
function getMode() {
return $this->_mode;
}
/**
*/
function setMode($mode) {
$this->_mode = $mode;
}
/**
*/
function getSource() {
return $this->_source;
}
/**
*/
function setSource($source) {
$this->_source = $source;
}
/**
*/
function ADODB_Encrypt_MCrypt($cipher = null, $mode = null, $source = null) {
if (!$cipher) {
$cipher = MCRYPT_RIJNDAEL_256;
}
if (!$mode) {
$mode = MCRYPT_MODE_ECB;
}
if (!$source) {
$source = MCRYPT_RAND;
}
$this->_cipher = $cipher;
$this->_mode = $mode;
$this->_source = $source;
}
/**
*/
function write($data, $key) {
$iv_size = mcrypt_get_iv_size($this->_cipher, $this->_mode);
$iv = mcrypt_create_iv($iv_size, $this->_source);
return mcrypt_encrypt($this->_cipher, $key, $data, $this->_mode, $iv);
}
/**
*/
function read($data, $key) {
$iv_size = mcrypt_get_iv_size($this->_cipher, $this->_mode);
$iv = mcrypt_create_iv($iv_size, $this->_source);
$rv = mcrypt_decrypt($this->_cipher, $key, $data, $this->_mode, $iv);
return rtrim($rv, "\0");
}
}
return 1;
?>
+38
View File
@@ -0,0 +1,38 @@
<?php
// $CVSHeader$
/*
V4.01 23 Oct 2003 (c) 2000-2004 John Lim ([email protected]). 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.
*/
include_once ADODB_SESSION . '/crypt.inc.php';
/**
*/
class ADODB_Encrypt_MD5 {
/**
*/
function write($data, $key) {
$md5crypt =& new MD5Crypt();
return $md5crypt->encrypt($data, $key);
}
/**
*/
function read($data, $key) {
$md5crypt =& new MD5Crypt();
return $md5crypt->decrypt($data, $key);
}
}
return 1;
?>
@@ -0,0 +1,50 @@
<?php
// $CVSHeader$
/*
V4.01 23 Oct 2003 (c) 2000-2004 John Lim ([email protected]). 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.
*/
@define('HORDE_BASE', dirname(dirname(dirname(__FILE__))) . '/horde');
if (!is_dir(HORDE_BASE)) {
trigger_error(sprintf('Directory not found: \'%s\'', HORDE_BASE), E_USER_ERROR);
return 0;
}
include_once HORDE_BASE . '/lib/Horde.php';
include_once HORDE_BASE . '/lib/Secret.php';
/**
NOTE: On Windows 2000 SP4 with PHP 4.3.1, MCrypt 2.4.x, and Apache 1.3.28,
the session didn't work properly.
This may be resolved with 4.3.3.
*/
class ADODB_Encrypt_Secret {
/**
*/
function write($data, $key) {
return Secret::write($key, $data);
}
/**
*/
function read($data, $key) {
return Secret::read($key, $data);
}
}
return 1;
?>
+131
View File
@@ -0,0 +1,131 @@
John,
I have been an extremely satisfied ADODB user for several years now.
To give you something back for all your hard work, I've spent the last 3
days rewriting the adodb-session.php code.
----------
What's New
----------
Here's a list of the new code's benefits:
* Combines the functionality of the three files:
adodb-session.php
adodb-session-clob.php
adodb-cryptsession.php
each with very similar functionality, into a single file adodb-session.php.
This will ease maintenance and support issues.
* Supports multiple encryption and compression schemes.
Currently, we support:
MD5Crypt (crypt.inc.php)
MCrypt
Secure (Horde's emulation of MCrypt, if MCrypt module is not available.)
GZip
BZip2
These can be stacked, so if you want to compress and then encrypt your
session data, it's easy.
Also, the built-in MCrypt functions will be *much* faster, and more secure,
than the MD5Crypt code.
* adodb-session.php contains a single class ADODB_Session that encapsulates
all functionality.
This eliminates the use of global vars and defines (though they are
supported for backwards compatibility).
* All user defined parameters are now static functions in the ADODB_Session
class.
New parameters include:
* encryptionKey(): Define the encryption key used to encrypt the session.
Originally, it was a hard coded string.
* persist(): Define if the database will be opened in persistent mode.
Originally, the user had to call adodb_sess_open().
* dataFieldName(): Define the field name used to store the session data, as
'DATA' appears to be a reserved word in the following cases:
ANSI SQL
IBM DB2
MS SQL Server
Postgres
SAP
* filter(): Used to support multiple, simulataneous encryption/compression
schemes.
* Debug support is improved thru _rsdump() function, which is called after
every database call.
------------
What's Fixed
------------
The new code includes several bug fixes and enhancements:
* sesskey is compared in BINARY mode for MySQL, to avoid problems with
session keys that differ only by case.
Of course, the user should define the sesskey field as BINARY, to
correctly fix this problem, otherwise performance will suffer.
* In ADODB_Session::gc(), if $expire_notify is true, the multiple DELETES in
the original code have been optimized to a single DELETE.
* In ADODB_Session::destroy(), since "SELECT expireref, sesskey FROM $table
WHERE sesskey = $qkey" will only return a single value, we don't loop on the
result, we simply process the row, if any.
* We close $rs after every use.
---------------
What's the Same
---------------
I know backwards compatibility is *very* important to you. Therefore, the
new code is 100% backwards compatible.
If you like my code, but don't "trust" it's backwards compatible, maybe we
offer it as beta code, in a new directory for a release or two?
------------
What's To Do
------------
I've vascillated over whether to use a single function to get/set
parameters:
$user = ADODB_Session::user(); // get
ADODB_Session::user($user); // set
or to use separate functions (which is the PEAR/Java way):
$user = ADODB_Session::getUser();
ADODB_Session::setUser($user);
I've chosen the former as it's makes for a simpler API, and reduces the
amount of code, but I'd be happy to change it to the latter.
Also, do you think the class should be a singleton class, versus a static
class?
Let me know if you find this code useful, and will be including it in the
next release of ADODB.
If so, I will modify the current documentation to detail the new
functionality. To that end, what file(s) contain the documentation? Please
send them to me if they are not publically available.
Also, if there is *anything* in the code that you like to see changed, let
me know.
Thanks,
Ross
+24
View File
@@ -0,0 +1,24 @@
<?php
// $CVSHeader$
/*
V4.01 23 Oct 2003 (c) 2000-2004 John Lim ([email protected]). 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
*/
require_once dirname(__FILE__) . '/adodb-session.php';
ADODB_Session::clob('CLOB');
?>
+817
View File
@@ -0,0 +1,817 @@
<?php
// $CVSHeader$
/*
V4.01 23 Oct 2003 (c) 2000-2004 John Lim ([email protected]). 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.
*/
/*
You may want to rename the 'data' field to 'session_data' as
'data' appears to be a reserved word for one or more of the following:
ANSI SQL
IBM DB2
MS SQL Server
Postgres
SAP
If you do, then execute:
ADODB_Session::dataFieldName('session_data');
*/
if (!defined('_ADODB_LAYER')) {
require_once realpath(dirname(__FILE__) . '/../adodb.inc.php');
}
if (defined('ADODB_SESSION')) return 1;
define('ADODB_SESSION', dirname(__FILE__));
/*!
\static
*/
class ADODB_Session {
/////////////////////
// getter/setter methods
/////////////////////
/*!
*/
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 = 'xphplens_2';
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 = 'sessions';
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) {
static $_sync_seconds = 60;
static $set = false;
if (!is_null($sync_seconds)) {
$_sync_seconds = (int) $sync_seconds;
$set = true;
} elseif (!$set) {
// backwards compatibility
if (defined('ADODB_SESSION_SYNCH_SECS')) {
return ADODB_SESSION_SYNCH_SECS;
}
}
return $_sync_seconds;
}
/*!
*/
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) {
static $_data_field_name = 'data';
if (!is_null($data_field_name)) {
$_data_field_name = trim($data_field_name);
}
return $_data_field_name;
}
/*!
*/
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
/////////////////////
/*!
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)) {
$persist = (bool) $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');
// cannot use =& below - do not know why...
$conn = ADONewConnection($driver);
if ($debug) {
$conn->debug = true;
// ADOConnection::outp( " driver=$driver user=$user pwd=$password db=$database ");
}
if ($persist) {
$ok = $conn->PConnect($host, $user, $password, $database);
} 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();
$data = ADODB_Session::dataFieldName();
$filter = ADODB_Session::filter();
$table = ADODB_Session::table();
if (!$conn) {
return '';
}
assert('$table');
$qkey = $conn->quote($key);
$binary = $conn->dataProvider === 'mysql' ? '/*! BINARY */' : '';
$sql = "SELECT $data FROM $table WHERE $binary sesskey = $qkey AND expiry >= " . time();
$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) {
$clob = ADODB_Session::clob();
$conn =& ADODB_Session::_conn();
$crc = ADODB_Session::_crc();
$data = ADODB_Session::dataFieldName();
$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;
}
assert('$table');
$expiry = time() + $lifetime;
$qkey = $conn->quote($key);
$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>';
}
$sql = "UPDATE $table SET expiry = $expiry WHERE $binary sesskey = $qkey AND expiry >= " . time();
$rs =& $conn->Execute($sql);
ADODB_Session::_dumprs($rs);
if ($rs) {
$rs->Close();
}
return true;
}
$val = rawurlencode($val);
foreach ($filter as $f) {
if (is_object($f)) {
$val = $f->write($val, ADODB_Session::_sessionKey());
}
}
$arr = array('sesskey' => $key, 'expiry' => $expiry, $data => $val, 'expireref' => '');
if ($expire_notify) {
$var = reset($expire_notify);
global $$var;
if (isset($$var)) {
$arr['expireref'] = $$var;
}
}
if (!$clob) { // no lobs, simply use replace()
$rs = $conn->Replace($table, $arr, 'sesskey', $autoQuote = true);
ADODB_Session::_dumprs($rs);
} 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;
}
// 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";
} else {
$sql = "INSERT INTO $table (expiry, $data, sesskey) VALUES ($expiry, $lob_value, $qkey)";
}
if ($rs) {
$rs->Close();
}
$err = '';
$rs1 =& $conn->Execute($sql);
ADODB_Session::_dumprs($rs1);
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";
}
$rs = ($rs && $rs2) ? true : false;
if ($rs1) {
$rs1->Close();
}
if (is_object($rs2)) {
$rs2->Close();
}
}
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();
}
}
}
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();
$sync_seconds = ADODB_Session::syncSeconds();
$table = ADODB_Session::table();
if (!$conn) {
return false;
}
assert('$table');
$time = time();
$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->BeginTrans();
$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'");
$rs->MoveNext();
}
$rs->Close();
$conn->CommitTrans();
}
} 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);
}
}
if ($sync_seconds) {
$sql = 'SELECT ';
if ($conn->dataProvider === 'oci8') {
$sql .= "TO_CHAR({$conn->sysTimeStamp}, 'RRRR-MM-DD HH24:MI:SS')";
} else {
$sql .= $conn->sysTimeStamp;
}
$sql .= " FROM $table";
$rs =& $conn->SelectLimit($sql, 1);
if ($rs && !$rs->EOF) {
$dbts = reset($rs->fields);
$rs->Close();
$dbt = $conn->UnixTimeStamp($dbts);
$t = time();
if (abs($dbt - $t) >= $sync_seconds) {
global $HTTP_SERVER_VARS;
$msg = __FILE__ .
": Server time for webserver {$HTTP_SERVER_VARS['HTTP_HOST']} not in synch with database: " .
" database=$dbt ($dbts), webserver=$t (diff=". (abs($dbt - $t) / 3600) . ' hours)';
error_log($msg);
if ($debug) {
ADOConnection::outp("<p>$msg</p>");
}
}
}
}
return true;
}
}
ADODB_Session::_init();
// 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,16 @@
-- $CVSHeader$
CREATE DATABASE /*! IF NOT EXISTS */ adodb_sessions;
USE adodb_sessions;
DROP TABLE /*! IF EXISTS */ sessions;
CREATE TABLE /*! IF NOT EXISTS */ sessions (
sesskey CHAR(32) /*! BINARY */ NOT NULL DEFAULT '',
expiry INT(11) /*! UNSIGNED */ NOT NULL DEFAULT 0,
expireref VARCHAR(64) DEFAULT '',
data LONGTEXT DEFAULT '',
PRIMARY KEY (sesskey),
INDEX expiry (expiry)
);
@@ -0,0 +1,15 @@
-- $CVSHeader$
DROP TABLE adodb_sessions;
CREATE TABLE sessions (
sesskey CHAR(32) DEFAULT '' NOT NULL,
expiry INT DEFAULT 0 NOT NULL,
expireref VARCHAR(64) DEFAULT '',
data CLOB DEFAULT '',
PRIMARY KEY (sesskey)
);
CREATE INDEX ix_expiry ON sessions (expiry);
QUIT;
@@ -0,0 +1,16 @@
-- $CVSHeader$
DROP TABLE adodb_sessions;
CREATE TABLE sessions (
sesskey CHAR(32) DEFAULT '' NOT NULL,
expiry INT DEFAULT 0 NOT NULL,
expireref VARCHAR(64) DEFAULT '',
data VARCHAR(4000) DEFAULT '',
PRIMARY KEY (sesskey),
INDEX expiry (expiry)
);
CREATE INDEX ix_expiry ON sessions (expiry);
QUIT;
+64
View File
@@ -0,0 +1,64 @@
<?php
// Session Encryption by Ari Kuorikoski <[email protected]>
class MD5Crypt{
function keyED($txt,$encrypt_key)
{
$encrypt_key = md5($encrypt_key);
$ctr=0;
$tmp = "";
for ($i=0;$i<strlen($txt);$i++){
if ($ctr==strlen($encrypt_key)) $ctr=0;
$tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1);
$ctr++;
}
return $tmp;
}
function Encrypt($txt,$key)
{
srand((double)microtime()*1000000);
$encrypt_key = md5(rand(0,32000));
$ctr=0;
$tmp = "";
for ($i=0;$i<strlen($txt);$i++)
{
if ($ctr==strlen($encrypt_key)) $ctr=0;
$tmp.= substr($encrypt_key,$ctr,1) .
(substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
$ctr++;
}
return base64_encode($this->keyED($tmp,$key));
}
function Decrypt($txt,$key)
{
$txt = $this->keyED(base64_decode($txt),$key);
$tmp = "";
for ($i=0;$i<strlen($txt);$i++){
$md5 = substr($txt,$i,1);
$i++;
$tmp.= (substr($txt,$i,1) ^ $md5);
}
return $tmp;
}
function RandPass()
{
$randomPassword = "";
srand((double)microtime()*1000000);
for($i=0;$i<8;$i++)
{
$randnumber = rand(48,120);
while (($randnumber >= 58 && $randnumber <= 64) || ($randnumber >= 91 && $randnumber <= 96))
{
$randnumber = rand(48,120);
}
$randomPassword .= chr($randnumber);
}
return $randomPassword;
}
}
?>
+1 -1
View File
@@ -8,7 +8,7 @@
<body>
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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
@@ -2,7 +2,7 @@
<body bgcolor=white>
<?php
/**
* V4.01 23 Oct 2003 (c) 2001-2002 John Lim ([email protected]). All rights reserved.
* V4.11 27 Jan 2004 (c) 2001-2002 John Lim ([email protected]). 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.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
+35
View File
@@ -0,0 +1,35 @@
<?php
include_once('../adodb.inc.php');
$db = NewADOConnection('postgres7');
$db->Connect('localhost','tester','test','test') || die("failed connection");
$enc = "GIF89a%01%00%01%00%80%FF%00%C0%C0%C0%00%00%00%21%F9%04%01%00%00%00%00%2C%00%00%00%00%01%00%01%00%00%01%012%00%3Bt_clear.gif%0D";
$val = rawurldecode($enc);
$db->debug=1;
### TEST BEGINS
$db->Execute("insert into photos (id,name) values(9999,'dot.gif')");
$db->UpdateBlob('photos','photo',$val,'id=9999');
$v = $db->GetOne('select photo from photos where id=9999');
### CLEANUP
$db->Execute("delete from photos where id=9999");
### VALIDATION
if ($v !== $val) echo "<b>*** ERROR: Inserted value does not match downloaded val<b>";
else echo "<b>*** OK: Passed</b>";
echo "<pre>";
echo "INSERTED: ", $enc;
echo "<hr>";
echo"RETURNED: ", rawurlencode($v);
echo "<hr><p>";
echo "INSERTED: ", $val;
echo "<hr>";
echo "RETURNED: ", $v;
?>
+56
View File
@@ -0,0 +1,56 @@
<?php
/*
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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 8.
*/
error_reporting(E_ALL);
$path = dirname(__FILE__);
include("$path/../adodb-exceptions.inc.php");
include("$path/../adodb.inc.php");
try {
$dbt = 'oci8';
switch($dbt) {
case 'oci8':
$db = NewADOConnection("oci8");
$db->Connect('','scott','natsoft');
break;
default:
case 'mysql':
$db = NewADOConnection("mysql");
$db->Connect('localhost','root','','test');
break;
}
$db->debug=1;
$cnt = $db->GetOne("select count(*) from adoxyz");
$rs = $db->Execute("select * from adoxyz order by id");
$i = 0;
foreach($rs as $v) {
$i += 1;
echo "$i: "; adodb_pr($v); adodb_pr($rs->fields);
flush();
}
if ($i != $cnt) die("actual cnt is $i, cnt should be $cnt\n");
$rs = $db->Execute("select bad from badder");
} catch (exception $e) {
adodb_pr($e);
$e = adodb_backtrace($e->trace);
}
?>
+1 -1
View File
@@ -1,6 +1,6 @@
<?PHP
// V4.01 23 Oct 2003
// V4.11 27 Jan 2004
error_reporting(E_ALL);
+78 -42
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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,7 +10,7 @@ V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights rese
*/
error_reporting(E_ALL);
$ADODB_FLUSH = true;
define('ADODB_ASSOC_CASE',0);
@@ -28,7 +28,7 @@ function CheckWS($conn)
{
global $ADODB_EXTENSION;
include_once('../adodb-session.php');
include_once('../session/adodb-session.php');
$saved = $ADODB_EXTENSION;
$db = ADONewConnection($conn);
@@ -118,6 +118,7 @@ FROM `nuke_stories` `t1`, `nuke_authors` `t2`, `nuke_stories_cat` `t3`, `nuke_to
flush();
print "<i>date1</i> (1969-02-20) = ".$db->DBDate('1969-2-20');
print "<br><i>date1</i> (1999-02-20) = ".$db->DBDate('1999-2-20');
print "<br><i>date1.1</i> 1999 = ".$db->DBDate("'1999'");
print "<br><i>date2</i> (1970-1-2) = ".$db->DBDate(24*3600)."<p>";
print "<i>ts1</i> (1999-02-20 13:40:50) = ".$db->DBTimeStamp('1999-2-20 1:40:50 pm');
print "<br><i>ts1.1</i> (1999-02-20 13:40:00) = ".$db->DBTimeStamp('1999-2-20 13:40');
@@ -126,6 +127,10 @@ FROM `nuke_stories` `t1`, `nuke_authors` `t2`, `nuke_stories_cat` `t3`, `nuke_to
print "<br> Fractional TS (1999-2-20 13:40:50.91): ".$db->DBTimeStamp($db->UnixTimeStamp('1999-2-20 13:40:50.91+1'));
$dd = $db->UnixDate('1999-02-20');
print "<br>unixdate</i> 1999-02-20 = ".date('Y-m-d',$dd)."<p>";
print "<br><i>ts4</i> =".($db->UnixTimeStamp("19700101000101")+8*3600);
print "<br><i>ts5</i> =".$db->DBTimeStamp($db->UnixTimeStamp("20040110092123"));
print "<br><i>ts6</i> =".$db->UserTimeStamp("20040110092123");
print "<br><i>ts6</i> =".$db->DBTimeStamp("20040110092123");
flush();
// mssql too slow in failing bad connection
if (false && $db->databaseType != 'mssql') {
@@ -260,8 +265,18 @@ FROM `nuke_stories` `t1`, `nuke_authors` `t2`, `nuke_stories_cat` `t3`, `nuke_to
$a = $db->MetaColumns('ADOXYZ');
if ($a===false) print "<b>MetaColumns not supported</b></p>";
else {
print "<p>Columns of ADOXYZ: ";
foreach($a as $v) print " ($v->name $v->type $v->max_length) ";
print "<p>Columns of ADOXYZ: <font size=1><br>";
foreach($a as $v) {print_r($v); echo "<br>";}
echo "</font>";
}
print "<p>Testing MetaIndexes</p>";
$a = $db->MetaIndexes('ADOXYZ',true);
if ($a===false) print "<b>MetaIndexes not supported</b></p>";
else {
print "<p>Indexes of ADOXYZ: <font size=1><br>";
foreach($a as $v) {print_r($v); echo "<br>";}
echo "</font>";
}
print "<p>Testing MetaPrimaryKeys</p>";
$a = $db->MetaPrimaryKeys('ADOXYZ');
@@ -329,8 +344,8 @@ GO
$yr = '1998';
$stmt = $db->PrepareSP('SalesByCategory');
$db->Parameter($stmt,$cat,'CategoryName');
$db->Parameter($stmt,$yr,'OrdYear');
$db->InParameter($stmt,$cat,'CategoryName');
$db->InParameter($stmt,$yr,'OrdYear');
$rs = $db->Execute($stmt);
rs2html($rs);
@@ -338,8 +353,8 @@ GO
$yr = 1998;
$stmt = $db->PrepareSP('SalesByCategory');
$db->Parameter($stmt,$cat,'CategoryName');
$db->Parameter($stmt,$yr,'OrdYear');
$db->InParameter($stmt,$cat,'CategoryName');
$db->InParameter($stmt,$yr,'OrdYear');
$rs = $db->Execute($stmt);
rs2html($rs);
@@ -362,9 +377,9 @@ GO
$days = 10;
$begin_date = '';
$end_date = '';
$db->Parameter($stmt,$days,'days', false, 4, SQLINT4);
$db->Parameter($stmt,$begin_date,'start', 1, 20, SQLVARCHAR );
$db->Parameter($stmt,$end_date,'end', 1, 20, SQLVARCHAR );
$db->InParameter($stmt,$days,'days', 4, SQLINT4);
$db->OutParameter($stmt,$begin_date,'start', 20, SQLVARCHAR );
$db->OutParameter($stmt,$end_date,'end', 20, SQLVARCHAR );
$db->Execute($stmt);
if (empty($begin_date) or empty($end_date)) {
Err("MSSQL SP Test for OUT Failed");
@@ -388,6 +403,7 @@ GO
CREATE OR REPLACE PACKAGE adodb AS
TYPE TabType IS REF CURSOR RETURN tab%ROWTYPE;
PROCEDURE open_tab (tabcursor IN OUT TabType,tablenames in varchar);
PROCEDURE data_out(input IN varchar, output OUT varchar);
END adodb;
/
@@ -396,12 +412,16 @@ PROCEDURE open_tab (tabcursor IN OUT TabType,tablenames in varchar) IS
BEGIN
OPEN tabcursor FOR SELECT * FROM tab where tname like tablenames;
END open_tab;
PROCEDURE data_out(input IN varchar, output OUT varchar) IS
BEGIN
output := 'Cinta Hati '||input;
END;
END adodb;
/
*/
*/
$stmt = $db->Prepare("BEGIN adodb.open_tab(:RS,'A%'); END;");
$db->Parameter($stmt, $cur, 'RS', false, -1, OCI_B_CURSOR);
$db->InParameter($stmt, $cur, 'RS', -1, OCI_B_CURSOR);
$rs = $db->Execute($stmt);
if ($rs && !$rs->EOF) {
@@ -410,15 +430,22 @@ END adodb;
print "<b>Error in using Cursor Variables 1</b><p>";
}
$rs = $db->ExecuteCursor("BEGIN adodb.open_tab(:RS2,:TAB); END;",'RS2',array('TAB'=>'A%'));
if ($rs && !$rs->EOF) {
print "Test 2 RowCount: ".$rs->RecordCount()."<p>";
} else {
print "<b>Error in using Cursor Variables 2</b><p>";
}
print "<h4>Testing Stored Procedures for oci8</h4>";
$stmt = $db->PrepareSP("BEGIN adodb.data_out(:a1, :a2); END;");
$a1 = 'Malaysia';
//$a2 = ''; # a2 doesn't even need to be defined!
$db->InParameter($stmt,$a1,'a1');
$db->OutParameter($stmt,$a2,'a2');
$rs = $db->Execute($stmt);
if ($rs) {
if ($a2 !== 'Cinta Hati Malaysia') print "<b>Stored Procedure Error: a2 = $a2</b><p>";
else echo "OK: a2=$a2<p>";
} else {
print "<b>Error in using Stored Procedure IN/Out Variables</b><p>";
}
$tname = 'A%';
@@ -530,6 +557,7 @@ END adodb;
$db->Execute("insert into ADOXYZ (id,firstname,lastname,created) values ($i*10+9,'Steven','Oey',$time )");
} // for
if (1) {
$db->debug=1;
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$cnt = $db->GetOne("select count(*) from ADOXYZ");
$rs = $db->Execute('update ADOXYZ set id=id+1');
@@ -555,23 +583,24 @@ END adodb;
print "<p><b>Error on RecordCount. Should be 0. Was ".$rs->RecordCount()."</b></p>";
print_r($rs->fields);
}
$rs = &$db->Execute("select id,firstname,lastname,created from ADOXYZ order by id");
if ($rs) {
if ($rs->RecordCount() != 50) {
print "<p><b>RecordCount returns ".$rs->RecordCount()."</b></p>";
$poc = $rs->PO_RecordCount('ADOXYZ');
if ($poc == 50) print "<p> &nbsp; &nbsp; PO_RecordCount passed</p>";
else print "<p><b>PO_RecordCount returns wrong value: $poc</b></p>";
} else print "<p>RecordCount() passed</p>";
if (isset($rs->fields['firstname'])) print '<p>The fields columns can be indexed by column name.</p>';
else {
Err( '<p>The fields columns <i>cannot</i> be indexed by column name.</p>');
print_r($rs->fields);
if ($db->databaseType !== 'odbc') {
$rs = &$db->Execute("select id,firstname,lastname,created,".$db->random." from ADOXYZ order by id");
if ($rs) {
if ($rs->RecordCount() != 50) {
print "<p><b>RecordCount returns ".$rs->RecordCount()."</b></p>";
$poc = $rs->PO_RecordCount('ADOXYZ');
if ($poc == 50) print "<p> &nbsp; &nbsp; PO_RecordCount passed</p>";
else print "<p><b>PO_RecordCount returns wrong value: $poc</b></p>";
} else print "<p>RecordCount() passed</p>";
if (isset($rs->fields['firstname'])) print '<p>The fields columns can be indexed by column name.</p>';
else {
Err( '<p>The fields columns <i>cannot</i> be indexed by column name.</p>');
print_r($rs->fields);
}
if (empty($HTTP_GET_VARS['hide'])) rs2html($rs);
}
if (empty($HTTP_GET_VARS['hide'])) rs2html($rs);
else print "<b>Error in Execute of SELECT with random</b></p>";
}
else print "<b>Error in Execute of SELECT</b></p>";
$val = $db->GetOne("select count(*) from ADOXYZ");
if ($val == 50) print "<p>GetOne returns ok</p>";
else print "<p><b>Fail: GetOne returns $val</b></p>";
@@ -1076,6 +1105,7 @@ END adodb;
err('**** RSFilter failed');
print_r($rs->fields);
}
rs2html($rs);
$db->debug=1;
@@ -1138,7 +1168,10 @@ END adodb;
'firstname', # row fields
'lastname', # column fields
false, # join
'ID' # sum
'ID', # sum
'Sum ', # label for sum
'sum', # aggregate function
true
);
$rs = $db->Execute($sql);
if ($rs) rs2html($rs);
@@ -1205,13 +1238,16 @@ END adodb;
if ($ds != date("d m Y")) Err("Bad UserDate: ".$ds);
else echo "Passed UserDate: $ds<p>";
}
$rs = $db->SelectLimit("select ".$db->sysTimeStamp." from adoxyz",1);
$db->debug=1;
if ($db->dataProvider == 'oci8')
$rs = $db->SelectLimit("select to_char(".$db->sysTimeStamp.",'YYYY-MM-DD HH24:MI:SS') from adoxyz",1);
else
$rs = $db->SelectLimit("select ".$db->sysTimeStamp." from adoxyz",1);
$date = $rs->fields[0];
if (!$date) Err("Bad sysTimeStamp");
else {
$ds = $db->UserTimeStamp($date,"H \\h\\r\\s-d m Y");
if ($ds != date("H \\h\\r\\s-d m Y")) Err("Bad UserTimeStamp: ".$ds);
if ($ds != date("H \\h\\r\\s-d m Y")) Err("Bad UserTimeStamp: ".$ds.", correct is ".date("H \\h\\r\\s-d m Y"));
else echo "Passed UserTimeStamp: $ds<p>";
$date = 100;
@@ -1408,6 +1444,6 @@ include('./testdatabases.inc.php');
include_once('../adodb-time.inc.php');
adodb_date_test();
?>
<p><i>ADODB Database Library (c) 2000-2003 John Lim. All rights reserved. Released under BSD and LGPL.</i></p>
<p><i>ADODB Database Library (c) 2000-2004 John Lim. All rights reserved. Released under BSD and LGPL.</i></p>
</body>
</html>
+1 -1
View File
@@ -8,7 +8,7 @@
<body>
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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 -20
View File
@@ -1,32 +1,44 @@
<code>
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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 8.
*/
#
# Code to test Move
#
include("../adodb.inc.php");
$c1 = &ADONewConnection('postgres');
if (!$c1->PConnect("susetikus","tester","test","test"))
die("Cannot connect to database");
# select * from last table in DB
$rs = $c1->Execute("select * from adoxyz order by 1");
error_reporting(E_ALL);
$path = dirname(__FILE__);
include("$path/../adodb-exceptions.inc.php");
include("$path/../adodb.inc.php");
try {
$db = NewADOConnection("oci8");
$db->Connect('','scott','natsoft');
$db->debug=1;
$cnt = $db->GetOne("select count(*) from adoxyz");
$rs = $db->Execute("select * from adoxyz order by id");
$i = 0;
$max = $rs->RecordCount();
if ($max == -1) "RecordCount returns -1<br>";
while (!$rs->EOF and $i < $max) {
$rs->Move($i);
print_r( $rs->fields);
print '<BR>';
$i++;
foreach($rs as $k => $v) {
$i += 1;
echo $k; adodb_pr($v);
flush();
}
?>
</code>
if ($i != $cnt) die("actual cnt is $i, cnt should be $cnt\n");
$rs = $db->Execute("select bad from badder");
} catch (exception $e) {
adodb_pr($e);
$e = adodb_backtrace($e->trace);
}
?>
+2 -1
View File
@@ -1,7 +1,7 @@
<?php
/**
* @version V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
* @version V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). 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.
@@ -63,6 +63,7 @@ FROM ADOXYZ WHERE lastname=".$conn->qstr($record['lastname']);
$rs = $conn->Execute($sql); // Execute the query and get the existing record to update
if (!$rs) print "<p>No record found!</p>";
$record = array(); // Initialize an array to hold the record data to update
// Set the values for the fields in the record
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
/*
V4.01 23 Oct 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
V4.11 27 Jan 2004 (c) 2000-2004 John Lim ([email protected]). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.

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