mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
Upgraded to ADOdb 2.00
This commit is contained in:
parent
ee990b193a
commit
28bbcf011c
245
lib/adodb/adodb-cryptsession.php
Normal file
245
lib/adodb/adodb-cryptsession.php
Normal file
@ -0,0 +1,245 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Made table name configurable - by David Johnson djohnson@inpro.net
|
||||
Encryption by Ari Kuorikoski <ari.kuorikoski@finebyte.com>
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Latest version of ADODB is available at http://php.weblogs.com/adodb
|
||||
======================================================================
|
||||
|
||||
This file provides PHP4 session management using the ADODB database
|
||||
wrapper library.
|
||||
|
||||
Example
|
||||
=======
|
||||
|
||||
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>";
|
||||
|
||||
|
||||
Installation
|
||||
============
|
||||
1. Create a new database in MySQL or Access "sessions" like
|
||||
so:
|
||||
|
||||
create table sessions (
|
||||
SESSKEY char(32) not null,
|
||||
EXPIRY int(11) unsigned not null,
|
||||
DATA text not null,
|
||||
primary key (sesskey)
|
||||
);
|
||||
|
||||
2. Then define the following parameters in this file:
|
||||
$ADODB_SESSION_DRIVER='database driver, eg. mysql or ibase';
|
||||
$ADODB_SESSION_CONNECT='server to connect to';
|
||||
$ADODB_SESSION_USER ='user';
|
||||
$ADODB_SESSION_PWD ='password';
|
||||
$ADODB_SESSION_DB ='database';
|
||||
$ADODB_SESSION_TBL = 'sessions'
|
||||
|
||||
3. Recommended is PHP 4.0.2 or later. There are documented
|
||||
session bugs in
|
||||
earlier versions of PHP.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
include_once('crypt.inc.php');
|
||||
|
||||
if (!defined('_ADODB_LAYER')) {
|
||||
include ('adodb.inc.php');
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!defined('ADODB_SESSION')) {
|
||||
|
||||
define('ADODB_SESSION',1);
|
||||
|
||||
GLOBAL $ADODB_SESSION_CONNECT,
|
||||
$ADODB_SESSION_DRIVER,
|
||||
$ADODB_SESSION_USER,
|
||||
$ADODB_SESSION_PWD,
|
||||
$ADODB_SESSION_DB,
|
||||
$ADODB_SESS_CONN,
|
||||
$ADODB_SESS_LIFE,
|
||||
$ADODB_SESS_DEBUG,
|
||||
$ADODB_SESS_INSERT;
|
||||
|
||||
//$ADODB_SESS_DEBUG = true;
|
||||
|
||||
/* SET THE FOLLOWING PARAMETERS */
|
||||
if (empty($ADODB_SESSION_DRIVER)) {
|
||||
$ADODB_SESSION_DRIVER='mysql';
|
||||
$ADODB_SESSION_CONNECT='serverName';
|
||||
$ADODB_SESSION_USER ='PhpSessions';
|
||||
$ADODB_SESSION_PWD ='sessions';
|
||||
$ADODB_SESSION_DB ='sessions';
|
||||
}
|
||||
if (empty($ADODB_SESSION_TBL)){
|
||||
$ADODB_SESSION_TBL = 'sessions';
|
||||
}
|
||||
|
||||
|
||||
function ADODB_Session_Key()
|
||||
{
|
||||
$ADODB_CRYPT_KEY = 'CRYPTED ADODB SESSIONS ROCK!';
|
||||
|
||||
/* USE THIS FUNCTION TO CREATE THE ENCRYPTION KEY FOR CRYPTED SESSIONS */
|
||||
/* Crypt the used key, $ADODB_CRYPT_KEY as key and session_ID as SALT */
|
||||
return crypt($ADODB_CRYPT_KEY, session_ID());
|
||||
}
|
||||
|
||||
$ADODB_SESS_LIFE = get_cfg_var('session.gc_maxlifetime');
|
||||
if ($ADODB_SESS_LIFE <= 1) {
|
||||
// bug in PHP 4.0.3 pl 1 -- how about other versions?
|
||||
//print "<h3>Session Error: PHP.INI setting <i>session.gc_maxlifetime</i>not set: $ADODB_SESS_LIFE</h3>";
|
||||
$ADODB_SESS_LIFE=1440;
|
||||
}
|
||||
|
||||
function adodb_sess_open($save_path, $session_name)
|
||||
{
|
||||
GLOBAL $ADODB_SESSION_CONNECT,
|
||||
$ADODB_SESSION_DRIVER,
|
||||
$ADODB_SESSION_USER,
|
||||
$ADODB_SESSION_PWD,
|
||||
$ADODB_SESSION_DB,
|
||||
$ADODB_SESS_CONN,
|
||||
$ADODB_SESS_DEBUG;
|
||||
|
||||
$ADODB_SESS_INSERT = false;
|
||||
|
||||
if (isset($ADODB_SESS_CONN)) return true;
|
||||
|
||||
$ADODB_SESS_CONN = ADONewConnection($ADODB_SESSION_DRIVER);
|
||||
if (!empty($ADODB_SESS_DEBUG)) {
|
||||
$ADODB_SESS_CONN->debug = true;
|
||||
print" conn=$ADODB_SESSION_CONNECT user=$ADODB_SESSION_USER pwd=$ADODB_SESSION_PWD db=$ADODB_SESSION_DB ";
|
||||
}
|
||||
return $ADODB_SESS_CONN->PConnect($ADODB_SESSION_CONNECT,
|
||||
$ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB);
|
||||
|
||||
}
|
||||
|
||||
function adodb_sess_close()
|
||||
{
|
||||
global $ADODB_SESS_CONN;
|
||||
|
||||
if ($ADODB_SESS_CONN) $ADODB_SESS_CONN->Close();
|
||||
return true;
|
||||
}
|
||||
|
||||
function adodb_sess_read($key)
|
||||
{
|
||||
$Crypt = new MD5Crypt;
|
||||
global $ADODB_SESS_CONN,$ADODB_SESS_INSERT,$ADODB_SESSION_TBL;
|
||||
$rs = $ADODB_SESS_CONN->Execute("SELECT data FROM $ADODB_SESSION_TBL WHERE sesskey = '$key' AND expiry >= " . time());
|
||||
if ($rs) {
|
||||
if ($rs->EOF) {
|
||||
$ADODB_SESS_INSERT = true;
|
||||
$v = '';
|
||||
} else {
|
||||
// Decrypt session data
|
||||
$v = rawurldecode($Crypt->Decrypt(reset($rs->fields), ADODB_Session_Key()));
|
||||
}
|
||||
$rs->Close();
|
||||
return $v;
|
||||
}
|
||||
else $ADODB_SESS_INSERT = true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function adodb_sess_write($key, $val)
|
||||
{
|
||||
$Crypt = new MD5Crypt;
|
||||
global $ADODB_SESS_INSERT,$ADODB_SESS_CONN, $ADODB_SESS_LIFE, $ADODB_SESSION_TBL;
|
||||
|
||||
$expiry = time() + $ADODB_SESS_LIFE;
|
||||
|
||||
// encrypt session data..
|
||||
$val = $Crypt->Encrypt(rawurlencode($val), ADODB_Session_Key());
|
||||
$qry = "UPDATE $ADODB_SESSION_TBL SET expiry=$expiry,data='$val' WHERE sesskey='$key'";
|
||||
$rs = $ADODB_SESS_CONN->Execute($qry);
|
||||
if ($rs) $rs->Close();
|
||||
else print '<p>Session Update: '.$ADODB_SESS_CONN->ErrorMsg().'</p>';
|
||||
|
||||
if ($ADODB_SESS_INSERT || $rs === false) {
|
||||
$qry = "INSERT INTO $ADODB_SESSION_TBL(sesskey,expiry,data) VALUES ('$key',$expiry,'$val')";
|
||||
$rs = $ADODB_SESS_CONN->Execute($qry);
|
||||
if ($rs) $rs->Close();
|
||||
else print '<p>Session Insert: '.$ADODB_SESS_CONN->ErrorMsg().'</p>';
|
||||
}
|
||||
// bug in access driver (could be odbc?) means that info is not commited
|
||||
// properly unless select statement executed in Win2000
|
||||
if ($ADODB_SESS_CONN->databaseType == 'access') $rs = $ADODB_SESS_CONN->Execute("select sesskey from $ADODB_SESSION_TBL WHERE sesskey='$key'");
|
||||
|
||||
return isset($rs);
|
||||
}
|
||||
|
||||
function adodb_sess_destroy($key)
|
||||
{
|
||||
global $ADODB_SESS_CONN, $ADODB_SESSION_TBL;
|
||||
|
||||
$qry = "DELETE FROM $ADODB_SESSION_TBL WHERE sesskey = '$key'";
|
||||
$rs = $ADODB_SESS_CONN->Execute($qry);
|
||||
if ($rs) $rs->Close();
|
||||
return $rs;
|
||||
}
|
||||
|
||||
function adodb_sess_gc($maxlifetime) {
|
||||
global $ADODB_SESS_CONN, $ADODB_SESSION_TBL;
|
||||
|
||||
$qry = "DELETE FROM $ADODB_SESSION_TBL WHERE expiry < " . time();
|
||||
$rs = $ADODB_SESS_CONN->Execute($qry);
|
||||
if ($rs) $rs->Close();
|
||||
|
||||
// suggested by Cameron, "GaM3R" <gamr@outworld.cx>
|
||||
if (defined('ADODB_SESSION_OPTIMIZE'))
|
||||
{
|
||||
switch( $ADODB_SESSION_DRIVER ) {
|
||||
case 'mysql':
|
||||
case 'mysqlt':
|
||||
$opt_qry = 'OPTIMIZE TABLE '.$ADODB_SESSION_TBL;
|
||||
break;
|
||||
case 'postgresql':
|
||||
case 'postgresql7':
|
||||
$opt_qry = 'VACUUM '.$ADODB_SESSION_TBL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
session_module_name('user');
|
||||
session_set_save_handler(
|
||||
"adodb_sess_open",
|
||||
"adodb_sess_close",
|
||||
"adodb_sess_read",
|
||||
"adodb_sess_write",
|
||||
"adodb_sess_destroy",
|
||||
"adodb_sess_gc");
|
||||
}
|
||||
|
||||
/* TEST SCRIPT -- UNCOMMENT */
|
||||
/*
|
||||
if (0) {
|
||||
GLOBAL $HTTP_SESSION_VARS;
|
||||
|
||||
session_start();
|
||||
session_register('AVAR');
|
||||
$HTTP_SESSION_VARS['AVAR'] += 1;
|
||||
print "<p>\$HTTP_SESSION_VARS['AVAR']={$HTTP_SESSION_VARS['AVAR']}</p>";
|
||||
}
|
||||
*/
|
||||
?>
|
272
lib/adodb/adodb-csvlib.inc.php
Normal file
272
lib/adodb/adodb-csvlib.inc.php
Normal file
@ -0,0 +1,272 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence. See License.txt.
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
|
||||
Library for CSV serialization. This is used by the csv/proxy driver and is the
|
||||
CacheExecute() serialization format.
|
||||
|
||||
==== NOTE ====
|
||||
Format documented at http://php.weblogs.com/ADODB_CSV
|
||||
==============
|
||||
*/
|
||||
|
||||
/**
|
||||
* convert a recordset into CSV format
|
||||
*
|
||||
* @param rs the recordset
|
||||
*
|
||||
* @return the CSV formated data
|
||||
*/
|
||||
function &rs2csv(&$rs,$conn=false,$sql='')
|
||||
{
|
||||
$max = ($rs) ? $rs->FieldCount() : 0;
|
||||
|
||||
if ($sql) $sql = urlencode($sql);
|
||||
// metadata setup
|
||||
|
||||
if ($max <= 0 || $rs->dataProvider == 'empty') { // is insert/update/delete
|
||||
if (is_object($conn)) {
|
||||
$sql .= ','.$conn->Affected_Rows();
|
||||
$sql .= ','.$conn->Insert_ID();
|
||||
} else
|
||||
$sql .= ',,';
|
||||
|
||||
$text = "====-1,0,$sql\n";
|
||||
return $text;
|
||||
} else {
|
||||
$tt = ($rs->timeCreated) ? $rs->timeCreated : time();
|
||||
$line = "====0,$tt,$sql\n";
|
||||
}
|
||||
// column definitions
|
||||
for($i=0; $i < $max; $i++) {
|
||||
$o = $rs->FetchField($i);
|
||||
$line .= urlencode($o->name).':'.$rs->MetaType($o->type,$o->max_length).":$o->max_length,";
|
||||
}
|
||||
$text = substr($line,0,strlen($line)-1)."\n";
|
||||
|
||||
|
||||
// get data
|
||||
if ($rs->databaseType == 'array') {
|
||||
$text .= serialize($rs->_array);
|
||||
} else {
|
||||
$rows = array();
|
||||
while (!$rs->EOF) {
|
||||
$rows[] = $rs->fields;
|
||||
$rs->MoveNext();
|
||||
}
|
||||
$text .= serialize($rows);
|
||||
}
|
||||
$rs->MoveFirst();
|
||||
return $text;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Open CSV file and convert it into Data.
|
||||
*
|
||||
* @param url file/ftp/http url
|
||||
* @param err returns the error message
|
||||
* @param timeout dispose if recordset has been alive for $timeout secs
|
||||
*
|
||||
* @return recordset, or false if error occured. If no
|
||||
* error occurred in sql INSERT/UPDATE/DELETE,
|
||||
* empty recordset is returned
|
||||
*/
|
||||
function &csv2rs($url,&$err,$timeout=0)
|
||||
{
|
||||
$fp = @fopen($url,'r');
|
||||
$err = false;
|
||||
if (!$fp) {
|
||||
$err = $url.'file/URL not found';
|
||||
return false;
|
||||
}
|
||||
flock($fp, LOCK_SH);
|
||||
$arr = array();
|
||||
$ttl = 0;
|
||||
|
||||
if ($meta = fgetcsv ($fp, 8192, ",")) {
|
||||
// check if error message
|
||||
if (substr($meta[0],0,4) === '****') {
|
||||
$err = trim(substr($meta[0],4,1024));
|
||||
fclose($fp);
|
||||
return false;
|
||||
}
|
||||
// check for meta data
|
||||
// $meta[0] is -1 means return an empty recordset
|
||||
// $meta[1] contains a time
|
||||
|
||||
if (substr($meta[0],0,4) === '====') {
|
||||
|
||||
if ($meta[0] == "====-1") {
|
||||
if (sizeof($meta) < 5) {
|
||||
$err = "Corrupt first line for format -1";
|
||||
fclose($fp);
|
||||
return false;
|
||||
}
|
||||
fclose($fp);
|
||||
|
||||
if ($timeout > 0) {
|
||||
$err = " Illegal Timeout $timeout ";
|
||||
return false;
|
||||
}
|
||||
$rs->fields = array();
|
||||
$rs->timeCreated = $meta[1];
|
||||
$rs = new ADORecordSet($val=true);
|
||||
$rs->EOF = true;
|
||||
$rs->_numOfFields=0;
|
||||
$rs->sql = urldecode($meta[2]);
|
||||
$rs->affectedrows = (integer)$meta[3];
|
||||
$rs->insertid = $meta[4];
|
||||
return $rs;
|
||||
}
|
||||
# Under high volume loads, we want only 1 thread/process to _write_file
|
||||
# so that we don't have 50 processes queueing to write the same data.
|
||||
# Would require probabilistic blocking write
|
||||
#
|
||||
# -2 sec before timeout, give processes 1/16 chance of writing to file with blocking io
|
||||
# -1 sec after timeout give processes 1/4 chance of writing with blocking
|
||||
# +0 sec after timeout, give processes 100% chance writing with blocking
|
||||
if (sizeof($meta) > 1) {
|
||||
if($timeout >0){
|
||||
$tdiff = $meta[1]+$timeout - time();
|
||||
if ($tdiff <= 2) {
|
||||
switch($tdiff) {
|
||||
case 2:
|
||||
if ((rand() & 15) == 0) {
|
||||
fclose($fp);
|
||||
$err = "Timeout 2";
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if ((rand() & 3) == 0) {
|
||||
fclose($fp);
|
||||
$err = "Timeout 1";
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
fclose($fp);
|
||||
$err = "Timeout 0";
|
||||
return false;
|
||||
} // switch
|
||||
|
||||
} // if check flush cache
|
||||
}// (timeout>0)
|
||||
$ttl = $meta[1];
|
||||
}
|
||||
$meta = fgetcsv($fp, 8192, ",");
|
||||
if (!$meta) {
|
||||
fclose($fp);
|
||||
$err = "Unexpected EOF 1";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Get Column definitions
|
||||
$flds = array();
|
||||
foreach($meta as $o) {
|
||||
$o2 = explode(':',$o);
|
||||
if (sizeof($o2)!=3) {
|
||||
$arr[] = $meta;
|
||||
$flds = false;
|
||||
break;
|
||||
}
|
||||
$fld = new ADOFieldObject();
|
||||
$fld->name = urldecode($o2[0]);
|
||||
$fld->type = $o2[1];
|
||||
$fld->max_length = $o2[2];
|
||||
$flds[] = $fld;
|
||||
}
|
||||
} else {
|
||||
fclose($fp);
|
||||
$err = "Recordset had unexpected EOF 2";
|
||||
//print "$url ";print_r($meta);
|
||||
//die();
|
||||
return false;
|
||||
}
|
||||
|
||||
// slurp in the data
|
||||
$MAXSIZE = 128000;
|
||||
$text = fread($fp,$MAXSIZE);
|
||||
if (strlen($text) == $MAXSIZE) {
|
||||
$text .= fread($fp,filesize($url)-$MAXSIZE);
|
||||
}
|
||||
|
||||
fclose($fp);
|
||||
//$text = substr($text,0,44);
|
||||
$arr = @unserialize($text);
|
||||
|
||||
//var_dump($arr);
|
||||
if (!is_array($arr)) {
|
||||
$err = "Recordset had unexpected EOF 3";
|
||||
return false;
|
||||
}
|
||||
$rs = new ADORecordSet_array();
|
||||
$rs->timeCreated = $ttl;
|
||||
$rs->InitArrayFields($arr,$flds);
|
||||
return $rs;
|
||||
}
|
||||
|
||||
/*
|
||||
# The following code was an alternative method of saving
|
||||
# recordsets and is experimental and was never used.
|
||||
# It is faster, but provides very little error checking.
|
||||
|
||||
//High speed rs2csv 10% faster
|
||||
function & xrs2csv(&$rs)
|
||||
{
|
||||
return time()."\n".serialize($rs);
|
||||
}
|
||||
function & xcsv2rs($url,&$err,$timeout)
|
||||
{
|
||||
$t = filemtime($url);// this is cached - should we clearstatcache() ?
|
||||
if ($t === false) {
|
||||
$err = 'File not found 1';
|
||||
return false;
|
||||
}
|
||||
|
||||
if (time() > $t + $timeout){
|
||||
$err = " Timeout 1";
|
||||
return false;
|
||||
}
|
||||
|
||||
$fp = @fopen($url,'r');
|
||||
if (!$fp) {
|
||||
$err = ' file not found ';
|
||||
return false;
|
||||
}
|
||||
|
||||
flock($fp,LOCK_SH);
|
||||
$t = fgets($fp,100);
|
||||
if ($t === false){
|
||||
fclose($fp);
|
||||
$err = " EOF 1 ";
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
if (time() > ((integer)$t) + $timeout){
|
||||
fclose($fp);
|
||||
$err = " Timeout 2";
|
||||
return false;
|
||||
}* /
|
||||
|
||||
$txt = &fread($fp,1999999); // Increase if EOF 2 error returned
|
||||
fclose($fp);
|
||||
$o = @unserialize($txt);
|
||||
if (!is_object($o)) {
|
||||
$err = " EOF 2";
|
||||
return false;
|
||||
}
|
||||
$o->timeCreated = $t;
|
||||
return $o;
|
||||
}
|
||||
*/
|
||||
?>
|
73
lib/adodb/adodb-errorhandler.inc.php
Normal file
73
lib/adodb/adodb-errorhandler.inc.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* @version V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
* Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
*
|
||||
* Set tabs to 4 for best viewing.
|
||||
*
|
||||
* Latest version is available at http://php.weblogs.com
|
||||
*
|
||||
*/
|
||||
|
||||
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
|
||||
* @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_Error_Handler($dbms, $fn, $errno, $errmsg, $p1=false, $p2=false)
|
||||
{
|
||||
switch($fn) {
|
||||
case 'EXECUTE':
|
||||
$sql = $p1;
|
||||
$inputparams = $p2;
|
||||
|
||||
$s = "$dbms error: [$errno: $errmsg] in $fn(\"$sql\")\n";
|
||||
break;
|
||||
|
||||
case 'PCONNECT':
|
||||
case 'CONNECT':
|
||||
$host = $p1;
|
||||
$database = $p2;
|
||||
|
||||
$s = "$dbms error: [$errno: $errmsg] in $fn($host, '****', '****', $database)\n";
|
||||
break;
|
||||
default:
|
||||
$s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)\n";
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* Log connection error somewhere
|
||||
* 0 message is sent to PHP's system logger, using the Operating System's system
|
||||
* logging mechanism or a file, depending on what the error_log configuration
|
||||
* directive is set to.
|
||||
* 1 message is sent by email to the address in the destination parameter.
|
||||
* This is the only message type where the fourth parameter, extra_headers is used.
|
||||
* This message type uses the same internal function as mail() does.
|
||||
* 2 message is sent through the PHP debugging connection.
|
||||
* This option is only available if remote debugging has been enabled.
|
||||
* In this case, the destination parameter specifies the host name or IP address
|
||||
* and optionally, port number, of the socket receiving the debug information.
|
||||
* 3 message is appended to the file destination
|
||||
*/
|
||||
if (defined('ADODB_ERROR_LOG_TYPE')) {
|
||||
$t = date('Y-m-d H:i:s');
|
||||
if (defined('ADODB_ERROR_LOG_DEST'))
|
||||
error_log("($t) $s", ADODB_ERROR_LOG_TYPE, ADODB_ERROR_LOG_DEST);
|
||||
else
|
||||
error_log("($t) $s", ADODB_ERROR_LOG_TYPE);
|
||||
}
|
||||
|
||||
|
||||
//print "<p>$s</p>";
|
||||
trigger_error($s,E_USER_ERROR);
|
||||
}
|
||||
?>
|
86
lib/adodb/adodb-errorpear.inc.php
Normal file
86
lib/adodb/adodb-errorpear.inc.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* @version V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
* Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
*
|
||||
* Set tabs to 4 for best viewing.
|
||||
*
|
||||
* Latest version is available at http://php.weblogs.com
|
||||
*
|
||||
*/
|
||||
include_once('PEAR.php');
|
||||
|
||||
define('ADODB_ERROR_HANDLER','ADODB_Error_PEAR');
|
||||
|
||||
/*
|
||||
* Enabled the following if you want to terminate scripts when an error occurs
|
||||
*/
|
||||
//PEAR::setErrorHandling (PEAR_ERROR_DIE);
|
||||
|
||||
/*
|
||||
* Name of the PEAR_Error derived class to call.
|
||||
*/
|
||||
if (!defined('ADODB_PEAR_ERROR_CLASS')) define('ADODB_PEAR_ERROR_CLASS','PEAR_Error');
|
||||
|
||||
/*
|
||||
* Store the last PEAR_Error object here
|
||||
*/
|
||||
global $ADODB_Last_PEAR_Error; $ADODB_Last_PEAR_Error = false;
|
||||
|
||||
/**
|
||||
* Error Handler with PEAR support. 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_Error_PEAR($dbms, $fn, $errno, $errmsg, $p1=false, $p2=false)
|
||||
{
|
||||
global $ADODB_Last_PEAR_Error;
|
||||
switch($fn) {
|
||||
case 'EXECUTE':
|
||||
$sql = $p1;
|
||||
$inputparams = $p2;
|
||||
|
||||
$s = "$dbms error: [$errno: $errmsg] in $fn(\"$sql\")";
|
||||
break;
|
||||
|
||||
case 'PCONNECT':
|
||||
case 'CONNECT':
|
||||
$host = $p1;
|
||||
$database = $p2;
|
||||
|
||||
$s = "$dbms error: [$errno: $errmsg] in $fn('$host', ?, ?, '$database')";
|
||||
break;
|
||||
|
||||
default:
|
||||
$s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)";
|
||||
break;
|
||||
}
|
||||
|
||||
$class = ADODB_PEAR_ERROR_CLASS;
|
||||
$ADODB_Last_PEAR_Error = new $class($s, $errno,
|
||||
$GLOBALS['_PEAR_default_error_mode'],
|
||||
$GLOBALS['_PEAR_default_error_options'],
|
||||
$errmsg);
|
||||
|
||||
//print "<p>!$s</p>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns last PEAR_Error object. This error might be for an error that
|
||||
* occured several sql statements ago.
|
||||
*/
|
||||
function &ADODB_PEAR_Error()
|
||||
{
|
||||
global $ADODB_Last_PEAR_Error;
|
||||
|
||||
return $ADODB_Last_PEAR_Error;
|
||||
}
|
||||
|
||||
?>
|
276
lib/adodb/adodb-lib.inc.php
Normal file
276
lib/adodb/adodb-lib.inc.php
Normal file
@ -0,0 +1,276 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence. See License.txt.
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Less commonly used functions are placed here to reduce size of adodb.inc.php.
|
||||
*/
|
||||
|
||||
function _adodb_totalpages(&$rs)
|
||||
{
|
||||
if ($rs->rowsPerPage) {
|
||||
$rows = ($rs->RecordCount()+$rs->rowsPerPage-1) / $rs->rowsPerPage;
|
||||
if ($rows < 0) return -1;
|
||||
else return $rows;
|
||||
} else return -1;
|
||||
}
|
||||
|
||||
// Requires $ADODB_FETCH_MODE = ADODB_FETCH_NUM
|
||||
function _adodb_getmenu(&$zthis, $name,$defstr='',$blank1stItem=true,$multiple=false,
|
||||
$size=0, $selectAttr='',$compareFields0=true)
|
||||
{
|
||||
$hasvalue = false;
|
||||
|
||||
if ($multiple or is_array($defstr)) {
|
||||
if ($size==0) $size=5;
|
||||
$attr = " multiple size=$size";
|
||||
if (!strpos($name,'[]')) $name .= '[]';
|
||||
} else if ($size) $attr = " size=$size";
|
||||
else $attr ='';
|
||||
|
||||
|
||||
$s = "<select name=\"$name\"$attr $selectAttr>";
|
||||
if ($blank1stItem) $s .= "\n<option></option>";
|
||||
|
||||
if ($zthis->FieldCount() > 1) $hasvalue=true;
|
||||
else $compareFields0 = true;
|
||||
|
||||
while(!$zthis->EOF) {
|
||||
$zval = trim($zthis->fields[0]);
|
||||
$selected = trim($zthis->fields[$compareFields0 ? 0 : 1]);
|
||||
|
||||
if ($blank1stItem && $zval=="") {
|
||||
$zthis->MoveNext();
|
||||
continue;
|
||||
}
|
||||
if ($hasvalue)
|
||||
$value = 'value="'.htmlspecialchars(trim($zthis->fields[1])).'"';
|
||||
|
||||
|
||||
if (is_array($defstr)) {
|
||||
|
||||
if (in_array($selected,$defstr))
|
||||
$s .= "<option selected $value>".htmlspecialchars($zval).'</option>';
|
||||
else
|
||||
$s .= "\n<option ".$value.'>'.htmlspecialchars($zval).'</option>';
|
||||
}
|
||||
else {
|
||||
if (strcasecmp($selected,$defstr)==0)
|
||||
$s .= "<option selected $value>".htmlspecialchars($zval).'</option>';
|
||||
else
|
||||
$s .= "\n<option ".$value.'>'.htmlspecialchars($zval).'</option>';
|
||||
}
|
||||
$zthis->MoveNext();
|
||||
} // while
|
||||
|
||||
return $s ."\n</select>\n";
|
||||
}
|
||||
|
||||
function &_adodb_pageexecute(&$zthis, $sql, $nrows, $page, $inputarr=false, $arg3=false, $secs2cache=0)
|
||||
{
|
||||
|
||||
$atfirstpage = false;
|
||||
$atlastpage = false;
|
||||
|
||||
if (!isset($page) || $page <= 1) { // If page number <= 1, then we are at the first page
|
||||
$page = 1;
|
||||
$atfirstpage = true;
|
||||
}
|
||||
if ($nrows <= 0) $nrows = 10; // If an invalid nrows is supplied, we assume a default value of 10 rows per page
|
||||
|
||||
// ***** Here we check whether $page is the last page or whether we are trying to retrieve a page number greater than
|
||||
// the last page number.
|
||||
$pagecounter = $page + 1;
|
||||
$pagecounteroffset = ($pagecounter * $nrows) - $nrows;
|
||||
if ($secs2cache>0) $rstest = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $pagecounteroffset, $inputarr, $arg3);
|
||||
else $rstest = &$zthis->SelectLimit($sql, $nrows, $pagecounteroffset, $inputarr, $arg3, $secs2cache);
|
||||
if ($rstest) {
|
||||
while ($rstest && $rstest->EOF && $pagecounter>0) {
|
||||
$atlastpage = true;
|
||||
$pagecounter--;
|
||||
$pagecounteroffset = $nrows * ($pagecounter - 1);
|
||||
$rstest->Close();
|
||||
if ($secs2cache>0) $rstest = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $pagecounteroffset, $inputarr, $arg3);
|
||||
else $rstest = &$zthis->SelectLimit($sql, $nrows, $pagecounteroffset, $inputarr, $arg3, $secs2cache);
|
||||
}
|
||||
if ($rstest) $rstest->Close();
|
||||
}
|
||||
if ($atlastpage) { // If we are at the last page or beyond it, we are going to retrieve it
|
||||
$page = $pagecounter;
|
||||
if ($page == 1) $atfirstpage = true; // We have to do this again in case the last page is the same as the first
|
||||
//... page, that is, the recordset has only 1 page.
|
||||
}
|
||||
|
||||
// We get the data we want
|
||||
$offset = $nrows * ($page-1);
|
||||
if ($secs2cache > 0) $rsreturn = &$zthis->CacheSelectLimit($secs2cache, $sql, $nrows, $offset, $inputarr, $arg3);
|
||||
else $rsreturn = &$zthis->SelectLimit($sql, $nrows, $offset, $inputarr, $arg3, $secs2cache);
|
||||
|
||||
// Before returning the RecordSet, we set the pagination properties we need
|
||||
if ($rsreturn) {
|
||||
$rsreturn->rowsPerPage = $nrows;
|
||||
$rsreturn->AbsolutePage($page);
|
||||
$rsreturn->AtFirstPage($atfirstpage);
|
||||
$rsreturn->AtLastPage($atlastpage);
|
||||
}
|
||||
return $rsreturn;
|
||||
}
|
||||
|
||||
function _adodb_getupdatesql(&$zthis,&$rs, $arrFields,$forceUpdate=false,$magicq=false)
|
||||
{
|
||||
if (!$rs) {
|
||||
printf(ADODB_BAD_RS,'GetUpdateSQL');
|
||||
return false;
|
||||
}
|
||||
|
||||
$fieldUpdatedCount = 0;
|
||||
|
||||
// Get the table name from the existing query.
|
||||
preg_match("/FROM\s".ADODB_TABLE_REGEX."/i", $rs->sql, $tableName);
|
||||
|
||||
// Get the full where clause excluding the word "WHERE" from
|
||||
// the existing query.
|
||||
preg_match("/WHERE\s(.*)/i", $rs->sql, $whereClause);
|
||||
|
||||
// updateSQL will contain the full update query when all
|
||||
// processing has completed.
|
||||
$updateSQL = "UPDATE " . $tableName[1] . " SET ";
|
||||
|
||||
// Loop through all of the fields in the recordset
|
||||
for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++) {
|
||||
|
||||
// Get the field from the recordset
|
||||
$field = $rs->FetchField($i);
|
||||
|
||||
// If the recordset field is one
|
||||
// of the fields passed in then process.
|
||||
if (isset($arrFields[$field->name])) {
|
||||
|
||||
// If the existing field value in the recordset
|
||||
// is different from the value passed in then
|
||||
// go ahead and append the field name and new value to
|
||||
// the update query.
|
||||
|
||||
if ($forceUpdate || strcmp($rs->fields[$i], $arrFields[$field->name])) {
|
||||
// Set the counter for the number of fields that will be updated.
|
||||
$fieldUpdatedCount++;
|
||||
|
||||
// Based on the datatype of the field
|
||||
// Format the value properly for the database
|
||||
$mt = $rs->MetaType($field->type);
|
||||
|
||||
// "mike" <mike@partner2partner.com> patch and "Ryan Bailey" <rebel@windriders.com>
|
||||
//PostgreSQL uses a 't' or 'f' and therefore needs to be processed as a string ('C') type field.
|
||||
if ((substr($zthis->databaseType,0,8) == "postgres") && ($mt == "L")) $mt = "C";
|
||||
|
||||
switch($mt) {
|
||||
case "C":
|
||||
case "X":
|
||||
$updateSQL .= $field->name . " = " . $zthis->qstr($arrFields[$field->name],$magicq) . ", ";
|
||||
break;
|
||||
case "D":
|
||||
$updateSQL .= $field->name . " = " . $zthis->DBDate($arrFields[$field->name]) . ", ";
|
||||
break;
|
||||
case "T":
|
||||
$updateSQL .= $field->name . " = " . $zthis->DBTimeStamp($arrFields[$field->name]) . ", ";
|
||||
break;
|
||||
default:
|
||||
$updateSQL .= $field->name . " = " . (float) $arrFields[$field->name] . ", ";
|
||||
break;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
// If there were any modified fields then build the rest of the update query.
|
||||
if ($fieldUpdatedCount > 0 || $forceUpdate) {
|
||||
// Strip off the comma and space on the end of the update query.
|
||||
$updateSQL = substr($updateSQL, 0, -2);
|
||||
|
||||
// If the recordset has a where clause then use that same where clause
|
||||
// for the update.
|
||||
if ($whereClause[1]) $updateSQL .= " WHERE " . $whereClause[1];
|
||||
|
||||
return $updateSQL;
|
||||
} else {
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
function _adodb_getinsertsql(&$zthis,&$rs,$arrFields,$magicq=false)
|
||||
{
|
||||
$values = '';
|
||||
$fields = '';
|
||||
|
||||
if (!$rs) {
|
||||
printf(ADODB_BAD_RS,'GetInsertSQL');
|
||||
return false;
|
||||
}
|
||||
|
||||
$fieldInsertedCount = 0;
|
||||
|
||||
// Get the table name from the existing query.
|
||||
preg_match("/FROM\s".ADODB_TABLE_REGEX."/i", $rs->sql, $tableName);
|
||||
|
||||
// Loop through all of the fields in the recordset
|
||||
for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++) {
|
||||
|
||||
// Get the field from the recordset
|
||||
$field = $rs->FetchField($i);
|
||||
// If the recordset field is one
|
||||
// of the fields passed in then process.
|
||||
if (isset($arrFields[$field->name])) {
|
||||
|
||||
// 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" <mike@partner2partner.com> patch and "Ryan Bailey" <rebel@windriders.com>
|
||||
//PostgreSQL uses a 't' or 'f' and therefore needs to be processed as a string ('C') type field.
|
||||
if ((substr($zthis->databaseType,0,8) == "postgres") && ($mt == "L")) $mt = "C";
|
||||
|
||||
// Based on the datatype of the field
|
||||
// Format the value properly for the database
|
||||
switch($mt) {
|
||||
case "C":
|
||||
case "X":
|
||||
$values .= $zthis->qstr($arrFields[$field->name],$magicq) . ", ";
|
||||
break;
|
||||
case "D":
|
||||
$values .= $zthis->DBDate($arrFields[$field->name]) . ", ";
|
||||
break;
|
||||
case "T":
|
||||
$values .= $zthis->DBTimeStamp($arrFields[$field->name]) . ", ";
|
||||
break;
|
||||
default:
|
||||
$values .= (float) $arrFields[$field->name] . ", ";
|
||||
break;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
// If there were any inserted fields then build the rest of the insert query.
|
||||
if ($fieldInsertedCount > 0) {
|
||||
|
||||
// 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 )";
|
||||
|
||||
return $insertSQL;
|
||||
|
||||
} else {
|
||||
return false;
|
||||
};
|
||||
}
|
||||
?>
|
342
lib/adodb/adodb-pear.inc.php
Normal file
342
lib/adodb/adodb-pear.inc.php
Normal file
@ -0,0 +1,342 @@
|
||||
<?php
|
||||
/**
|
||||
* @version V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
* Released under both BSD license and Lesser GPL library license.
|
||||
* Whenever there is any discrepancy between the two licenses,
|
||||
* the BSD license will take precedence.
|
||||
*
|
||||
* Set tabs to 4 for best viewing.
|
||||
*
|
||||
* PEAR DB Emulation Layer for ADODB.
|
||||
*
|
||||
* The following code is modelled on PEAR DB code by Stig Bakken <ssb@fast.no> |
|
||||
* and Tomas V.V.Cox <cox@idecnet.com>
|
||||
*/
|
||||
|
||||
/*
|
||||
We support:
|
||||
|
||||
DB_Common
|
||||
---------
|
||||
query - returns PEAR_Error on error
|
||||
limitQuery - return PEAR_Error on error
|
||||
prepare - does not return PEAR_Error on error
|
||||
execute - does not return PEAR_Error on error
|
||||
setFetchMode - supports ASSOC and ORDERED
|
||||
errorNative
|
||||
quote
|
||||
nextID
|
||||
disconnect
|
||||
|
||||
DB_Result
|
||||
---------
|
||||
numRows - returns -1 if not supported
|
||||
numCols
|
||||
fetchInto - does not support passing of fetchmode
|
||||
fetchRows - does not support passing of fetchmode
|
||||
free
|
||||
*/
|
||||
|
||||
define('ADODB_PEAR',dirname(__FILE__));
|
||||
require_once "PEAR.php";
|
||||
require_once ADODB_PEAR."/adodb-errorpear.inc.php";
|
||||
require_once ADODB_PEAR."/adodb.inc.php";
|
||||
|
||||
if (!defined('DB_OK')) {
|
||||
define("DB_OK", 1);
|
||||
define("DB_ERROR",-1);
|
||||
/**
|
||||
* This is a special constant that tells DB the user hasn't specified
|
||||
* any particular get mode, so the default should be used.
|
||||
*/
|
||||
|
||||
define('DB_FETCHMODE_DEFAULT', 0);
|
||||
|
||||
/**
|
||||
* Column data indexed by numbers, ordered from 0 and up
|
||||
*/
|
||||
|
||||
define('DB_FETCHMODE_ORDERED', 1);
|
||||
|
||||
/**
|
||||
* Column data indexed by column names
|
||||
*/
|
||||
|
||||
define('DB_FETCHMODE_ASSOC', 2);
|
||||
|
||||
/* for compatibility */
|
||||
|
||||
define('DB_GETMODE_ORDERED', DB_FETCHMODE_ORDERED);
|
||||
define('DB_GETMODE_ASSOC', DB_FETCHMODE_ASSOC);
|
||||
|
||||
/**
|
||||
* these are constants for the tableInfo-function
|
||||
* they are bitwised or'ed. so if there are more constants to be defined
|
||||
* in the future, adjust DB_TABLEINFO_FULL accordingly
|
||||
*/
|
||||
|
||||
define('DB_TABLEINFO_ORDER', 1);
|
||||
define('DB_TABLEINFO_ORDERTABLE', 2);
|
||||
define('DB_TABLEINFO_FULL', 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* The main "DB" class is simply a container class with some static
|
||||
* methods for creating DB objects as well as some utility functions
|
||||
* common to all parts of DB.
|
||||
*
|
||||
*/
|
||||
|
||||
class DB
|
||||
{
|
||||
/**
|
||||
* Create a new DB object for the specified database type
|
||||
*
|
||||
* @param $type string database type, for example "mysql"
|
||||
*
|
||||
* @return object a newly created DB object, or a DB error code on
|
||||
* error
|
||||
*/
|
||||
|
||||
function &factory($type)
|
||||
{
|
||||
include_once(ADODB_DIR."/drivers/adodb-$type.inc.php");
|
||||
$obj = &NewADOConnection($type);
|
||||
if (!is_object($obj)) return new PEAR_Error('Unknown Database Driver: '.$dsninfo['phptype'],-1);
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DB object and connect to the specified database
|
||||
*
|
||||
* @param $dsn mixed "data source name", see the DB::parseDSN
|
||||
* method for a description of the dsn format. Can also be
|
||||
* specified as an array of the format returned by DB::parseDSN.
|
||||
*
|
||||
* @param $options mixed if boolean (or scalar), tells whether
|
||||
* this connection should be persistent (for backends that support
|
||||
* this). This parameter can also be an array of options, see
|
||||
* DB_common::setOption for more information on connection
|
||||
* options.
|
||||
*
|
||||
* @return object a newly created DB connection object, or a DB
|
||||
* error object on error
|
||||
*
|
||||
* @see DB::parseDSN
|
||||
* @see DB::isError
|
||||
*/
|
||||
function &connect($dsn, $options = false)
|
||||
{
|
||||
if (is_array($dsn)) {
|
||||
$dsninfo = $dsn;
|
||||
} else {
|
||||
$dsninfo = DB::parseDSN($dsn);
|
||||
}
|
||||
switch ($dsninfo["phptype"]) {
|
||||
case 'pgsql': $type = 'postgres7'; break;
|
||||
case 'ifx': $type = 'informix9'; break;
|
||||
default: $type = $dsninfo["phptype"]; break;
|
||||
}
|
||||
|
||||
if (is_array($options) && isset($options["debug"]) &&
|
||||
$options["debug"] >= 2) {
|
||||
// expose php errors with sufficient debug level
|
||||
@include_once("adodb-$type.inc.php");
|
||||
} else {
|
||||
@include_once("adodb-$type.inc.php");
|
||||
}
|
||||
|
||||
@$obj =&NewADOConnection($type);
|
||||
if (!is_object($obj)) return new PEAR_Error('Unknown Database Driver: '.$dsninfo['phptype'],-1);
|
||||
|
||||
if (is_array($options)) {
|
||||
$persist = !empty($options['persistent']);
|
||||
} else {
|
||||
$persist = true;
|
||||
}
|
||||
|
||||
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();
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the DB API version
|
||||
*
|
||||
* @return int the DB API version number
|
||||
*/
|
||||
function apiVersion()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell whether a result code from a DB method is an error
|
||||
*
|
||||
* @param $value int result code
|
||||
*
|
||||
* @return bool whether $value is an error
|
||||
*/
|
||||
function isError($value)
|
||||
{
|
||||
return (is_object($value) &&
|
||||
(get_class($value) == 'db_error' ||
|
||||
is_subclass_of($value, 'db_error')));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tell whether a result code from a DB method is a warning.
|
||||
* Warnings differ from errors in that they are generated by DB,
|
||||
* and are not fatal.
|
||||
*
|
||||
* @param $value mixed result value
|
||||
*
|
||||
* @return bool whether $value is a warning
|
||||
*/
|
||||
function isWarning($value)
|
||||
{
|
||||
return is_object($value) &&
|
||||
(get_class( $value ) == "db_warning" ||
|
||||
is_subclass_of($value, "db_warning"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a data source name
|
||||
*
|
||||
* @param $dsn string Data Source Name to be parsed
|
||||
*
|
||||
* @return array an associative array with the following keys:
|
||||
*
|
||||
* phptype: Database backend used in PHP (mysql, odbc etc.)
|
||||
* dbsyntax: Database used with regards to SQL syntax etc.
|
||||
* protocol: Communication protocol to use (tcp, unix etc.)
|
||||
* hostspec: Host specification (hostname[:port])
|
||||
* database: Database to use on the DBMS server
|
||||
* username: User name for login
|
||||
* password: Password for login
|
||||
*
|
||||
* The format of the supplied DSN is in its fullest form:
|
||||
*
|
||||
* phptype(dbsyntax)://username:password@protocol+hostspec/database
|
||||
*
|
||||
* Most variations are allowed:
|
||||
*
|
||||
* phptype://username:password@protocol+hostspec:110//usr/db_file.db
|
||||
* phptype://username:password@hostspec/database_name
|
||||
* phptype://username:password@hostspec
|
||||
* phptype://username@hostspec
|
||||
* phptype://hostspec/database
|
||||
* phptype://hostspec
|
||||
* phptype(dbsyntax)
|
||||
* phptype
|
||||
*
|
||||
* @author Tomas V.V.Cox <cox@idecnet.com>
|
||||
*/
|
||||
function parseDSN($dsn)
|
||||
{
|
||||
if (is_array($dsn)) {
|
||||
return $dsn;
|
||||
}
|
||||
|
||||
$parsed = array(
|
||||
'phptype' => false,
|
||||
'dbsyntax' => false,
|
||||
'protocol' => false,
|
||||
'hostspec' => false,
|
||||
'database' => false,
|
||||
'username' => false,
|
||||
'password' => false
|
||||
);
|
||||
|
||||
// Find phptype and dbsyntax
|
||||
if (($pos = strpos($dsn, '://')) !== false) {
|
||||
$str = substr($dsn, 0, $pos);
|
||||
$dsn = substr($dsn, $pos + 3);
|
||||
} else {
|
||||
$str = $dsn;
|
||||
$dsn = NULL;
|
||||
}
|
||||
|
||||
// Get phptype and dbsyntax
|
||||
// $str => phptype(dbsyntax)
|
||||
if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) {
|
||||
$parsed['phptype'] = $arr[1];
|
||||
$parsed['dbsyntax'] = (empty($arr[2])) ? $arr[1] : $arr[2];
|
||||
} else {
|
||||
$parsed['phptype'] = $str;
|
||||
$parsed['dbsyntax'] = $str;
|
||||
}
|
||||
|
||||
if (empty($dsn)) {
|
||||
return $parsed;
|
||||
}
|
||||
|
||||
// Get (if found): username and password
|
||||
// $dsn => username:password@protocol+hostspec/database
|
||||
if (($at = strpos($dsn,'@')) !== false) {
|
||||
$str = substr($dsn, 0, $at);
|
||||
$dsn = substr($dsn, $at + 1);
|
||||
if (($pos = strpos($str, ':')) !== false) {
|
||||
$parsed['username'] = urldecode(substr($str, 0, $pos));
|
||||
$parsed['password'] = urldecode(substr($str, $pos + 1));
|
||||
} else {
|
||||
$parsed['username'] = urldecode($str);
|
||||
}
|
||||
}
|
||||
|
||||
// Find protocol and hostspec
|
||||
// $dsn => protocol+hostspec/database
|
||||
if (($pos=strpos($dsn, '/')) !== false) {
|
||||
$str = substr($dsn, 0, $pos);
|
||||
$dsn = substr($dsn, $pos + 1);
|
||||
} else {
|
||||
$str = $dsn;
|
||||
$dsn = NULL;
|
||||
}
|
||||
|
||||
// Get protocol + hostspec
|
||||
// $str => protocol+hostspec
|
||||
if (($pos=strpos($str, '+')) !== false) {
|
||||
$parsed['protocol'] = substr($str, 0, $pos);
|
||||
$parsed['hostspec'] = urldecode(substr($str, $pos + 1));
|
||||
} else {
|
||||
$parsed['hostspec'] = urldecode($str);
|
||||
}
|
||||
|
||||
// Get dabase if any
|
||||
// $dsn => database
|
||||
if (!empty($dsn)) {
|
||||
$parsed['database'] = $dsn;
|
||||
}
|
||||
|
||||
return $parsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a PHP database extension if it is not loaded already.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param $name the base name of the extension (without the .so or
|
||||
* .dll suffix)
|
||||
*
|
||||
* @return bool true if the extension was already or successfully
|
||||
* loaded, false if it could not be loaded
|
||||
*/
|
||||
function assertExtension($name)
|
||||
{
|
||||
if (!extension_loaded($name)) {
|
||||
$dlext = (substr(PHP_OS, 0, 3) == 'WIN') ? '.dll' : '.so';
|
||||
@dl($name . $dlext);
|
||||
}
|
||||
if (!extension_loaded($name)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
229
lib/adodb/adodb-session.php
Normal file
229
lib/adodb/adodb-session.php
Normal file
@ -0,0 +1,229 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Made table name configurable - by David Johnson djohnson@inpro.net
|
||||
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Latest version of ADODB is available at http://php.weblogs.com/adodb
|
||||
======================================================================
|
||||
|
||||
This file provides PHP4 session management using the ADODB database
|
||||
wrapper library.
|
||||
|
||||
Example
|
||||
=======
|
||||
|
||||
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>";
|
||||
|
||||
|
||||
Installation
|
||||
============
|
||||
1. Create a new database in MySQL or Access "sessions" like
|
||||
so:
|
||||
|
||||
create table sessions (
|
||||
SESSKEY char(32) not null,
|
||||
EXPIRY int(11) unsigned not null,
|
||||
DATA text not null,
|
||||
primary key (sesskey)
|
||||
);
|
||||
|
||||
2. Then define the following parameters in this file:
|
||||
$ADODB_SESSION_DRIVER='database driver, eg. mysql or ibase';
|
||||
$ADODB_SESSION_CONNECT='server to connect to';
|
||||
$ADODB_SESSION_USER ='user';
|
||||
$ADODB_SESSION_PWD ='password';
|
||||
$ADODB_SESSION_DB ='database';
|
||||
$ADODB_SESSION_TBL = 'sessions'
|
||||
|
||||
3. Recommended is PHP 4.0.2 or later. There are documented
|
||||
session bugs in
|
||||
earlier versions of PHP.
|
||||
|
||||
*/
|
||||
|
||||
if (!defined('_ADODB_LAYER')) {
|
||||
include ('adodb.inc.php');
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!defined('ADODB_SESSION')) {
|
||||
|
||||
define('ADODB_SESSION',1);
|
||||
|
||||
GLOBAL $ADODB_SESSION_CONNECT,
|
||||
$ADODB_SESSION_DRIVER,
|
||||
$ADODB_SESSION_USER,
|
||||
$ADODB_SESSION_PWD,
|
||||
$ADODB_SESSION_DB,
|
||||
$ADODB_SESS_CONN,
|
||||
$ADODB_SESS_LIFE,
|
||||
$ADODB_SESS_DEBUG,
|
||||
$ADODB_SESS_INSERT;
|
||||
|
||||
//$ADODB_SESS_DEBUG = true;
|
||||
|
||||
/* SET THE FOLLOWING PARAMETERS */
|
||||
if (empty($ADODB_SESSION_DRIVER)) {
|
||||
$ADODB_SESSION_DRIVER='mysql';
|
||||
$ADODB_SESSION_CONNECT='localhost';
|
||||
$ADODB_SESSION_USER ='root';
|
||||
$ADODB_SESSION_PWD ='';
|
||||
$ADODB_SESSION_DB ='xphplens_2';
|
||||
}
|
||||
if (empty($ADODB_SESSION_TBL)){
|
||||
$ADODB_SESSION_TBL = 'sessions';
|
||||
}
|
||||
|
||||
$ADODB_SESS_LIFE = get_cfg_var('session.gc_maxlifetime');
|
||||
if ($ADODB_SESS_LIFE <= 1) {
|
||||
// bug in PHP 4.0.3 pl 1 -- how about other versions?
|
||||
//print "<h3>Session Error: PHP.INI setting <i>session.gc_maxlifetime</i>not set: $ADODB_SESS_LIFE</h3>";
|
||||
$ADODB_SESS_LIFE=1440;
|
||||
}
|
||||
|
||||
function adodb_sess_open($save_path, $session_name,$persist=true)
|
||||
{
|
||||
GLOBAL $ADODB_SESS_CONN;
|
||||
//if( $persist) print "PERSIST ";
|
||||
if (isset($ADODB_SESS_CONN)) return true;
|
||||
|
||||
GLOBAL $ADODB_SESSION_CONNECT,
|
||||
$ADODB_SESSION_DRIVER,
|
||||
$ADODB_SESSION_USER,
|
||||
$ADODB_SESSION_PWD,
|
||||
$ADODB_SESSION_DB,
|
||||
$ADODB_SESS_DEBUG;
|
||||
|
||||
$ADODB_SESS_CONN = ADONewConnection($ADODB_SESSION_DRIVER);
|
||||
if (!empty($ADODB_SESS_DEBUG)) {
|
||||
$ADODB_SESS_CONN->debug = true;
|
||||
print" conn=$ADODB_SESSION_CONNECT user=$ADODB_SESSION_USER pwd=$ADODB_SESSION_PWD db=$ADODB_SESSION_DB ";
|
||||
}
|
||||
if ($persist) $ADODB_SESS_CONN->PConnect($ADODB_SESSION_CONNECT,
|
||||
$ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB);
|
||||
else $ADODB_SESS_CONN->Connect($ADODB_SESSION_CONNECT,
|
||||
$ADODB_SESSION_USER,$ADODB_SESSION_PWD,$ADODB_SESSION_DB);
|
||||
|
||||
}
|
||||
|
||||
function adodb_sess_close()
|
||||
{
|
||||
global $ADODB_SESS_CONN;
|
||||
|
||||
if ($ADODB_SESS_CONN) $ADODB_SESS_CONN->Close();
|
||||
return true;
|
||||
}
|
||||
|
||||
function adodb_sess_read($key)
|
||||
{
|
||||
global $ADODB_SESS_CONN,$ADODB_SESS_INSERT,$ADODB_SESSION_TBL;
|
||||
$ADODB_SESS_INSERT = false;
|
||||
$rs = $ADODB_SESS_CONN->Execute("SELECT data FROM $ADODB_SESSION_TBL WHERE sesskey = '$key' AND expiry >= " . time());
|
||||
if ($rs) {
|
||||
if ($rs->EOF) {
|
||||
$ADODB_SESS_INSERT = true;
|
||||
$v = '';
|
||||
} else
|
||||
$v = rawurldecode(reset($rs->fields));
|
||||
|
||||
$rs->Close();
|
||||
return $v;
|
||||
}
|
||||
else $ADODB_SESS_INSERT = true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function adodb_sess_write($key, $val)
|
||||
{
|
||||
global $ADODB_SESS_INSERT,$ADODB_SESS_CONN, $ADODB_SESS_LIFE, $ADODB_SESSION_TBL;
|
||||
|
||||
$expiry = time() + $ADODB_SESS_LIFE;
|
||||
|
||||
$val = rawurlencode($val);
|
||||
$qry = "UPDATE $ADODB_SESSION_TBL SET expiry=$expiry,data='$val' WHERE sesskey='$key'";
|
||||
$rs = $ADODB_SESS_CONN->Execute($qry);
|
||||
if ($rs) $rs->Close();
|
||||
else print '<p>Session Update: '.$ADODB_SESS_CONN->ErrorMsg().'</p>';
|
||||
|
||||
if ($ADODB_SESS_INSERT || $rs === false) {
|
||||
$qry = "INSERT INTO $ADODB_SESSION_TBL(sesskey,expiry,data) VALUES ('$key',$expiry,'$val')";
|
||||
$rs = $ADODB_SESS_CONN->Execute($qry);
|
||||
if ($rs) $rs->Close();
|
||||
else print '<p>Session Insert: '.$ADODB_SESS_CONN->ErrorMsg().'</p>';
|
||||
}
|
||||
// bug in access driver (could be odbc?) means that info is not commited
|
||||
// properly unless select statement executed in Win2000
|
||||
if ($ADODB_SESS_CONN->databaseType == 'access') $rs = $ADODB_SESS_CONN->Execute("select sesskey from $ADODB_SESSION_TBL WHERE sesskey='$key'");
|
||||
|
||||
return isset($rs);
|
||||
}
|
||||
|
||||
function adodb_sess_destroy($key)
|
||||
{
|
||||
global $ADODB_SESS_CONN, $ADODB_SESSION_TBL;
|
||||
|
||||
$qry = "DELETE FROM $ADODB_SESSION_TBL WHERE sesskey = '$key'";
|
||||
$rs = $ADODB_SESS_CONN->Execute($qry);
|
||||
return $rs ? true : false;
|
||||
}
|
||||
|
||||
function adodb_sess_gc($maxlifetime) {
|
||||
global $ADODB_SESS_CONN, $ADODB_SESSION_TBL,$ADODB_SESSION_DRIVER;
|
||||
|
||||
$qry = "DELETE FROM $ADODB_SESSION_TBL WHERE expiry < " . time();
|
||||
$rs = $ADODB_SESS_CONN->Execute($qry);
|
||||
if ($rs) $rs->Close();
|
||||
|
||||
// suggested by Cameron, "GaM3R" <gamr@outworld.cx>
|
||||
if (defined('ADODB_SESSION_OPTIMIZE'))
|
||||
{
|
||||
switch( $ADODB_SESSION_DRIVER ) {
|
||||
case 'mysql':
|
||||
case 'mysqlt':
|
||||
$opt_qry = 'OPTIMIZE TABLE '.$ADODB_SESSION_TBL;
|
||||
break;
|
||||
case 'postgresql':
|
||||
case 'postgresql7':
|
||||
$opt_qry = 'VACUUM '.$ADODB_SESSION_TBL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
session_module_name('user');
|
||||
session_set_save_handler(
|
||||
"adodb_sess_open",
|
||||
"adodb_sess_close",
|
||||
"adodb_sess_read",
|
||||
"adodb_sess_write",
|
||||
"adodb_sess_destroy",
|
||||
"adodb_sess_gc");
|
||||
}
|
||||
|
||||
/* TEST SCRIPT -- UNCOMMENT */
|
||||
|
||||
if (0) {
|
||||
GLOBAL $HTTP_SESSION_VARS;
|
||||
|
||||
session_start();
|
||||
session_register('AVAR');
|
||||
$HTTP_SESSION_VARS['AVAR'] += 1;
|
||||
print "<p>\$HTTP_SESSION_VARS['AVAR']={$HTTP_SESSION_VARS['AVAR']}</p>";
|
||||
}
|
||||
|
||||
?>
|
2369
lib/adodb/adodb.inc.php
Normal file
2369
lib/adodb/adodb.inc.php
Normal file
File diff suppressed because it is too large
Load Diff
61
lib/adodb/crypt.inc.php
Normal file
61
lib/adodb/crypt.inc.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
// Session Encryption by Ari Kuorikoski <ari.kuorikoski@finebyte.com>
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
70
lib/adodb/drivers/adodb-access.inc.php
Normal file
70
lib/adodb/drivers/adodb-access.inc.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence. See License.txt.
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
|
||||
Microsoft Access data driver. Requires ODBC. Works only on MS Windows.
|
||||
*/
|
||||
if (!defined('_ADODB_ODBC_LAYER')) {
|
||||
include(ADODB_DIR."/drivers/adodb-odbc.inc.php");
|
||||
}
|
||||
if (!defined('_ADODB_ACCESS')) {
|
||||
define('_ADODB_ACCESS',1);
|
||||
|
||||
class ADODB_access extends ADODB_odbc {
|
||||
var $databaseType = 'access';
|
||||
var $hasTop = 'top'; // support mssql SELECT TOP 10 * FROM TABLE
|
||||
var $fmtDate = "#Y-m-d#";
|
||||
var $fmtTimeStamp = "#Y-m-d h:i:sA#"; // note not comma
|
||||
var $_bindInputArray = false; // strangely enough, setting to true does not work reliably
|
||||
var $sysDate = "FORMAT(NOW,'yyyy-mm-dd')";
|
||||
var $sysTimeStamp = 'NOW';
|
||||
|
||||
function ADODB_access()
|
||||
{
|
||||
$this->ADODB_odbc();
|
||||
}
|
||||
|
||||
function BeginTrans() { return false;}
|
||||
|
||||
function &MetaTables()
|
||||
{
|
||||
global $ADODB_FETCH_MODE;
|
||||
|
||||
$savem = $ADODB_FETCH_MODE;
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
||||
$qid = odbc_tables($this->_connectionID);
|
||||
$ADODB_FETCH_MODE = $savem;
|
||||
$rs = new ADORecordSet_odbc($qid);
|
||||
if (!$rs) return false;
|
||||
|
||||
$rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change;
|
||||
|
||||
$arr = &$rs->GetArray();
|
||||
|
||||
$arr2 = array();
|
||||
for ($i=0; $i < sizeof($arr); $i++) {
|
||||
if ($arr[$i][2] && substr($arr[$i][2],0,4) != 'MSys')
|
||||
$arr2[] = $arr[$i][2];
|
||||
}
|
||||
return $arr2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class ADORecordSet_access extends ADORecordSet_odbc {
|
||||
|
||||
var $databaseType = "access";
|
||||
|
||||
function ADORecordSet_access($id)
|
||||
{
|
||||
return $this->ADORecordSet_odbc($id);
|
||||
}
|
||||
}
|
||||
} // class
|
||||
?>
|
538
lib/adodb/drivers/adodb-ado.inc.php
Normal file
538
lib/adodb/drivers/adodb-ado.inc.php
Normal file
@ -0,0 +1,538 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
|
||||
Microsoft ADO data driver. Requires ADO. Works only on MS Windows.
|
||||
*/
|
||||
define("_ADODB_ADO_LAYER", 1 );
|
||||
/*--------------------------------------------------------------------------------------
|
||||
--------------------------------------------------------------------------------------*/
|
||||
|
||||
class ADODB_ado extends ADOConnection {
|
||||
var $databaseType = "ado";
|
||||
var $_bindInputArray = false;
|
||||
var $fmtDate = "'Y-m-d'";
|
||||
var $fmtTimeStamp = "'Y-m-d, h:i:sA'";
|
||||
var $replaceQuote = "''"; // string to use to replace quotes
|
||||
var $dataProvider = "ado";
|
||||
var $hasAffectedRows = true;
|
||||
var $adoParameterType = 201; // 201 = long varchar, 203=long wide varchar, 205 = long varbinary
|
||||
var $_affectedRows = false;
|
||||
var $_thisTransactions;
|
||||
|
||||
function ADODB_ado()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
function _affectedrows()
|
||||
{
|
||||
return $this->_affectedRows;
|
||||
}
|
||||
|
||||
function _connect($argHostname, $argUsername, $argPassword, $argProvider= 'MSDASQL')
|
||||
{
|
||||
$u = 'UID';
|
||||
$p = 'PWD';
|
||||
|
||||
$dbc = new COM('ADODB.Connection');
|
||||
if (! $dbc) return false;
|
||||
/* // handle SQL server provider specially ? no need
|
||||
if ($argProvider) {
|
||||
if ($argProvider == "SQLOLEDB") { // SQL Server Provider
|
||||
}
|
||||
}*/
|
||||
if ($argProvider) $dbc->Provider = $argProvider;
|
||||
else $dbc->Provider ='MSDASQL';
|
||||
|
||||
if ($argUsername) $argHostname .= ";$u=$argUsername";
|
||||
if ($argPassword)$argHostname .= ";$p=$argPassword";
|
||||
|
||||
if ($this->debug) print "<p>Host=".$argHostname."<BR>version=$dbc->version</p>";
|
||||
// @ added below for php 4.0.1 and earlier
|
||||
@$dbc->Open((string) $argHostname);
|
||||
|
||||
$this->_connectionID = $dbc;
|
||||
return $dbc != false;
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
function _pconnect($argHostname, $argUsername, $argPassword, $argProvider='MSDASQL')
|
||||
{
|
||||
$dbc = new COM("ADODB.Connection");
|
||||
if (! $dbc) return false;
|
||||
|
||||
if ($argProvider) $dbc->Provider = $argProvider;
|
||||
else $dbc->Provider ='MSDASQL';
|
||||
|
||||
if ($argUsername) $argHostname .= ";UID=$argUsername";
|
||||
if ($argPassword)$argHostname .= ";PWD=$argPassword";
|
||||
|
||||
if ($this->debug) print "<p>Host=".$argHostname."<BR>version=$dbc->version</p>";
|
||||
$dbc->Open((string) $argHostname);
|
||||
|
||||
$this->_connectionID = $dbc;
|
||||
return $dbc != false;
|
||||
}
|
||||
|
||||
/*
|
||||
adSchemaCatalogs = 1,
|
||||
adSchemaCharacterSets = 2,
|
||||
adSchemaCollations = 3,
|
||||
adSchemaColumns = 4,
|
||||
adSchemaCheckConstraints = 5,
|
||||
adSchemaConstraintColumnUsage = 6,
|
||||
adSchemaConstraintTableUsage = 7,
|
||||
adSchemaKeyColumnUsage = 8,
|
||||
adSchemaReferentialContraints = 9,
|
||||
adSchemaTableConstraints = 10,
|
||||
adSchemaColumnsDomainUsage = 11,
|
||||
adSchemaIndexes = 12,
|
||||
adSchemaColumnPrivileges = 13,
|
||||
adSchemaTablePrivileges = 14,
|
||||
adSchemaUsagePrivileges = 15,
|
||||
adSchemaProcedures = 16,
|
||||
adSchemaSchemata = 17,
|
||||
adSchemaSQLLanguages = 18,
|
||||
adSchemaStatistics = 19,
|
||||
adSchemaTables = 20,
|
||||
adSchemaTranslations = 21,
|
||||
adSchemaProviderTypes = 22,
|
||||
adSchemaViews = 23,
|
||||
adSchemaViewColumnUsage = 24,
|
||||
adSchemaViewTableUsage = 25,
|
||||
adSchemaProcedureParameters = 26,
|
||||
adSchemaForeignKeys = 27,
|
||||
adSchemaPrimaryKeys = 28,
|
||||
adSchemaProcedureColumns = 29,
|
||||
adSchemaDBInfoKeywords = 30,
|
||||
adSchemaDBInfoLiterals = 31,
|
||||
adSchemaCubes = 32,
|
||||
adSchemaDimensions = 33,
|
||||
adSchemaHierarchies = 34,
|
||||
adSchemaLevels = 35,
|
||||
adSchemaMeasures = 36,
|
||||
adSchemaProperties = 37,
|
||||
adSchemaMembers = 38
|
||||
|
||||
*/
|
||||
|
||||
function MetaTables()
|
||||
{
|
||||
$arr= array();
|
||||
$dbc = $this->_connectionID;
|
||||
|
||||
$adors=@$dbc->OpenSchema(20);//tables
|
||||
if ($adors){
|
||||
$f = $adors->Fields(2);//table/view name
|
||||
$t = $adors->Fields(3);//table type
|
||||
while (!$adors->EOF){
|
||||
$tt=substr($t->value,0,6);
|
||||
if ($tt!='SYSTEM' && $tt !='ACCESS')
|
||||
$arr[]=$f->value;
|
||||
//print $f->value . ' ' . $t->value.'<br>';
|
||||
$adors->MoveNext();
|
||||
}
|
||||
$adors->Close();
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
function MetaColumns($table)
|
||||
{
|
||||
$table = strtoupper($table);
|
||||
$arr= array();
|
||||
$dbc = $this->_connectionID;
|
||||
|
||||
$adors=@$dbc->OpenSchema(4);//tables
|
||||
|
||||
if ($adors){
|
||||
$t = $adors->Fields(2);//table/view name
|
||||
while (!$adors->EOF){
|
||||
|
||||
|
||||
if (strtoupper($t->Value) == $table) {
|
||||
|
||||
$fld = new ADOFieldObject();
|
||||
$c = $adors->Fields(3);
|
||||
$fld->name = $c->Value;
|
||||
$fld->type = 'CHAR'; // cannot discover type in ADO!
|
||||
$fld->max_length = -1;
|
||||
$arr[strtoupper($fld->name)]=$fld;
|
||||
}
|
||||
|
||||
$adors->MoveNext();
|
||||
}
|
||||
$adors->Close();
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/* returns queryID or false */
|
||||
function &_query($sql,$inputarr=false)
|
||||
{
|
||||
|
||||
$dbc = $this->_connectionID;
|
||||
|
||||
// return rs
|
||||
if ($inputarr) {
|
||||
$oCmd = new COM('ADODB.Command');
|
||||
$oCmd->ActiveConnection = $dbc;
|
||||
$oCmd->CommandText = $sql;
|
||||
$oCmd->CommandType = 1;
|
||||
|
||||
foreach($inputarr as $val) {
|
||||
// name, type, direction 1 = input, len,
|
||||
$this->adoParameterType = 130;
|
||||
$p = $oCmd->CreateParameter('name',$this->adoParameterType,1,strlen($val),$val);
|
||||
//print $p->Type.' '.$p->value;
|
||||
$oCmd->Parameters->Append($p);
|
||||
}
|
||||
$p = false;
|
||||
$rs = $oCmd->Execute();
|
||||
$e = $dbc->Errors;
|
||||
if ($dbc->Errors->Count > 0) return false;
|
||||
return $rs;
|
||||
}
|
||||
$rs = @$dbc->Execute($sql,&$this->_affectedRows);
|
||||
|
||||
if ($dbc->Errors->Count > 0) return false;
|
||||
if (! $rs) return false;
|
||||
|
||||
if ($rs->State == 0) return true; // 0 = adStateClosed means no records returned
|
||||
return $rs;
|
||||
}
|
||||
|
||||
|
||||
function BeginTrans()
|
||||
{
|
||||
if (isset($this->_thisTransactions))
|
||||
if (!$this->_thisTransactions) return false;
|
||||
else {
|
||||
$o = $this->_connectionID->Properties("Transaction DDL");
|
||||
$this->_thisTransactions = $o ? true : false;
|
||||
if (!$o) return false;
|
||||
}
|
||||
@$this->_connectionID->BeginTrans();
|
||||
return true;
|
||||
}
|
||||
function CommitTrans($ok=true)
|
||||
{
|
||||
if (!$ok) return $this->RollbackTrans();
|
||||
@$this->_connectionID->CommitTrans();
|
||||
return true;
|
||||
}
|
||||
function RollbackTrans() {
|
||||
@$this->_connectionID->RollbackTrans();
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Returns: the last error message from previous database operation */
|
||||
|
||||
function ErrorMsg()
|
||||
{
|
||||
$errc = $this->_connectionID->Errors;
|
||||
if ($errc->Count == 0) return '';
|
||||
$err = $errc->Item($errc->Count-1);
|
||||
return $err->Description;
|
||||
}
|
||||
|
||||
function ErrorNo()
|
||||
{
|
||||
$errc = $this->_connectionID->Errors;
|
||||
if ($errc->Count == 0) return 0;
|
||||
$err = $errc->Item($errc->Count-1);
|
||||
return $err->NativeError;
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
function _close()
|
||||
{
|
||||
if ($this->_connectionID) $this->_connectionID->Close();
|
||||
$this->_connectionID = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------------------
|
||||
Class Name: Recordset
|
||||
--------------------------------------------------------------------------------------*/
|
||||
|
||||
class ADORecordSet_ado extends ADORecordSet {
|
||||
|
||||
var $bind = false;
|
||||
var $databaseType = "ado";
|
||||
var $dataProvider = "ado";
|
||||
var $_tarr = false; // caches the types
|
||||
var $_flds; // and field objects
|
||||
var $canSeek = true;
|
||||
var $hideErrors = true;
|
||||
|
||||
function ADORecordSet_ado(&$id)
|
||||
{
|
||||
global $ADODB_FETCH_MODE;
|
||||
|
||||
$this->fetchMode = $ADODB_FETCH_MODE;
|
||||
return $this->ADORecordSet($id);
|
||||
}
|
||||
|
||||
|
||||
// returns the field object
|
||||
function FetchField($fieldOffset = -1) {
|
||||
$off=$fieldOffset+1; // offsets begin at 1
|
||||
|
||||
$o= new ADOFieldObject();
|
||||
$rs = $this->_queryID;
|
||||
$f = $rs->Fields($fieldOffset);
|
||||
$o->name = $f->Name;
|
||||
$o->type = $this->MetaType($f->Type);
|
||||
$o->max_length = $f->DefinedSize;
|
||||
|
||||
|
||||
//print "off=$off name=$o->name type=$o->type len=$o->max_length<br>";
|
||||
return $o;
|
||||
}
|
||||
|
||||
/* Use associative array to get fields array */
|
||||
function Fields($colname)
|
||||
{
|
||||
if ($this->fetchMode & ADODB_FETCH_ASSOC) 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 _initrs()
|
||||
{
|
||||
$rs = $this->_queryID;
|
||||
$this->_numOfRows = $rs->RecordCount;
|
||||
|
||||
$f = $rs->Fields;
|
||||
$this->_numOfFields = $f->Count;
|
||||
}
|
||||
|
||||
|
||||
// should only be used to move forward as we normally use forward-only cursors
|
||||
function _seek($row)
|
||||
{
|
||||
$rs = $this->_queryID;
|
||||
// absoluteposition doesn't work -- my maths is wrong ?
|
||||
// $rs->AbsolutePosition->$row-2;
|
||||
// return true;
|
||||
if ($this->_currentRow > $row) return false;
|
||||
@$rs->Move((integer)$row - $this->_currentRow-1); //adBookmarkFirst
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
OLEDB types
|
||||
|
||||
enum DBTYPEENUM
|
||||
{ DBTYPE_EMPTY = 0,
|
||||
DBTYPE_NULL = 1,
|
||||
DBTYPE_I2 = 2,
|
||||
DBTYPE_I4 = 3,
|
||||
DBTYPE_R4 = 4,
|
||||
DBTYPE_R8 = 5,
|
||||
DBTYPE_CY = 6,
|
||||
DBTYPE_DATE = 7,
|
||||
DBTYPE_BSTR = 8,
|
||||
DBTYPE_IDISPATCH = 9,
|
||||
DBTYPE_ERROR = 10,
|
||||
DBTYPE_BOOL = 11,
|
||||
DBTYPE_VARIANT = 12,
|
||||
DBTYPE_IUNKNOWN = 13,
|
||||
DBTYPE_DECIMAL = 14,
|
||||
DBTYPE_UI1 = 17,
|
||||
DBTYPE_ARRAY = 0x2000,
|
||||
DBTYPE_BYREF = 0x4000,
|
||||
DBTYPE_I1 = 16,
|
||||
DBTYPE_UI2 = 18,
|
||||
DBTYPE_UI4 = 19,
|
||||
DBTYPE_I8 = 20,
|
||||
DBTYPE_UI8 = 21,
|
||||
DBTYPE_GUID = 72,
|
||||
DBTYPE_VECTOR = 0x1000,
|
||||
DBTYPE_RESERVED = 0x8000,
|
||||
DBTYPE_BYTES = 128,
|
||||
DBTYPE_STR = 129,
|
||||
DBTYPE_WSTR = 130,
|
||||
DBTYPE_NUMERIC = 131,
|
||||
DBTYPE_UDT = 132,
|
||||
DBTYPE_DBDATE = 133,
|
||||
DBTYPE_DBTIME = 134,
|
||||
DBTYPE_DBTIMESTAMP = 135
|
||||
|
||||
ADO Types
|
||||
|
||||
adEmpty = 0,
|
||||
adTinyInt = 16,
|
||||
adSmallInt = 2,
|
||||
adInteger = 3,
|
||||
adBigInt = 20,
|
||||
adUnsignedTinyInt = 17,
|
||||
adUnsignedSmallInt = 18,
|
||||
adUnsignedInt = 19,
|
||||
adUnsignedBigInt = 21,
|
||||
adSingle = 4,
|
||||
adDouble = 5,
|
||||
adCurrency = 6,
|
||||
adDecimal = 14,
|
||||
adNumeric = 131,
|
||||
adBoolean = 11,
|
||||
adError = 10,
|
||||
adUserDefined = 132,
|
||||
adVariant = 12,
|
||||
adIDispatch = 9,
|
||||
adIUnknown = 13,
|
||||
adGUID = 72,
|
||||
adDate = 7,
|
||||
adDBDate = 133,
|
||||
adDBTime = 134,
|
||||
adDBTimeStamp = 135,
|
||||
adBSTR = 8,
|
||||
adChar = 129,
|
||||
adVarChar = 200,
|
||||
adLongVarChar = 201,
|
||||
adWChar = 130,
|
||||
adVarWChar = 202,
|
||||
adLongVarWChar = 203,
|
||||
adBinary = 128,
|
||||
adVarBinary = 204,
|
||||
adLongVarBinary = 205,
|
||||
adChapter = 136,
|
||||
adFileTime = 64,
|
||||
adDBFileTime = 137,
|
||||
adPropVariant = 138,
|
||||
adVarNumeric = 139
|
||||
*/
|
||||
function MetaType($t,$len=-1)
|
||||
{
|
||||
if (!is_numeric($t)) return $t;
|
||||
|
||||
switch ($t) {
|
||||
case 0:
|
||||
case 12: // variant
|
||||
case 8: // bstr
|
||||
case 129: //char
|
||||
case 130: //wc
|
||||
case 200: // varc
|
||||
case 202:// varWC
|
||||
case 128: // bin
|
||||
case 204: // varBin
|
||||
case 72: // guid
|
||||
if ($len <= $this->blobSize) return 'C';
|
||||
|
||||
case 201:
|
||||
case 203:
|
||||
return 'X';
|
||||
case 128:
|
||||
case 204:
|
||||
case 205:
|
||||
return 'B';
|
||||
case 7:
|
||||
case 133: return 'D';
|
||||
|
||||
case 134:
|
||||
case 135: return 'T';
|
||||
|
||||
case 11: return 'L';
|
||||
|
||||
case 16:// adTinyInt = 16,
|
||||
case 2://adSmallInt = 2,
|
||||
case 3://adInteger = 3,
|
||||
case 4://adBigInt = 20,
|
||||
case 17://adUnsignedTinyInt = 17,
|
||||
case 18://adUnsignedSmallInt = 18,
|
||||
case 19://adUnsignedInt = 19,
|
||||
case 20://adUnsignedBigInt = 21,
|
||||
return 'I';
|
||||
default: return 'N';
|
||||
}
|
||||
}
|
||||
|
||||
// time stamp not supported yet
|
||||
function _fetch()
|
||||
{
|
||||
$rs = $this->_queryID;
|
||||
if ($rs->EOF) return false;
|
||||
$this->fields = array();
|
||||
|
||||
if (!$this->_tarr) {
|
||||
$tarr = array();
|
||||
$flds = array();
|
||||
for ($i=0,$max = $this->_numOfFields; $i < $max; $i++) {
|
||||
$f = $rs->Fields($i);
|
||||
$flds[] = $f;
|
||||
$tarr[] = $f->Type;
|
||||
}
|
||||
// bind types and flds only once
|
||||
$this->_tarr = $tarr;
|
||||
$this->_flds = $flds;
|
||||
}
|
||||
$t = reset($this->_tarr);
|
||||
$f = reset($this->_flds);
|
||||
|
||||
if ($this->hideErrors) $olde = error_reporting(E_ERROR|E_CORE_ERROR);// sometimes $f->value be null
|
||||
for ($i=0,$max = $this->_numOfFields; $i < $max; $i++) {
|
||||
|
||||
switch($t) {
|
||||
|
||||
case 133:// A date value (yyyymmdd)
|
||||
$val = $f->value;
|
||||
$this->fields[] = substr($val,0,4).'-'.substr($val,4,2).'-'.substr($val,6,2);
|
||||
break;
|
||||
case 7: // adDate
|
||||
$this->fields[] = date('Y-m-d',(integer)$f->value);
|
||||
break;
|
||||
case 1: // null
|
||||
$this->fields[] = false;
|
||||
break;
|
||||
case 6: // currency is not supported properly;
|
||||
print '<br><b>'.$f->Name.': currency type not supported by PHP</b><br>';
|
||||
$this->fields[] = (float) $f->value;
|
||||
break;
|
||||
default:
|
||||
$this->fields[] = $f->value;
|
||||
break;
|
||||
}
|
||||
//print " $f->value $t, ";
|
||||
$f = next($this->_flds);
|
||||
$t = next($this->_tarr);
|
||||
} // for
|
||||
if ($this->hideErrors) error_reporting($olde);
|
||||
@$rs->MoveNext(); // @ needed for some versions of PHP!
|
||||
|
||||
if ($this->fetchMode == ADODB_FETCH_ASSOC) {
|
||||
$this->fields = $this->GetRowAssoc(false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function _close() {
|
||||
$this->_flds = false;
|
||||
@$this->_queryID->Close();// by Pete Dishman (peterd@telephonetics.co.uk)
|
||||
$this->_queryID = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
42
lib/adodb/drivers/adodb-ado_access.inc.php
Normal file
42
lib/adodb/drivers/adodb-ado_access.inc.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence. See License.txt.
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
|
||||
Microsoft Access ADO data driver. Requires ADO and ODBC. Works only on MS Windows.
|
||||
*/
|
||||
|
||||
if (!defined('_ADODB_ADO_LAYER')) {
|
||||
include(ADODB_DIR."/drivers/adodb-ado.inc.php");
|
||||
}
|
||||
|
||||
class ADODB_ado_access extends ADODB_ado {
|
||||
var $databaseType = 'ado_access';
|
||||
var $hasTop = 'top'; // support mssql SELECT TOP 10 * FROM TABLE
|
||||
var $fmtDate = "#Y-m-d#";
|
||||
var $fmtTimeStamp = "#Y-m-d h:i:sA#";// note no comma
|
||||
|
||||
function ADODB_ado_access()
|
||||
{
|
||||
}
|
||||
|
||||
function BeginTrans() { return false;}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class ADORecordSet_ado_access extends ADORecordSet_ado {
|
||||
|
||||
var $databaseType = "ado_access";
|
||||
|
||||
function ADORecordSet_ado_access(&$id)
|
||||
{
|
||||
return $this->ADORecordSet_ado($id);
|
||||
}
|
||||
}
|
||||
?>
|
42
lib/adodb/drivers/adodb-ado_mssql.inc.php
Normal file
42
lib/adodb/drivers/adodb-ado_mssql.inc.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
|
||||
Microsoft SQL Server ADO data driver. Requires ADO and MSSQL client.
|
||||
Works only on MS Windows.
|
||||
|
||||
It is normally better to use the mssql driver directly because it is much faster.
|
||||
This file is only a technology demonstration and for test purposes.
|
||||
*/
|
||||
|
||||
if (!defined('_ADODB_ADO_LAYER')) {
|
||||
include(ADODB_DIR."/drivers/adodb-ado.inc.php");
|
||||
}
|
||||
|
||||
class ADODB_ado_mssql extends ADODB_ado {
|
||||
var $databaseType = 'ado_mssql';
|
||||
var $hasTop = 'top';
|
||||
var $sysDate = 'GetDate()';
|
||||
var $sysTimeStamp = 'GetDate()';
|
||||
|
||||
function ADODB_ado_mssql()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class ADORecordSet_ado_mssql extends ADORecordSet_ado {
|
||||
|
||||
var $databaseType = 'ado_mssql';
|
||||
|
||||
function ADORecordSet_ado_mssql(&$id)
|
||||
{
|
||||
return $this->ADORecordSet_ado($id);
|
||||
}
|
||||
}
|
||||
?>
|
64
lib/adodb/drivers/adodb-borland_ibase.inc.php
Normal file
64
lib/adodb/drivers/adodb-borland_ibase.inc.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
|
||||
Support Borland Interbase 6.5 and later
|
||||
|
||||
*/
|
||||
|
||||
include_once(ADODB_DIR."/drivers/adodb-ibase.inc.php");
|
||||
|
||||
class ADODB_borland_ibase extends ADODB_ibase {
|
||||
var $databaseType = "borland_ibase";
|
||||
|
||||
function ADODB_borland_ibase()
|
||||
{
|
||||
$this->ADODB_ibase();
|
||||
}
|
||||
|
||||
// Note that Interbase 6.5 uses ROWS instead - don't you love forking wars!
|
||||
// SELECT col1, col2 FROM table ROWS 5 -- get 5 rows
|
||||
// SELECT col1, col2 FROM TABLE ORDER BY col1 ROWS 3 TO 7 -- first 5 skip 2
|
||||
// Firebird uses
|
||||
// SELECT FIRST 5 SKIP 2 col1, col2 FROM TABLE
|
||||
function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false, $arg3=false,$secs=0)
|
||||
{
|
||||
if ($nrows > 0) {
|
||||
if ($offset <= 0) $str = " ROWS $nrows ";
|
||||
else {
|
||||
$a = $offset+1;
|
||||
$b = $offset+$nrows;
|
||||
$str = " ROWS $a TO $b";
|
||||
}
|
||||
} else {
|
||||
// ok, skip
|
||||
$a = $offset + 1;
|
||||
$str = " ROWS $a TO 999999999"; // 999 million
|
||||
}
|
||||
$sql .= $str;
|
||||
|
||||
return ($secs) ?
|
||||
$this->CacheExecute($secs,$sql,$inputarr,$arg3)
|
||||
:
|
||||
$this->Execute($sql,$inputarr,$arg3);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
class ADORecordSet_borland_ibase extends ADORecordSet_ibase {
|
||||
|
||||
var $databaseType = "borland_ibase";
|
||||
|
||||
function ADORecordSet_borland_ibase($id)
|
||||
{
|
||||
$this->ADORecordSet_ibase($id);
|
||||
}
|
||||
}
|
||||
?>
|
194
lib/adodb/drivers/adodb-csv.inc.php
Normal file
194
lib/adodb/drivers/adodb-csv.inc.php
Normal file
@ -0,0 +1,194 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 4.
|
||||
|
||||
Currently unsupported: MetaDatabases, MetaTables and MetaColumns, and also inputarr in Execute.
|
||||
Native types have been converted to MetaTypes.
|
||||
Transactions not supported yet.
|
||||
*/
|
||||
|
||||
if (! defined("_ADODB_CSV_LAYER")) {
|
||||
define("_ADODB_CSV_LAYER", 1 );
|
||||
|
||||
include_once(ADODB_DIR.'/adodb-csvlib.inc.php');
|
||||
|
||||
class ADODB_csv extends ADOConnection {
|
||||
var $databaseType = 'csv';
|
||||
var $hasInsertID = true;
|
||||
var $hasAffectedRows = true;
|
||||
var $fmtTimeStamp = "'Y-m-d H:i:s'";
|
||||
var $_affectedrows=0;
|
||||
var $_insertid=0;
|
||||
var $_url;
|
||||
var $replaceQuote = "''"; // string to use to replace quotes
|
||||
|
||||
function ADODB_csv()
|
||||
{
|
||||
}
|
||||
|
||||
function _insertid()
|
||||
{
|
||||
return $this->_insertid;
|
||||
}
|
||||
|
||||
function _affectedrows()
|
||||
{
|
||||
return $this->_affectedrows;
|
||||
}
|
||||
|
||||
function &MetaDatabases()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// returns true or false
|
||||
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
|
||||
{
|
||||
if (strtolower(substr($argHostname,0,7)) !== 'http://') return false;
|
||||
$this->_url = $argHostname;
|
||||
return true;
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
|
||||
{
|
||||
if (strtolower(substr($argHostname,0,7)) !== 'http://') return false;
|
||||
$this->_url = $argHostname;
|
||||
return true;
|
||||
}
|
||||
|
||||
function &MetaColumns($table)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// parameters use PostgreSQL convention, not MySQL
|
||||
function &SelectLimit($sql,$nrows=-1,$offset=-1,$arg3=false)
|
||||
{
|
||||
global $ADODB_FETCH_MODE;
|
||||
|
||||
$url = $this->_url.'?sql='.urlencode($sql)."&nrows=$nrows&fetch=$ADODB_FETCH_MODE&offset=$offset&arg3=".urlencode($arg3);
|
||||
$err = false;
|
||||
$rs = csv2rs($url,$err,false);
|
||||
|
||||
if ($this->debug) print "$url<br><i>$err</i><br>";
|
||||
|
||||
$at = strpos($err,'::::');
|
||||
if ($at === false) {
|
||||
$this->_errorMsg = $err;
|
||||
$this->_errorNo = (integer)$err;
|
||||
} else {
|
||||
$this->_errorMsg = substr($err,$at+4,1024);
|
||||
$this->_errorNo = -9999;
|
||||
}
|
||||
if ($this->_errorNo)
|
||||
if ($fn = $this->raiseErrorFn) {
|
||||
$fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,'');
|
||||
}
|
||||
|
||||
if (is_object($rs)) {
|
||||
$rs->databaseType='csv';
|
||||
$rs->fetchMode = $ADODB_FETCH_MODE;
|
||||
$rs->connection = &$this;
|
||||
}
|
||||
return $rs;
|
||||
}
|
||||
|
||||
// returns queryID or false
|
||||
function &Execute($sql,$inputarr=false,$arg3=false)
|
||||
{
|
||||
global $ADODB_FETCH_MODE;
|
||||
|
||||
if (!$this->_bindInputArray && $inputarr) {
|
||||
$sqlarr = explode('?',$sql);
|
||||
$sql = '';
|
||||
$i = 0;
|
||||
foreach($inputarr as $v) {
|
||||
|
||||
$sql .= $sqlarr[$i];
|
||||
// from Ron Baldwin <ron.baldwin@sourceprose.com>
|
||||
// Only quote string types
|
||||
if (gettype($v) == 'string')
|
||||
$sql .= $this->qstr($v);
|
||||
else if ($v === null)
|
||||
$sql .= 'NULL';
|
||||
else
|
||||
$sql .= $v;
|
||||
$i += 1;
|
||||
|
||||
}
|
||||
$sql .= $sqlarr[$i];
|
||||
if ($i+1 != sizeof($sqlarr))
|
||||
print "Input Array does not match ?: ".htmlspecialchars($sql);
|
||||
$inputarr = false;
|
||||
}
|
||||
|
||||
$url = $this->_url.'?sql='.urlencode($sql)."&fetch=$ADODB_FETCH_MODE";
|
||||
if ($arg3) $url .= "&arg3=".urlencode($arg3);
|
||||
$err = false;
|
||||
|
||||
$rs = csv2rs($url,$err,false);
|
||||
if ($this->debug) print urldecode($url)."<br><i>$err</i><br>";
|
||||
$at = strpos($err,'::::');
|
||||
if ($at === false) {
|
||||
$this->_errorMsg = $err;
|
||||
$this->_errorNo = (integer)$err;
|
||||
} else {
|
||||
$this->_errorMsg = substr($err,$at+4,1024);
|
||||
$this->_errorNo = -9999;
|
||||
}
|
||||
|
||||
if ($this->_errorNo)
|
||||
if ($fn = $this->raiseErrorFn) {
|
||||
$fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,$inputarr);
|
||||
}
|
||||
if (is_object($rs)) {
|
||||
$rs->fetchMode = $ADODB_FETCH_MODE;
|
||||
$this->_affectedrows = $rs->affectedrows;
|
||||
$this->_insertid = $rs->insertid;
|
||||
$rs->databaseType='csv';
|
||||
$rs->connection = &$this;
|
||||
}
|
||||
return $rs;
|
||||
}
|
||||
|
||||
/* Returns: the last error message from previous database operation */
|
||||
function ErrorMsg()
|
||||
{
|
||||
return $this->_errorMsg;
|
||||
}
|
||||
|
||||
/* Returns: the last error number from previous database operation */
|
||||
function ErrorNo()
|
||||
{
|
||||
return $this->_errorNo;
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
function _close()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
} // class
|
||||
|
||||
class ADORecordset_csv extends ADORecordset {
|
||||
function ADORecordset_csv($id)
|
||||
{
|
||||
$this->ADORecordset($id);
|
||||
}
|
||||
|
||||
function _close()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
} // define
|
||||
|
||||
?>
|
181
lib/adodb/drivers/adodb-db2.inc.php
Normal file
181
lib/adodb/drivers/adodb-db2.inc.php
Normal file
@ -0,0 +1,181 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
|
||||
DB2 data driver. Requires ODBC.
|
||||
|
||||
From phpdb list:
|
||||
|
||||
Hi Andrew,
|
||||
|
||||
thanks a lot for your help. Today we discovered what
|
||||
our real problem was:
|
||||
|
||||
After "playing" a little bit with the php-scripts that try
|
||||
to connect to the IBM DB2, we set the optional parameter
|
||||
Cursortype when calling odbc_pconnect(....).
|
||||
|
||||
And the exciting thing: When we set the cursor type
|
||||
to SQL_CUR_USE_ODBC Cursor Type, then
|
||||
the whole query speed up from 1 till 10 seconds
|
||||
to 0.2 till 0.3 seconds for 100 records. Amazing!!!
|
||||
|
||||
Therfore, PHP is just almost fast as calling the DB2
|
||||
from Servlets using JDBC (don't take too much care
|
||||
about the speed at whole: the database was on a
|
||||
completely other location, so the whole connection
|
||||
was made over a slow network connection).
|
||||
|
||||
I hope this helps when other encounter the same
|
||||
problem when trying to connect to DB2 from
|
||||
PHP.
|
||||
|
||||
Kind regards,
|
||||
Christian Szardenings
|
||||
|
||||
2 Oct 2001
|
||||
Mark Newnham has discovered that the SQL_CUR_USE_ODBC is not supported by
|
||||
IBM's DB2 ODBC driver, so this must be a 3rd party ODBC driver.
|
||||
|
||||
From the IBM CLI Reference:
|
||||
|
||||
SQL_ATTR_ODBC_CURSORS (DB2 CLI v5)
|
||||
This connection attribute is defined by ODBC, but is not supported by DB2
|
||||
CLI. Any attempt to set or get this attribute will result in an SQLSTATE of
|
||||
HYC00 (Driver not capable).
|
||||
|
||||
A 32-bit option specifying how the Driver Manager uses the ODBC cursor
|
||||
library.
|
||||
|
||||
So I guess this means the message [above] was related to using a 3rd party
|
||||
odbc driver.
|
||||
|
||||
*/
|
||||
|
||||
if (!defined('_ADODB_ODBC_LAYER')) {
|
||||
include(ADODB_DIR."/drivers/adodb-odbc.inc.php");
|
||||
}
|
||||
if (!defined('ADODB_DB2')){
|
||||
define('ADODB_DB2',1);
|
||||
|
||||
class ADODB_DB2 extends ADODB_odbc {
|
||||
var $databaseType = "db2";
|
||||
var $concat_operator = 'CONCAT';
|
||||
var $sysDate = 'CURRENT DATE';
|
||||
var $sysTimeStamp = 'CURRENT TIMESTAMP';
|
||||
//var $curmode = SQL_CUR_USE_ODBC;
|
||||
|
||||
function ADODB_DB2()
|
||||
{
|
||||
$this->ADODB_odbc();
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
// curmode is not properly supported by DB2 odbc driver according to Mark Newnham
|
||||
function _connect($argDSN, $argUsername, $argPassword, $argDatabasename)
|
||||
{
|
||||
global $php_errormsg;
|
||||
|
||||
$php_errormsg = '';
|
||||
$this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword);
|
||||
$this->_errorMsg = $php_errormsg;
|
||||
|
||||
//if ($this->_connectionID) odbc_autocommit($this->_connectionID,true);
|
||||
return $this->_connectionID != false;
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename)
|
||||
{
|
||||
global $php_errormsg;
|
||||
$php_errormsg = '';
|
||||
$this->_connectionID = odbc_pconnect($argDSN,$argUsername,$argPassword);
|
||||
$this->_errorMsg = $php_errormsg;
|
||||
|
||||
//if ($this->_connectionID) odbc_autocommit($this->_connectionID,true);
|
||||
return $this->_connectionID != false;
|
||||
}
|
||||
|
||||
function RowLock($tables,$where)
|
||||
{
|
||||
if ($this->_autocommit) $this->BeginTrans();
|
||||
return $this->GetOne("select 1 as ignore from $tables where $where for update");
|
||||
}
|
||||
|
||||
function &SelectLimit($sql,$nrows=-1,$offset=-1,$arg3=false)
|
||||
{
|
||||
if ($offset <= 0) {
|
||||
// could also use " OPTIMIZE FOR $nrows ROWS "
|
||||
$sql .= " FETCH FIRST $nrows ROWS ONLY ";
|
||||
return $this->Execute($sql,false,$arg3);
|
||||
} else {
|
||||
$nrows += $offset;
|
||||
$sql .= " FETCH FIRST $nrows ROWS ONLY ";
|
||||
return ADOConnection::SelectLimit($sql,-1,$offset,$arg3);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
class ADORecordSet_db2 extends ADORecordSet_odbc {
|
||||
|
||||
var $databaseType = "db2";
|
||||
|
||||
function ADORecordSet_db2($id)
|
||||
{
|
||||
$this->ADORecordSet_odbc($id);
|
||||
}
|
||||
|
||||
function MetaType($t,$len=-1,$fieldobj=false)
|
||||
{
|
||||
switch (strtoupper($t)) {
|
||||
case 'VARCHAR':
|
||||
case 'CHAR':
|
||||
case 'CHARACTER':
|
||||
if ($len <= $this->blobSize) return 'C';
|
||||
|
||||
case 'LONGCHAR':
|
||||
case 'TEXT':
|
||||
case 'CLOB':
|
||||
case 'DBCLOB': // double-byte
|
||||
return 'X';
|
||||
|
||||
case 'BLOB':
|
||||
case 'GRAPHIC':
|
||||
case 'VARGRAPHIC':
|
||||
return 'B';
|
||||
|
||||
case 'DATE':
|
||||
return 'D';
|
||||
|
||||
case 'TIME':
|
||||
case 'TIMESTAMP':
|
||||
return 'T';
|
||||
|
||||
//case 'BOOLEAN':
|
||||
//case 'BIT':
|
||||
// return 'L';
|
||||
|
||||
//case 'COUNTER':
|
||||
// return 'R';
|
||||
|
||||
case 'INT':
|
||||
case 'INTEGER':
|
||||
case 'BIGINT':
|
||||
case 'SMALLINT':
|
||||
return 'I';
|
||||
|
||||
default: return 'N';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} //define
|
||||
?>
|
259
lib/adodb/drivers/adodb-fbsql.inc.php
Normal file
259
lib/adodb/drivers/adodb-fbsql.inc.php
Normal file
@ -0,0 +1,259 @@
|
||||
<?php
|
||||
/*
|
||||
@version V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Contribution by Frank M. Kromann <frank@frontbase.com>.
|
||||
Set tabs to 8.
|
||||
*/
|
||||
|
||||
if (! defined("_ADODB_FBSQL_LAYER")) {
|
||||
define("_ADODB_FBSQL_LAYER", 1 );
|
||||
|
||||
class ADODB_fbsql extends ADOConnection {
|
||||
var $databaseType = 'fbsql';
|
||||
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 = false;
|
||||
|
||||
function ADODB_fbsql()
|
||||
{
|
||||
}
|
||||
|
||||
function _insertid()
|
||||
{
|
||||
return fbsql_insert_id($this->_connectionID);
|
||||
}
|
||||
|
||||
function _affectedrows()
|
||||
{
|
||||
return fbsql_affected_rows($this->_connectionID);
|
||||
}
|
||||
|
||||
function &MetaDatabases()
|
||||
{
|
||||
$qid = fbsql_list_dbs($this->_connectionID);
|
||||
$arr = array();
|
||||
$i = 0;
|
||||
$max = fbsql_num_rows($qid);
|
||||
while ($i < $max) {
|
||||
$arr[] = fbsql_tablename($qid,$i);
|
||||
$i += 1;
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
// returns concatenated string
|
||||
function Concat()
|
||||
{
|
||||
$s = "";
|
||||
$arr = func_get_args();
|
||||
$first = true;
|
||||
|
||||
foreach($arr as $a) {
|
||||
if ($first) {
|
||||
$s = $a;
|
||||
$first = false;
|
||||
} else $s .= ','.$a;
|
||||
}
|
||||
if (sizeof($s) > 0) return "CONCAT($s)";
|
||||
else return '';
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
|
||||
{
|
||||
$this->_connectionID = fbsql_connect($argHostname,$argUsername,$argPassword);
|
||||
if ($this->_connectionID === false) return false;
|
||||
if ($argDatabasename) return $this->SelectDB($argDatabasename);
|
||||
return true;
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
|
||||
{
|
||||
$this->_connectionID = fbsql_pconnect($argHostname,$argUsername,$argPassword);
|
||||
if ($this->_connectionID === false) return false;
|
||||
if ($argDatabasename) return $this->SelectDB($argDatabasename);
|
||||
return true;
|
||||
}
|
||||
|
||||
function &MetaColumns($table)
|
||||
{
|
||||
if ($this->metaColumnsSQL) {
|
||||
|
||||
$rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
|
||||
|
||||
if ($rs === false) return false;
|
||||
|
||||
$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);
|
||||
|
||||
$retarr[strtoupper($fld->name)] = $fld;
|
||||
$rs->MoveNext();
|
||||
}
|
||||
$rs->Close();
|
||||
return $retarr;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
function SelectDB($dbName)
|
||||
{
|
||||
$this->databaseName = $dbName;
|
||||
if ($this->_connectionID) {
|
||||
return @fbsql_select_db($dbName,$this->_connectionID);
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
|
||||
// returns queryID or false
|
||||
function _query($sql,$inputarr)
|
||||
{
|
||||
return fbsql_query("$sql;",$this->_connectionID);
|
||||
}
|
||||
|
||||
/* Returns: the last error message from previous database operation */
|
||||
function ErrorMsg()
|
||||
{
|
||||
$this->_errorMsg = @fbsql_error($this->_connectionID);
|
||||
return $this->_errorMsg;
|
||||
}
|
||||
|
||||
/* Returns: the last error number from previous database operation */
|
||||
function ErrorNo()
|
||||
{
|
||||
return @fbsql_errno($this->_connectionID);
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
function _close()
|
||||
{
|
||||
return @fbsql_close($this->_connectionID);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------------------
|
||||
Class Name: Recordset
|
||||
--------------------------------------------------------------------------------------*/
|
||||
|
||||
class ADORecordSet_fbsql extends ADORecordSet{
|
||||
|
||||
var $databaseType = "fbsql";
|
||||
var $canSeek = true;
|
||||
|
||||
function ADORecordSet_fbsql($queryID) {
|
||||
global $ADODB_FETCH_MODE;
|
||||
|
||||
switch($ADODB_FETCH_MODE) {
|
||||
case ADODB_FETCH_NUM: $this->fetchMode = FBSQL_NUM; break;
|
||||
default:
|
||||
case ADODB_FETCH_BOTH: $this->fetchMode = FBSQL_BOTH; break;
|
||||
case ADODB_FETCH_ASSOC: $this->fetchMode = FBSQL_ASSOC; break;
|
||||
}
|
||||
return $this->ADORecordSet($queryID);
|
||||
}
|
||||
|
||||
function _initrs()
|
||||
{
|
||||
GLOBAL $ADODB_COUNTRECS;
|
||||
$this->_numOfRows = ($ADODB_COUNTRECS) ? @fbsql_num_rows($this->_queryID):-1;
|
||||
$this->_numOfFields = @fbsql_num_fields($this->_queryID);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function &FetchField($fieldOffset = -1) {
|
||||
if ($fieldOffset != -1) {
|
||||
$o = @fbsql_fetch_field($this->_queryID, $fieldOffset);
|
||||
//$o->max_length = -1; // fbsql returns the max length less spaces -- so it is unrealiable
|
||||
$f = @fbsql_field_flags($this->_queryID,$fieldOffset);
|
||||
$o->binary = (strpos($f,'binary')!== false);
|
||||
}
|
||||
else if ($fieldOffset == -1) { /* The $fieldOffset argument is not provided thus its -1 */
|
||||
$o = @fbsql_fetch_field($this->_queryID);// fbsql returns the max length less spaces -- so it is unrealiable
|
||||
//$o->max_length = -1;
|
||||
}
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
function _seek($row)
|
||||
{
|
||||
return @fbsql_data_seek($this->_queryID,$row);
|
||||
}
|
||||
|
||||
function _fetch($ignore_fields=false)
|
||||
{
|
||||
$this->fields = @fbsql_fetch_array($this->_queryID,$this->fetchMode);
|
||||
return ($this->fields == true);
|
||||
}
|
||||
|
||||
function _close() {
|
||||
return @fbsql_free_result($this->_queryID);
|
||||
}
|
||||
|
||||
function MetaType($t,$len=-1,$fieldobj=false)
|
||||
{
|
||||
$len = -1; // fbsql max_length is not accurate
|
||||
switch (strtoupper($t)) {
|
||||
case 'CHARACTER':
|
||||
case 'CHARACTER VARYING':
|
||||
case 'BLOB':
|
||||
case 'CLOB':
|
||||
case 'BIT':
|
||||
case 'BIT VARYING':
|
||||
if ($len <= $this->blobSize) return 'C';
|
||||
|
||||
// so we have to check whether binary...
|
||||
case 'IMAGE':
|
||||
case 'LONGBLOB':
|
||||
case 'BLOB':
|
||||
case 'MEDIUMBLOB':
|
||||
return !empty($fieldobj->binary) ? 'B' : 'X';
|
||||
|
||||
case 'DATE': return 'D';
|
||||
|
||||
case 'TIME':
|
||||
case 'TIME WITH TIME ZONE':
|
||||
case 'TIMESTAMP':
|
||||
case 'TIMESTAMP WITH TIME ZONE': return 'T';
|
||||
|
||||
case 'PRIMARY_KEY':
|
||||
return 'R';
|
||||
case 'INTEGER':
|
||||
case 'SMALLINT':
|
||||
case 'BOOLEAN':
|
||||
|
||||
if (!empty($fieldobj->primary_key)) return 'R';
|
||||
else return 'I';
|
||||
|
||||
default: return 'N';
|
||||
}
|
||||
}
|
||||
|
||||
} //class
|
||||
} // defined
|
||||
?>
|
52
lib/adodb/drivers/adodb-firebird.inc.php
Normal file
52
lib/adodb/drivers/adodb-firebird.inc.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
|
||||
*/
|
||||
|
||||
|
||||
include_once(ADODB_DIR."/drivers/adodb-ibase.inc.php");
|
||||
|
||||
class ADODB_firebird extends ADODB_ibase {
|
||||
var $databaseType = "firebird";
|
||||
|
||||
function ADODB_firebird()
|
||||
{
|
||||
$this->ADODB_ibase();
|
||||
}
|
||||
|
||||
// Note that Interbase 6.5 uses this ROWS instead - don't you love forking wars!
|
||||
// SELECT col1, col2 FROM table ROWS 5 -- get 5 rows
|
||||
// SELECT col1, col2 FROM TABLE ORDER BY col1 ROWS 3 TO 7 -- first 5 skip 2
|
||||
function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false, $arg3=false,$secs=0)
|
||||
{
|
||||
$str = 'SELECT ';
|
||||
if ($nrows >= 0) $str .= "FIRST $nrows ";
|
||||
$str .=($offset>=0) ? "SKIP $offset " : '';
|
||||
|
||||
$sql = preg_replace('/^[ \t]*select/i',$str,$sql);
|
||||
return ($secs) ?
|
||||
$this->CacheExecute($secs,$sql,$inputarr,$arg3)
|
||||
:
|
||||
$this->Execute($sql,$inputarr,$arg3);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
class ADORecordSet_firebird extends ADORecordSet_ibase {
|
||||
|
||||
var $databaseType = "firebird";
|
||||
|
||||
function ADORecordSet_firebird($id)
|
||||
{
|
||||
$this->ADORecordSet_ibase($id);
|
||||
}
|
||||
}
|
||||
?>
|
399
lib/adodb/drivers/adodb-ibase.inc.php
Normal file
399
lib/adodb/drivers/adodb-ibase.inc.php
Normal file
@ -0,0 +1,399 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
|
||||
Interbase data driver. Requires interbase client. Works on Windows and Unix.
|
||||
|
||||
3 Jan 2002 -- suggestions by Hans-Peter Oeri <kampfcaspar75@oeri.ch>
|
||||
changed transaction handling and added experimental blob stuff
|
||||
|
||||
Docs to interbase at the website
|
||||
http://www.synectics.co.za/php3/tutorial/IB_PHP3_API.html
|
||||
|
||||
To use gen_id(), see
|
||||
http://www.volny.cz/iprenosil/interbase/ip_ib_code.htm#_code_creategen
|
||||
|
||||
$rs = $conn->Execute('select gen_id(adodb,1) from rdb$database');
|
||||
$id = $rs->fields[0];
|
||||
$conn->Execute("insert into table (id, col1,...) values ($id, $val1,...)");
|
||||
*/
|
||||
|
||||
class ADODB_ibase extends ADOConnection {
|
||||
var $databaseType = "ibase";
|
||||
var $replaceQuote = "\'"; // string to use to replace quotes
|
||||
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'";
|
||||
var $ibasetrans = IBASE_DEFAULT;
|
||||
var $hasGenID = true;
|
||||
var $_bindInputArray = true;
|
||||
var $buffers = 0;
|
||||
var $dialect = 1;
|
||||
var $sysDate = "cast('TODAY' as date)";
|
||||
var $sysTimeStamp = "cast('NOW' as timestamp)";
|
||||
|
||||
function ADODB_ibase()
|
||||
{
|
||||
ibase_timefmt('%Y-%m-%d');
|
||||
|
||||
}
|
||||
|
||||
function BeginTrans()
|
||||
{
|
||||
$this->autoCommit = false;
|
||||
$this->_transactionID = $this->_connectionID;//ibase_trans($this->ibasetrans, $this->_connectionID);
|
||||
return $this->_transactionID;
|
||||
}
|
||||
|
||||
function CommitTrans($ok=true)
|
||||
{
|
||||
if (!$ok) return $this->RollbackTrans();
|
||||
$ret = false;
|
||||
$this->autoCommit = true;
|
||||
if ($this->_transactionID) {
|
||||
//print ' commit ';
|
||||
$ret = ibase_commit($this->_transactionID);
|
||||
}
|
||||
$this->_transactionID = false;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function RollbackTrans()
|
||||
{
|
||||
$ret = false;
|
||||
$this->autoCommit = true;
|
||||
if ($this->_transactionID)
|
||||
$ret = ibase_rollback($this->_transactionID);
|
||||
$this->_transactionID = false;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// See http://community.borland.com/article/0,1410,25844,00.html
|
||||
function RowLock($tables,$where,$col)
|
||||
{
|
||||
if ($this->autoCommit) $this->BeginTrans();
|
||||
$this->Execute("UPDATE $table SET $col=$col WHERE $where "); // is this correct - jlim?
|
||||
return 1;
|
||||
}
|
||||
|
||||
function GenID($seqname='adodbseq',$startID=1)
|
||||
{
|
||||
$getnext = ("SELECT Gen_ID($seqname,1) FROM RDB\$DATABASE");
|
||||
$rs = @$this->Execute($getnext);
|
||||
if (!$rs) {
|
||||
$u = strtoupper($seqname);
|
||||
$this->Execute(("INSERT INTO RDB\$GENERATORS (RDB\$GENERATOR_NAME) VALUES (UPPER('$seqname'))" ));
|
||||
$this->Execute("SET GENERATOR $seqname TO ".($startID-1).';');
|
||||
$rs = $this->Execute($getnext);
|
||||
}
|
||||
if ($rs && !$rs->EOF) $this->genID = (integer) reset($rs->fields);
|
||||
else $this->genID = 0; // false
|
||||
|
||||
if ($rs) $rs->Close();
|
||||
|
||||
return $this->genID;
|
||||
}
|
||||
|
||||
function SelectDB($dbName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function _handleerror()
|
||||
{
|
||||
$this->_errorMsg = ibase_errmsg();
|
||||
}
|
||||
|
||||
function ErrorNo() {
|
||||
if (preg_match('/error code = ([\-0-9]*)/i', $this->_errorMsg,$arr)) return (integer) $arr[1];
|
||||
else return 0;
|
||||
}
|
||||
|
||||
function ErrorMsg() {
|
||||
return $this->_errorMsg;
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
|
||||
{
|
||||
//if ($this->charSet !== false)
|
||||
$this->_connectionID = ibase_connect($argHostname,$argUsername,$argPassword,$this->charSet,$this->buffers,$this->dialect);
|
||||
// else
|
||||
// $this->_connectionID = ibase_connect($argHostname,$argUsername,$argPassword);
|
||||
|
||||
if ($this->_connectionID === false) {
|
||||
$this->_handleerror();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
// returns true or false
|
||||
function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
|
||||
{
|
||||
//if ($this->charSet !== false)
|
||||
$this->_connectionID = ibase_pconnect($argHostname,$argUsername,$argPassword,$this->charSet,$this->buffers,$this->dialect);
|
||||
// else
|
||||
// $this->_connectionID = ibase_pconnect($argHostname,$argUsername,$argPassword);
|
||||
|
||||
if ($this->_connectionID === false) {
|
||||
$this->_handleerror();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function Prepare($sql)
|
||||
{
|
||||
return $sql;
|
||||
$stmt = ibase_prepare($sql);
|
||||
if (!$stmt) return false;
|
||||
return array($sql,$stmt);
|
||||
}
|
||||
|
||||
// returns query ID if successful, otherwise false
|
||||
// there have been reports of problems with nested queries - the code is probably not re-entrant?
|
||||
function _query($sql,$iarr=false)
|
||||
{
|
||||
if (is_array($sql)) {
|
||||
$fn = 'ibase_execute';
|
||||
$sql = $sql[1];
|
||||
} else
|
||||
$fn = 'ibase_query';
|
||||
|
||||
if (!$this->autoCommit && $this->_transactionID) {
|
||||
$conn = $this->_transactionID;
|
||||
$docommit = false;
|
||||
} else {
|
||||
$conn = $this->_connectionID;
|
||||
$docommit = true;
|
||||
}
|
||||
if (is_array($iarr)) {
|
||||
switch(sizeof($iarr)) {
|
||||
case 1: $ret = $fn($conn,$sql,$iarr[0]); break;
|
||||
case 2: $ret = $fn($conn,$sql,$iarr[0],$iarr[1]); break;
|
||||
case 3: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2]); break;
|
||||
case 4: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3]); break;
|
||||
case 5: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4]); break;
|
||||
case 6: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5]); break;
|
||||
case 7: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6]); break;
|
||||
default: print "<p>Too many parameters to ibase query $sql</p>";
|
||||
case 8: $ret = $fn($conn,$sql,$iarr[0],$iarr[1],$iarr[2],$iarr[3],$iarr[4],$iarr[5],$iarr[6],$iarr[7]); break;
|
||||
}
|
||||
} else $ret = $fn($conn,$sql);
|
||||
|
||||
if ($docommit && $ret === true) ibase_commit($this->_connectionID);
|
||||
|
||||
$this->_handleerror();
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
function _close()
|
||||
{
|
||||
if (!$this->autoCommit) @ibase_rollback($this->_connectionID);
|
||||
return @ibase_close($this->_connectionID);
|
||||
}
|
||||
|
||||
// returns array of ADOFieldObjects for current table
|
||||
function &MetaColumns($table)
|
||||
{
|
||||
global $ADODB_FETCH_MODE;
|
||||
|
||||
if ($this->metaColumnsSQL) {
|
||||
|
||||
$save = $ADODB_FETCH_MODE;
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
||||
|
||||
$rs = $this->Execute(sprintf($this->metaColumnsSQL,strtoupper($table)));
|
||||
|
||||
$ADODB_FETCH_MODE = $save;
|
||||
if ($rs === false) return false;
|
||||
|
||||
$retarr = array();
|
||||
while (!$rs->EOF) { //print_r($rs->fields);
|
||||
$fld = new ADOFieldObject();
|
||||
$fld->name = $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 13:
|
||||
case 35:$tt = 'TIMESTAMP'; break;
|
||||
}
|
||||
$fld->type = $tt;
|
||||
$fld->max_length = $rs->fields[2];
|
||||
$retarr[strtoupper($fld->name)] = $fld;
|
||||
|
||||
$rs->MoveNext();
|
||||
}
|
||||
$rs->Close();
|
||||
return $retarr;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// no longer needed in php 4.1.0, but still backward compatible
|
||||
function &BlobEncode( $blob )
|
||||
{
|
||||
$blobid = ibase_blob_create( $this->_connectionID);
|
||||
ibase_blob_add( $blobid, $blob );
|
||||
return ibase_blob_close( $blobid );
|
||||
}
|
||||
|
||||
// no longer needed in php 4.1.0, but still backward compatible
|
||||
function &BlobDecode( $blob )
|
||||
{
|
||||
$blobid = ibase_blob_open( $blob );
|
||||
$realblob = ibase_blob_get( $blobid,MAX_BLOB_SIZE); // 2nd param is max size of blob -- Kevin Boillet <kevinboillet@yahoo.fr>
|
||||
ibase_blob_close( $blobid );
|
||||
|
||||
return( $realblob );
|
||||
}
|
||||
|
||||
/*
|
||||
Insert a null into the blob field of the table first.
|
||||
Then use UpdateBlob to store the blob.
|
||||
|
||||
Usage:
|
||||
|
||||
$conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)');
|
||||
$conn->UpdateBlob('blobtable','blobcol',$blob,'id=1');
|
||||
*/
|
||||
function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB')
|
||||
{
|
||||
$blob_id = ibase_blob_create($this->_connectionID);
|
||||
ibase_blob_add($blob_id, $val);
|
||||
$blob_id_str = ibase_blob_close($blob_id);
|
||||
return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blob_id_str)) != false;
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------------------
|
||||
Class Name: Recordset
|
||||
--------------------------------------------------------------------------------------*/
|
||||
|
||||
class ADORecordset_ibase extends ADORecordSet
|
||||
{
|
||||
|
||||
var $databaseType = "ibase";
|
||||
var $bind=false;
|
||||
|
||||
function ADORecordset_ibase($id)
|
||||
{
|
||||
global $ADODB_FETCH_MODE;
|
||||
|
||||
$this->fetchMode = $ADODB_FETCH_MODE;
|
||||
return $this->ADORecordSet($id);
|
||||
}
|
||||
|
||||
/* Returns: an object containing field information.
|
||||
Get column information in the Recordset object. fetchField() can be used in order to obtain information about
|
||||
fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by
|
||||
fetchField() is retrieved. */
|
||||
|
||||
function &FetchField($fieldOffset = -1)
|
||||
{
|
||||
$fld = new ADOFieldObject;
|
||||
$ibf = ibase_field_info($this->_queryID,$fieldOffset);
|
||||
$fld->name = strtolower($ibf['name']);
|
||||
if (empty($fld->name)) $fld->name = $ibf['alias'];
|
||||
$fld->type = $ibf['type'];
|
||||
$fld->max_length = $ibf['length'];
|
||||
if ($this->debug) print_r($fld);
|
||||
return $fld;
|
||||
}
|
||||
|
||||
function _initrs()
|
||||
{
|
||||
$this->_numOfRows = -1;
|
||||
$this->_numOfFields = @ibase_num_fields($this->_queryID);
|
||||
}
|
||||
|
||||
function _seek($row)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
function _fetch() {
|
||||
|
||||
$f = ibase_fetch_row($this->_queryID);
|
||||
if ($f === false) return false;
|
||||
|
||||
$this->fields = $f;
|
||||
if ($this->fetchMode & ADODB_FETCH_ASSOC) {
|
||||
$this->fields = $this->GetRowAssoc(false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Use associative array to get fields array */
|
||||
function Fields($colname)
|
||||
{
|
||||
if ($this->fetchMode & ADODB_FETCH_ASSOC) 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 _close()
|
||||
{
|
||||
return @ibase_free_result($this->_queryID);
|
||||
}
|
||||
|
||||
function MetaType($t,$len=-1)
|
||||
{
|
||||
switch (strtoupper($t)) {
|
||||
case 'CHAR':
|
||||
return 'C';
|
||||
|
||||
case 'TEXT':
|
||||
case 'VARCHAR':
|
||||
case 'VARYING':
|
||||
if ($len <= $this->blobSize) return 'C';
|
||||
return 'X';
|
||||
case 'BLOB':
|
||||
return 'B';
|
||||
|
||||
case 'TIMESTAMP':
|
||||
case 'DATE': return 'D';
|
||||
|
||||
//case 'T': return 'T';
|
||||
|
||||
//case 'L': return 'L';
|
||||
case 'INT':
|
||||
case 'SHORT':
|
||||
case 'INTEGER': return 'I';
|
||||
default: return 'N';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
30
lib/adodb/drivers/adodb-informix.inc.php
Normal file
30
lib/adodb/drivers/adodb-informix.inc.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* @version V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my).
|
||||
All rights reserved.
|
||||
* Released under both BSD license and Lesser GPL library license.
|
||||
* Whenever there is any discrepancy between the two licenses,
|
||||
* the BSD license will take precedence.
|
||||
*
|
||||
* Set tabs to 4 for best viewing.
|
||||
*
|
||||
* Latest version is available at http://php.weblogs.com
|
||||
*
|
||||
* Informix 9 driver that supports SELECT FIRST
|
||||
*
|
||||
*/
|
||||
include_once(ADODB_DIR.'/drivers/adodb-informix72.inc.php');
|
||||
|
||||
class ADODB_informix extends ADODB_informix72 {
|
||||
var $databaseType = "informix";
|
||||
var $hasTop = 'FIRST';
|
||||
}
|
||||
|
||||
class ADORecordset_informix extends ADORecordset_informix72 {
|
||||
var $databaseType = "informix";
|
||||
function ADORecordset_informix($id)
|
||||
{
|
||||
$this->ADORecordset_informix72($id);
|
||||
}
|
||||
}
|
||||
?>
|
286
lib/adodb/drivers/adodb-informix72.inc.php
Normal file
286
lib/adodb/drivers/adodb-informix72.inc.php
Normal file
@ -0,0 +1,286 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 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.
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
|
||||
Informix port by Mitchell T. Young (mitch@youngfamily.org)
|
||||
|
||||
Further mods by "Samuel CARRIERE" <samuel_carriere@hotmail.com>
|
||||
|
||||
*/
|
||||
|
||||
class ADODB_informix72 extends ADOConnection {
|
||||
var $databaseType = "informix72";
|
||||
var $dataProvider = "informix";
|
||||
var $replaceQuote = "''"; // string to use to replace quotes
|
||||
var $fmtDate = "'Y-m-d'";
|
||||
var $fmtTimeStamp = "'Y-m-d H:i:s'";
|
||||
var $hasInsertID = true;
|
||||
var $hasAffectedRows = true;
|
||||
var $metaTablesSQL="select tabname from systables";
|
||||
var $metaColumnsSQL = "select colname, coltype, collength from syscolumns c, systables t where c.tabid=t.tabid and tabname='%s'";
|
||||
var $concat_operator = '||';
|
||||
|
||||
var $lastQuery = false;
|
||||
var $has_insertid = true;
|
||||
|
||||
var $_autocommit = true;
|
||||
var $_bindInputArray = true; // set to true if ADOConnection.Execute() permits binding of array parameters.
|
||||
var $sysDate = 'TODAY';
|
||||
var $sysTimeStamp = 'CURRENT';
|
||||
|
||||
function ADODB_informix72()
|
||||
{
|
||||
|
||||
// alternatively, use older method:
|
||||
//putenv("DBDATE=Y4MD-");
|
||||
|
||||
// force ISO date format
|
||||
putenv('GL_DATE=%Y-%m-%d');
|
||||
}
|
||||
|
||||
function _insertid()
|
||||
{
|
||||
$sqlca =ifx_getsqlca($this->lastQuery);
|
||||
return @$sqlca["sqlerrd1"];
|
||||
}
|
||||
|
||||
function _affectedrows()
|
||||
{
|
||||
if ($this->lastQuery) {
|
||||
return ifx_affected_rows ($this->lastQuery);
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
function BeginTrans()
|
||||
{
|
||||
$this->Execute('BEGIN');
|
||||
$this->_autocommit = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
function CommitTrans($ok=true)
|
||||
{
|
||||
if (!$ok) return $this->RollbackTrans();
|
||||
$this->Execute('COMMIT');
|
||||
$this->_autocommit = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
function RollbackTrans()
|
||||
{
|
||||
$this->Execute('ROLLBACK');
|
||||
$this->_autocommit = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
function RowLock($tables,$where)
|
||||
{
|
||||
if ($this->_autocommit) $this->BeginTrans();
|
||||
return $this->GetOne("select 1 as ignore from $tables where $where for update");
|
||||
}
|
||||
|
||||
/* Returns: the last error message from previous database operation
|
||||
Note: This function is NOT available for Microsoft SQL Server. */
|
||||
|
||||
function ErrorMsg() {
|
||||
$this->_errorMsg = ifx_errormsg();
|
||||
return $this->_errorMsg;
|
||||
}
|
||||
|
||||
function ErrorNo() {
|
||||
return ifx_error();
|
||||
}
|
||||
|
||||
function MetaColumns($table)
|
||||
{
|
||||
return ADOConnection::MetaColumns($table,false);
|
||||
}
|
||||
|
||||
|
||||
// returns true or false
|
||||
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
|
||||
{
|
||||
$dbs = $argDatabasename . "@" . $argHostname;
|
||||
$this->_connectionID = ifx_connect($dbs,$argUsername,$argPassword);
|
||||
if ($this->_connectionID === false) return false;
|
||||
#if ($argDatabasename) return $this->SelectDB($argDatabasename);
|
||||
return true;
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
|
||||
{
|
||||
$dbs = $argDatabasename . "@" . $argHostname;
|
||||
$this->_connectionID = ifx_pconnect($dbs,$argUsername,$argPassword);
|
||||
if ($this->_connectionID === false) return false;
|
||||
#if ($argDatabasename) return $this->SelectDB($argDatabasename);
|
||||
return true;
|
||||
}
|
||||
|
||||
// returns query ID if successful, otherwise false
|
||||
function _query($sql,$inputarr)
|
||||
{
|
||||
// String parameters have to be converted using ifx_create_char
|
||||
if ($inputarr) {
|
||||
foreach($inputarr as $v) {
|
||||
if (gettype($v) == 'string') {
|
||||
$tab[] = ifx_create_char($v);
|
||||
}
|
||||
else {
|
||||
$tab[] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// In case of select statement, we use a scroll cursor in order
|
||||
// to be able to call "move", or "movefirst" statements
|
||||
if (preg_match("/^[\\t\\n ]*select/i", $sql)) {
|
||||
if ($inputarr) {
|
||||
$this->lastQuery = ifx_query($sql,$this->_connectionID, IFX_SCROLL, $tab);
|
||||
}
|
||||
else {
|
||||
$this->lastQuery = ifx_query($sql,$this->_connectionID, IFX_SCROLL);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($inputarr) {
|
||||
$this->lastQuery = ifx_query($sql,$this->_connectionID, $tab);
|
||||
}
|
||||
else {
|
||||
$this->lastQuery = ifx_query($sql,$this->_connectionID);
|
||||
}
|
||||
}
|
||||
|
||||
// Following line have been commented because autocommit mode is
|
||||
// not supported by informix SE 7.2
|
||||
|
||||
//if ($this->_autocommit) ifx_query('COMMIT',$this->_connectionID);
|
||||
|
||||
return $this->lastQuery;
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
function _close()
|
||||
{
|
||||
$this->lastQuery = false;
|
||||
return ifx_close($this->_connectionID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------------------------
|
||||
Class Name: Recordset
|
||||
--------------------------------------------------------------------------------------*/
|
||||
|
||||
class ADORecordset_informix72 extends ADORecordSet {
|
||||
|
||||
var $databaseType = "informix72";
|
||||
var $canSeek = true;
|
||||
var $_fieldprops = false;
|
||||
|
||||
function ADORecordset_informix72($id)
|
||||
{
|
||||
global $ADODB_FETCH_MODE;
|
||||
|
||||
$this->fetchMode = $ADODB_FETCH_MODE;
|
||||
return $this->ADORecordSet($id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Returns: an object containing field information.
|
||||
Get column information in the Recordset object. fetchField() can be used in order to obtain information about
|
||||
fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by
|
||||
fetchField() is retrieved. */
|
||||
function &FetchField($fieldOffset = -1)
|
||||
{
|
||||
if (empty($this->_fieldprops)) {
|
||||
$fp = ifx_fieldproperties($this->_queryID);
|
||||
foreach($fp as $k => $v) {
|
||||
$o = new ADOFieldObject;
|
||||
$o->name = $k;
|
||||
$arr = split(';',$v); //"SQLTYPE;length;precision;scale;ISNULLABLE"
|
||||
$o->type = $arr[0];
|
||||
$o->max_length = $arr[1];
|
||||
$this->_fieldprops[] = $o;
|
||||
}
|
||||
}
|
||||
return $this->_fieldprops[$fieldOffset];
|
||||
}
|
||||
|
||||
function _initrs()
|
||||
{
|
||||
$this->_numOfRows = -1; // ifx_affected_rows not reliable, only returns estimate -- ($ADODB_COUNTRECS)? ifx_affected_rows($this->_queryID):-1;
|
||||
$this->_numOfFields = ifx_num_fields($this->_queryID);
|
||||
}
|
||||
|
||||
function _seek($row)
|
||||
{
|
||||
return @ifx_fetch_row($this->_queryID, $row);
|
||||
}
|
||||
|
||||
function MoveLast()
|
||||
{
|
||||
$this->fields = @ifx_fetch_row($this->_queryID, "LAST");
|
||||
if ($this->fields) $this->EOF = false;
|
||||
$this->_currentRow = -1;
|
||||
|
||||
if ($this->fetchMode == ADODB_FETCH_NUM) {
|
||||
foreach($this->fields as $v) {
|
||||
$arr[] = $v;
|
||||
}
|
||||
$this->fields = $arr;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function MoveFirst()
|
||||
{
|
||||
$this->fields = @ifx_fetch_row($this->_queryID, "FIRST");
|
||||
if ($this->fields) $this->EOF = false;
|
||||
$this->_currentRow = 0;
|
||||
|
||||
if ($this->fetchMode == ADODB_FETCH_NUM) {
|
||||
foreach($this->fields as $v) {
|
||||
$arr[] = $v;
|
||||
}
|
||||
$this->fields = $arr;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function _fetch($ignore_fields=false)
|
||||
{
|
||||
|
||||
$this->fields = @ifx_fetch_row($this->_queryID);
|
||||
|
||||
if (!is_array($this->fields)) return false;
|
||||
|
||||
if ($this->fetchMode == ADODB_FETCH_NUM) {
|
||||
foreach($this->fields as $v) {
|
||||
$arr[] = $v;
|
||||
}
|
||||
$this->fields = $arr;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* close() only needs to be called if you are worried about using too much memory while your script
|
||||
is running. All associated result memory for the specified result identifier will automatically be freed. */
|
||||
function _close()
|
||||
{
|
||||
return ifx_free_result($this->_queryID);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
525
lib/adodb/drivers/adodb-mssql.inc.php
Normal file
525
lib/adodb/drivers/adodb-mssql.inc.php
Normal file
@ -0,0 +1,525 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
|
||||
Native mssql driver. Requires mssql client. Works on Windows.
|
||||
To configure for Unix, see
|
||||
http://phpbuilder.com/columns/alberto20000919.php3
|
||||
|
||||
*/
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// MSSQL returns dates with the format Oct 13 2002 or 13 Oct 2002
|
||||
// and this causes tons of problems because localized versions of
|
||||
// MSSQL will return the dates in dmy or mdy order; and also the
|
||||
// month strings depends on what language has been configured. The
|
||||
// following two variables allow you to control the localization
|
||||
// settings - Ugh.
|
||||
//
|
||||
// MORE LOCALIZATION INFO
|
||||
// ----------------------
|
||||
// To configure datetime, look for and modify sqlcommn.loc,
|
||||
// typically found in c:\mssql\install
|
||||
// Also read :
|
||||
// http://support.microsoft.com/default.aspx?scid=kb;EN-US;q220918
|
||||
// Alternatively use:
|
||||
// CONVERT(char(12),datecol,120)
|
||||
//----------------------------------------------------------------
|
||||
|
||||
global $ADODB_mssql_date_order; // 'dmy' and 'mdy' supported
|
||||
global $ADODB_mssql_mths; // array, months must be upper-case
|
||||
|
||||
$ADODB_mssql_date_order = 'mdy';
|
||||
$ADODB_mssql_mths = array(
|
||||
'JAN'=>1,'FEB'=>2,'MAR'=>3,'APR'=>4,'MAY'=>5,'JUN'=>6,
|
||||
'JUL'=>7,'AUG'=>8,'SEP'=>9,'OCT'=>10,'NOV'=>11,'DEC'=>12);
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Call this to autoset $ADODB_mssql_date_order at the beginning of your code,
|
||||
// just after you connect to the database. Supports mdy and dmy only
|
||||
function AutoDetect_MSSQL_Date_Order($conn)
|
||||
{
|
||||
global $ADODB_mssql_date_order;
|
||||
|
||||
$adate = $conn->GetOne('select getdate()');
|
||||
|
||||
if ($adate) {
|
||||
$anum = (int) $adate;
|
||||
if ($anum > 0) {
|
||||
if ($anum > 31) {
|
||||
print "<p>MSSQL: YYYY-MM-DD date format not supported currently</p>";
|
||||
} else
|
||||
$ADODB_mssql_date_order = 'dmy';
|
||||
} else
|
||||
$ADODB_mssql_date_order = 'mdy';
|
||||
}
|
||||
}
|
||||
|
||||
class ADODB_mssql extends ADOConnection {
|
||||
var $databaseType = "mssql";
|
||||
var $replaceQuote = "''"; // string to use to replace quotes
|
||||
var $fmtDate = "'Y-m-d'";
|
||||
var $fmtTimeStamp = "'Y-m-d h:i:sA'";
|
||||
var $hasInsertID = true;
|
||||
var $hasAffectedRows = true;
|
||||
var $metaTablesSQL="select name from sysobjects where type='U' or type='V' and (name not in ('sysallocations','syscolumns','syscomments','sysdepends','sysfilegroups','sysfiles','sysfiles1','sysforeignkeys','sysfulltextcatalogs','sysindexes','sysindexkeys','sysmembers','sysobjects','syspermissions','sysprotects','sysreferences','systypes','sysusers','sysalternates','sysconstraints','syssegments','REFERENTIAL_CONSTRAINTS','CHECK_CONSTRAINTS','CONSTRAINT_TABLE_USAGE','CONSTRAINT_COLUMN_USAGE','VIEWS','VIEW_TABLE_USAGE','VIEW_COLUMN_USAGE','SCHEMATA','TABLES','TABLE_CONSTRAINTS','TABLE_PRIVILEGES','COLUMNS','COLUMN_DOMAIN_USAGE','COLUMN_PRIVILEGES','DOMAINS','DOMAIN_CONSTRAINTS','KEY_COLUMN_USAGE'))";
|
||||
var $metaColumnsSQL = "select c.name,t.name,c.length from syscolumns c join systypes t on t.xusertype=c.xusertype join sysobjects o on o.id=c.id where o.name='%s'";
|
||||
var $hasTop = 'top'; // support mssql SELECT TOP 10 * FROM TABLE
|
||||
var $_hastrans = false;
|
||||
var $hasGenID = true;
|
||||
var $sysDate = 'GetDate()';
|
||||
var $sysTimeStamp = 'GetDate()';
|
||||
var $_has_mssql_init;
|
||||
var $maxParameterLen = 4000;
|
||||
var $arrayClass = 'ADORecordSet_array_mssql';
|
||||
|
||||
function ADODB_mssql()
|
||||
{
|
||||
$this->_has_mssql_init = (strnatcmp(PHP_VERSION,'4.1.0')>=0);
|
||||
|
||||
}
|
||||
|
||||
// might require begintrans -- committrans
|
||||
function _insertid()
|
||||
{
|
||||
return $this->GetOne('select @@identity');
|
||||
}
|
||||
// might require begintrans -- committrans
|
||||
function _affectedrows()
|
||||
{
|
||||
return $this->GetOne('select @@rowcount');
|
||||
}
|
||||
|
||||
function BeginTrans()
|
||||
{
|
||||
$this->_hastrans = true;
|
||||
$this->Execute('BEGIN TRAN');
|
||||
return true;
|
||||
}
|
||||
|
||||
function GenID($seq='adodbseq',$start=1)
|
||||
{
|
||||
//$this->debug=1;
|
||||
$this->Execute('BEGIN TRANSACTION adodbseq');
|
||||
$ok = $this->Execute("update $seq with (tablock,holdlock) set id = id + 1");
|
||||
if (!$ok) {
|
||||
$this->Execute("create table $seq (id float(53))");
|
||||
$ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)");
|
||||
if (!$ok) {
|
||||
$this->Execute('ROLLBACK TRANSACTION adodbseq');
|
||||
return false;
|
||||
}
|
||||
$this->Execute('COMMIT TRANSACTION adodbseq');
|
||||
return 1;
|
||||
}
|
||||
$num = $this->GetOne("select id from $seq");
|
||||
$this->Execute('COMMIT TRANSACTION adodbseq');
|
||||
return $num;
|
||||
|
||||
// in old implementation, pre 1.90, we returned GUID...
|
||||
//return $this->GetOne("SELECT CONVERT(varchar(255), NEWID()) AS 'Char'");
|
||||
}
|
||||
|
||||
function CommitTrans($ok=true)
|
||||
{
|
||||
if (!$ok) return $this->RollbackTrans();
|
||||
if (!$this->_hastrans) return false;
|
||||
$this->_hastrans = false;
|
||||
$this->Execute('COMMIT TRAN');
|
||||
return true;
|
||||
}
|
||||
function RollbackTrans()
|
||||
{
|
||||
if (!$this->_hastrans) return false;
|
||||
$this->_hastrans = false;
|
||||
$this->Execute('ROLLBACK TRAN');
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
Usage:
|
||||
|
||||
$this->BeginTrans();
|
||||
$this->RowLock('table1,table2','table1.id=33 and table2.id=table1.id'); # lock row 33 for both tables
|
||||
|
||||
# some operation on both tables table1 and table2
|
||||
|
||||
$this->CommitTrans();
|
||||
|
||||
See http://www.swynk.com/friends/achigrik/SQL70Locks.asp
|
||||
*/
|
||||
function RowLock($tables,$where)
|
||||
{
|
||||
if (!$this->_hastrans) $this->BeginTrans();
|
||||
return $this->GetOne("select top 1 null as ignore from $tables with (ROWLOCK,HOLDLOCK) where $where");
|
||||
}
|
||||
|
||||
//From: Fernando Moreira <FMoreira@imediata.pt>
|
||||
function MetaDatabases()
|
||||
{
|
||||
if(@mssql_select_db("master")) {
|
||||
$qry="select name from sysdatabases where name <> 'master'";
|
||||
if($rs=@mssql_query($qry)){
|
||||
$tmpAr=$ar=array();
|
||||
while($tmpAr=@mssql_fetch_row($rs))
|
||||
$ar[]=$tmpAr[0];
|
||||
@mssql_select_db($this->databaseName);
|
||||
if(sizeof($ar))
|
||||
return($ar);
|
||||
else
|
||||
return(false);
|
||||
} else {
|
||||
@mssql_select_db($this->databaseName);
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
|
||||
function SelectDB($dbName)
|
||||
{
|
||||
$this->databaseName = $dbName;
|
||||
if ($this->_connectionID) {
|
||||
return @mssql_select_db($dbName);
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
/* Returns: the last error message from previous database operation
|
||||
Note: This function is NOT available for Microsoft SQL Server. */
|
||||
function ErrorMsg()
|
||||
{
|
||||
$this->_errorMsg = mssql_get_last_message();
|
||||
return $this->_errorMsg;
|
||||
}
|
||||
|
||||
function ErrorNo()
|
||||
{
|
||||
$id = @mssql_query("select @@ERROR",$this->_connectionID);
|
||||
if (!$id) return false;
|
||||
$arr = mssql_fetch_array($id);
|
||||
@mssql_free_result($id);
|
||||
if (is_array($arr)) return $arr[0];
|
||||
else return -1;
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
|
||||
{
|
||||
$this->_connectionID = mssql_connect($argHostname,$argUsername,$argPassword);
|
||||
if ($this->_connectionID === false) return false;
|
||||
if ($argDatabasename) return $this->SelectDB($argDatabasename);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// returns true or false
|
||||
function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
|
||||
{
|
||||
$this->_connectionID = mssql_pconnect($argHostname,$argUsername,$argPassword);
|
||||
if ($this->_connectionID === false) return false;
|
||||
if ($argDatabasename) return $this->SelectDB($argDatabasename);
|
||||
return true;
|
||||
}
|
||||
|
||||
function Prepare($sql)
|
||||
{
|
||||
return $sql;
|
||||
}
|
||||
|
||||
function PrepareSP($sql)
|
||||
{
|
||||
if (!$this->_has_mssql_init) {
|
||||
print "PrepareSP: mssql_init only available since PHP 4.1.0<br>\n";
|
||||
return $sql;
|
||||
}
|
||||
$stmt = mssql_init($sql,$this->_connectionID);
|
||||
if (!$stmt) return $sql;
|
||||
return array($sql,$stmt);
|
||||
}
|
||||
|
||||
/*
|
||||
Usage:
|
||||
$stmt = $db->PrepareSP('SP_RUNSOMETHING'); -- takes 2 params, @myid and @group
|
||||
|
||||
# note that the parameter does not have @ in front!
|
||||
$db->Parameter($stmt,$id,'myid');
|
||||
$db->Parameter($stmt,$group,'group',false,64);
|
||||
$db->Execute($stmt);
|
||||
|
||||
@param $stmt Statement returned by Prepare() or PrepareSP().
|
||||
@param $var PHP variable to bind to. Can set to null (for isNull support).
|
||||
@param $name Name of stored procedure variable name to bind to.
|
||||
@param [$isOutput] Indicates direction of parameter 0/false=IN 1=OUT 2= IN/OUT. This is ignored in oci8.
|
||||
@param [$maxLen] Holds an maximum length of the variable.
|
||||
@param [$type] The data type of $var. Legal values depend on driver.
|
||||
|
||||
See mssql_bind documentation at php.net.
|
||||
*/
|
||||
function Parameter(&$stmt, &$var, $name, $isOutput=false, $maxLen=4000, $type=false)
|
||||
{
|
||||
if (!$this->_has_mssql_init) {
|
||||
print "Parameter: mssql_bind only available since PHP 4.1.0<br>\n";
|
||||
return $sql;
|
||||
}
|
||||
|
||||
$isNull = is_null($var); // php 4.0.4 and above...
|
||||
|
||||
if ($type === false)
|
||||
switch(gettype($var)) {
|
||||
default:
|
||||
case 'string': $type = SQLCHAR; break;
|
||||
case 'double': $type = SQLFLT8; break;
|
||||
case 'integer': $type = SQLINT4; break;
|
||||
case 'boolean': $type = SQLINT1; break; # SQLBIT not supported in 4.1.0
|
||||
}
|
||||
|
||||
if ($this->debug) {
|
||||
print "Parameter(\$stmt, \$php_var='$var', \$name='$name'); (type=$type)<br>\n";
|
||||
}
|
||||
return mssql_bind($stmt[1], '@'.$name, $var, $type, $isOutput, $isNull, $maxLen);
|
||||
}
|
||||
|
||||
/*
|
||||
Unfortunately, it appears that mssql cannot handle varbinary > 255 chars
|
||||
So all your blobs must be of type "image".
|
||||
|
||||
Remember to set in php.ini the following...
|
||||
|
||||
; Valid range 0 - 2147483647. Default = 4096.
|
||||
mssql.textlimit = 0 ; zero to pass through
|
||||
|
||||
; Valid range 0 - 2147483647. Default = 4096.
|
||||
mssql.textsize = 0 ; zero to pass through
|
||||
*/
|
||||
function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB')
|
||||
{
|
||||
$sql = "UPDATE $table SET $column=0x".bin2hex($val)." WHERE $where";
|
||||
return $this->Execute($sql) != false;
|
||||
}
|
||||
|
||||
// returns query ID if successful, otherwise false
|
||||
function _query($sql,$inputarr)
|
||||
{
|
||||
if (is_array($sql)) return mssql_execute($sql[1]);
|
||||
return mssql_query($sql,$this->_connectionID);
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
function _close()
|
||||
{
|
||||
if ($this->_hastrans) $this->RollbackTrans();
|
||||
$rez = @mssql_close($this->_connectionID);
|
||||
$this->_connectionID = false;
|
||||
return $rez;
|
||||
}
|
||||
|
||||
// mssql uses a default date like Dec 30 2000 12:00AM
|
||||
function UnixDate($v)
|
||||
{
|
||||
return ADORecordSet_array_mssql::UnixDate($v);
|
||||
}
|
||||
|
||||
function UnixTimeStamp($v)
|
||||
{
|
||||
return ADORecordSet_array_mssql::UnixTimeStamp($v);
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------------------
|
||||
Class Name: Recordset
|
||||
--------------------------------------------------------------------------------------*/
|
||||
|
||||
class ADORecordset_mssql extends ADORecordSet {
|
||||
|
||||
var $databaseType = "mssql";
|
||||
var $canSeek = true;
|
||||
// _mths works only in non-localised system
|
||||
|
||||
function ADORecordset_mssql($id)
|
||||
{
|
||||
GLOBAL $ADODB_FETCH_MODE;
|
||||
|
||||
$this->fetchMode = $ADODB_FETCH_MODE;
|
||||
return $this->ADORecordSet($id);
|
||||
}
|
||||
|
||||
//Contributed by "Sven Axelsson" <sven.axelsson@bokochwebb.se>
|
||||
// get next resultset - requires PHP 4.0.5 or later
|
||||
function NextRecordSet()
|
||||
{
|
||||
if (!mssql_next_result($this->_queryID)) return false;
|
||||
$this->_inited = false;
|
||||
$this->bind = false;
|
||||
$this->_currentRow = -1;
|
||||
$this->Init();
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Use associative array to get fields array */
|
||||
function Fields($colname)
|
||||
{
|
||||
if ($this->fetchMode != ADODB_FETCH_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)]];
|
||||
}
|
||||
|
||||
/* Returns: an object containing field information.
|
||||
Get column information in the Recordset object. fetchField() can be used in order to obtain information about
|
||||
fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by
|
||||
fetchField() is retrieved. */
|
||||
|
||||
function FetchField($fieldOffset = -1)
|
||||
{
|
||||
if ($fieldOffset != -1) {
|
||||
return @mssql_fetch_field($this->_queryID, $fieldOffset);
|
||||
}
|
||||
else if ($fieldOffset == -1) { /* The $fieldOffset argument is not provided thus its -1 */
|
||||
return @mssql_fetch_field($this->_queryID);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function _initrs()
|
||||
{
|
||||
GLOBAL $ADODB_COUNTRECS;
|
||||
$this->_numOfRows = ($ADODB_COUNTRECS)? @mssql_num_rows($this->_queryID):-1;
|
||||
$this->_numOfFields = @mssql_num_fields($this->_queryID);
|
||||
}
|
||||
|
||||
function _seek($row)
|
||||
{
|
||||
return @mssql_data_seek($this->_queryID, $row);
|
||||
}
|
||||
|
||||
// speedup
|
||||
function MoveNext()
|
||||
{
|
||||
if (!$this->EOF) {
|
||||
$this->_currentRow++;
|
||||
if ($this->fetchMode & ADODB_FETCH_ASSOC) $this->fields = @mssql_fetch_array($this->_queryID);
|
||||
else $this->fields = @mssql_fetch_row($this->_queryID);
|
||||
|
||||
if (is_array($this->fields)) return true;
|
||||
$this->EOF = true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// INSERT UPDATE DELETE returns false even if no error occurs in 4.0.4
|
||||
// also the date format has been changed from YYYY-mm-dd to dd MMM YYYY in 4.0.4. Idiot!
|
||||
function _fetch($ignore_fields=false)
|
||||
{
|
||||
if ($this->fetchMode & ADODB_FETCH_ASSOC) $this->fields = @mssql_fetch_array($this->_queryID);
|
||||
else $this->fields = @mssql_fetch_row($this->_queryID);
|
||||
return (!empty($this->fields));
|
||||
}
|
||||
|
||||
/* close() only needs to be called if you are worried about using too much memory while your script
|
||||
is running. All associated result memory for the specified result identifier will automatically be freed. */
|
||||
|
||||
function _close() {
|
||||
$rez = @mssql_free_result($this->_queryID);
|
||||
$this->_queryID = false;
|
||||
return $rez;
|
||||
}
|
||||
// mssql uses a default date like Dec 30 2000 12:00AM
|
||||
function UnixDate($v)
|
||||
{
|
||||
return ADORecordSet_array_mssql::UnixDate($v);
|
||||
}
|
||||
|
||||
function UnixTimeStamp($v)
|
||||
{
|
||||
return ADORecordSet_array_mssql::UnixTimeStamp($v);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class ADORecordSet_array_mssql extends ADORecordSet_array {
|
||||
function ADORecordSet_array_mssql($id=-1)
|
||||
{
|
||||
$this->ADORecordSet_array($id);
|
||||
}
|
||||
|
||||
// mssql uses a default date like Dec 30 2000 12:00AM
|
||||
function UnixDate($v)
|
||||
{
|
||||
global $ADODB_mssql_mths,$ADODB_mssql_date_order;
|
||||
|
||||
//Dec 30 2000 12:00AM
|
||||
if ($ADODB_mssql_date_order == 'dmy') {
|
||||
if (!preg_match( "|^([0-9]{1,2})[-/\. ]+([A-Za-z]{3})[-/\. ]+([0-9]{4})|" ,$v, $rr)) {
|
||||
return parent::UnixDate($v);
|
||||
}
|
||||
if ($rr[3] <= 1970) return 0;
|
||||
|
||||
$theday = $rr[1];
|
||||
$themth = substr(strtoupper($rr[2]),0,3);
|
||||
} else {
|
||||
if (!preg_match( "|^([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4})|" ,$v, $rr)) {
|
||||
return parent::UnixDate($v);
|
||||
}
|
||||
if ($rr[3] <= 1970) return 0;
|
||||
|
||||
$theday = $rr[2];
|
||||
$themth = substr(strtoupper($rr[1]),0,3);
|
||||
}
|
||||
$themth = $ADODB_mssql_mths[$themth];
|
||||
if ($themth <= 0) return false;
|
||||
// h-m-s-MM-DD-YY
|
||||
return mktime(0,0,0,$themth,$theday,$rr[3]);
|
||||
}
|
||||
|
||||
function UnixTimeStamp($v)
|
||||
{
|
||||
global $ADODB_mssql_mths,$ADODB_mssql_date_order;
|
||||
|
||||
//Dec 30 2000 12:00AM
|
||||
if ($ADODB_mssql_date_order == 'dmy') {
|
||||
if (!preg_match( "|^([0-9]{1,2})[-/\. ]+([A-Za-z]{3})[-/\. ]+([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})|"
|
||||
,$v, $rr)) return parent::UnixTimeStamp($v);
|
||||
if ($rr[3] <= 1970) return 0;
|
||||
|
||||
$theday = $rr[1];
|
||||
$themth = substr(strtoupper($rr[2]),0,3);
|
||||
} else {
|
||||
if (!preg_match( "|^([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})|"
|
||||
,$v, $rr)) return parent::UnixTimeStamp($v);
|
||||
if ($rr[3] <= 1970) return 0;
|
||||
|
||||
$theday = $rr[2];
|
||||
$themth = substr(strtoupper($rr[1]),0,3);
|
||||
}
|
||||
|
||||
$themth = $ADODB_mssql_mths[$themth];
|
||||
if ($themth <= 0) return false;
|
||||
|
||||
switch (strtoupper($rr[6])) {
|
||||
case 'P':
|
||||
if ($rr[4]<12) $rr[4] += 12;
|
||||
break;
|
||||
case 'A':
|
||||
if ($rr[4]==12) $rr[4] = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// h-m-s-MM-DD-YY
|
||||
return mktime($rr[4],$rr[5],0,$themth,$theday,$rr[3]);
|
||||
}
|
||||
}
|
||||
?>
|
436
lib/adodb/drivers/adodb-mysql.inc.php
Normal file
436
lib/adodb/drivers/adodb-mysql.inc.php
Normal file
@ -0,0 +1,436 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 8.
|
||||
|
||||
MySQL code that does not support transactions. Use mysqlt if you need transactions.
|
||||
Requires mysql client. Works on Windows and Unix.
|
||||
|
||||
28 Feb 2001: MetaColumns bug fix - suggested by Freek Dijkstra (phpeverywhere@macfreek.com)
|
||||
*/
|
||||
|
||||
if (! defined("_ADODB_MYSQL_LAYER")) {
|
||||
define("_ADODB_MYSQL_LAYER", 1 );
|
||||
|
||||
class ADODB_mysql extends ADOConnection {
|
||||
var $databaseType = 'mysql';
|
||||
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()';
|
||||
|
||||
function ADODB_mysql()
|
||||
{
|
||||
}
|
||||
|
||||
function _insertid()
|
||||
{
|
||||
return mysql_insert_id($this->_connectionID);
|
||||
}
|
||||
|
||||
function _affectedrows()
|
||||
{
|
||||
return mysql_affected_rows($this->_connectionID);
|
||||
}
|
||||
|
||||
// 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)";
|
||||
|
||||
function GenID($seqname='adodbseq',$startID=1)
|
||||
{
|
||||
//if (!$this->hasGenID) return false;
|
||||
$getnext = sprintf($this->_genIDSQL,$seqname);
|
||||
$rs = @$this->Execute($getnext);
|
||||
if (!$rs) {
|
||||
$u = strtoupper($seqname);
|
||||
$this->Execute(sprintf($this->_genSeqSQL,$seqname));
|
||||
$this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
|
||||
$rs = $this->Execute($getnext);
|
||||
}
|
||||
$this->genID = mysql_insert_id($this->_connectionID);
|
||||
|
||||
if ($rs) $rs->Close();
|
||||
|
||||
return $this->genID;
|
||||
}
|
||||
|
||||
function &MetaDatabases()
|
||||
{
|
||||
$qid = mysql_list_dbs($this->_connectionID);
|
||||
$arr = array();
|
||||
$i = 0;
|
||||
$max = mysql_num_rows($qid);
|
||||
while ($i < $max) {
|
||||
$arr[] = mysql_tablename($qid,$i);
|
||||
$i += 1;
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
// returns concatenated string
|
||||
function Concat()
|
||||
{
|
||||
$s = "";
|
||||
$arr = func_get_args();
|
||||
$first = true;
|
||||
/*
|
||||
foreach($arr as $a) {
|
||||
if ($first) {
|
||||
$s = $a;
|
||||
$first = false;
|
||||
} else $s .= ','.$a;
|
||||
}*/
|
||||
|
||||
// suggestion by andrew005@mnogo.ru
|
||||
$s = implode(',',$arr);
|
||||
if (strlen($s) > 0) return "CONCAT($s)";
|
||||
else return '';
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
|
||||
{
|
||||
$this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword);
|
||||
if ($this->_connectionID === false) return false;
|
||||
if ($argDatabasename) return $this->SelectDB($argDatabasename);
|
||||
return true;
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
|
||||
{
|
||||
$this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword);
|
||||
if ($this->_connectionID === false) return false;
|
||||
if ($argDatabasename) return $this->SelectDB($argDatabasename);
|
||||
return true;
|
||||
}
|
||||
|
||||
function &MetaColumns($table)
|
||||
{
|
||||
|
||||
if ($this->metaColumnsSQL) {
|
||||
global $ADODB_FETCH_MODE;
|
||||
|
||||
$save = $ADODB_FETCH_MODE;
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
||||
|
||||
$rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
|
||||
|
||||
$ADODB_FETCH_MODE = $save;
|
||||
|
||||
if ($rs === false) return false;
|
||||
|
||||
$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];
|
||||
if ($d != "" && $d != "NULL") {
|
||||
$fld->has_default = true;
|
||||
$fld->default_value = $d;
|
||||
} else {
|
||||
$fld->has_default = false;
|
||||
}
|
||||
}
|
||||
|
||||
$retarr[strtoupper($fld->name)] = $fld;
|
||||
$rs->MoveNext();
|
||||
}
|
||||
$rs->Close();
|
||||
return $retarr;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
function SelectDB($dbName)
|
||||
{
|
||||
$this->databaseName = $dbName;
|
||||
if ($this->_connectionID) {
|
||||
return @mysql_select_db($dbName,$this->_connectionID);
|
||||
}
|
||||
else 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," : '';
|
||||
|
||||
return ($secs) ? $this->CacheExecute($secs,$sql." LIMIT $offsetStr$nrows",$inputarr,$arg3)
|
||||
: $this->Execute($sql." LIMIT $offsetStr$nrows",$inputarr,$arg3);
|
||||
|
||||
}
|
||||
|
||||
// returns queryID or false
|
||||
function _query($sql,$inputarr)
|
||||
{
|
||||
global $ADODB_COUNTRECS;
|
||||
if($ADODB_COUNTRECS) return mysql_query($sql,$this->_connectionID);
|
||||
else return mysql_unbuffered_query($sql,$this->_connectionID); // requires PHP >= 4.0.6
|
||||
}
|
||||
|
||||
/* Returns: the last error message from previous database operation */
|
||||
function ErrorMsg()
|
||||
{
|
||||
if (empty($this->_connectionID)) $this->_errorMsg = @mysql_error();
|
||||
else $this->_errorMsg = @mysql_error($this->_connectionID);
|
||||
return $this->_errorMsg;
|
||||
}
|
||||
|
||||
/* Returns: the last error number from previous database operation */
|
||||
function ErrorNo()
|
||||
{
|
||||
if (empty($this->_connectionID)) return @mysql_errno();
|
||||
else return @mysql_errno($this->_connectionID);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// returns true or false
|
||||
function _close()
|
||||
{
|
||||
@mysql_close($this->_connectionID);
|
||||
$this->_connectionID = false;
|
||||
}
|
||||
|
||||
function ActualType($meta)
|
||||
{
|
||||
switch($meta) {
|
||||
case 'C': return 'VARCHAR';
|
||||
case 'X': return 'LONGTEXT';
|
||||
|
||||
case 'C2': return 'VARCHAR';
|
||||
case 'X2': return 'LONGTEXT';
|
||||
|
||||
case 'B': return 'LONGBLOB';
|
||||
|
||||
case 'D': return 'DATE';
|
||||
case 'T': return 'DATETIME';
|
||||
case 'L': return 'TINYINT';
|
||||
case 'R': return 'INTEGER NOT NULL AUTO_INCREMENT';
|
||||
case 'I': return 'INTEGER'; // enough for 9 petabytes!
|
||||
|
||||
case 'F': return 'DOUBLE';
|
||||
case 'N': return 'NUMERIC';
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Maximum size of C field
|
||||
*/
|
||||
function CharMax()
|
||||
{
|
||||
return 255;
|
||||
}
|
||||
|
||||
/*
|
||||
* Maximum size of X field
|
||||
*/
|
||||
function TextMax()
|
||||
{
|
||||
return 4294967295;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------------------
|
||||
Class Name: Recordset
|
||||
--------------------------------------------------------------------------------------*/
|
||||
|
||||
class ADORecordSet_mysql extends ADORecordSet{
|
||||
|
||||
var $databaseType = "mysql";
|
||||
var $canSeek = true;
|
||||
|
||||
function ADORecordSet_mysql($queryID) {
|
||||
GLOBAL $ADODB_FETCH_MODE;
|
||||
|
||||
switch ($ADODB_FETCH_MODE)
|
||||
{
|
||||
case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break;
|
||||
case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break;
|
||||
default:
|
||||
case ADODB_FETCH_DEFAULT:
|
||||
case ADODB_FETCH_BOTH:$this->fetchMode = MYSQL_BOTH; break;
|
||||
}
|
||||
|
||||
$this->ADORecordSet($queryID);
|
||||
}
|
||||
|
||||
function _initrs()
|
||||
{
|
||||
GLOBAL $ADODB_COUNTRECS;
|
||||
$this->_numOfRows = ($ADODB_COUNTRECS) ? @mysql_num_rows($this->_queryID):-1;
|
||||
$this->_numOfFields = @mysql_num_fields($this->_queryID);
|
||||
}
|
||||
|
||||
function &FetchField($fieldOffset = -1) {
|
||||
if ($fieldOffset != -1) {
|
||||
$o = @mysql_fetch_field($this->_queryID, $fieldOffset);
|
||||
$f = @mysql_field_flags($this->_queryID,$fieldOffset);
|
||||
$o->max_length = @mysql_field_len($this->_queryID,$fieldOffset); // suggested by: Jim Nicholson (jnich@att.com)
|
||||
//$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
|
||||
$o->binary = (strpos($f,'binary')!== false);
|
||||
}
|
||||
else if ($fieldOffset == -1) { /* The $fieldOffset argument is not provided thus its -1 */
|
||||
$o = @mysql_fetch_field($this->_queryID);
|
||||
$o->max_length = @mysql_field_len($this->_queryID); // suggested by: Jim Nicholson (jnich@att.com)
|
||||
//$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
|
||||
}
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
function &GetRowAssoc($upper=true)
|
||||
{
|
||||
if ($this->fetchMode == MYSQL_ASSOC && !$upper) return $rs->fields;
|
||||
return ADORecordSet::GetRowAssoc($upper);
|
||||
}
|
||||
|
||||
/* Use associative array to get fields array */
|
||||
function Fields($colname)
|
||||
{
|
||||
// added @ by "Michael William Miller" <mille562@pilot.msu.edu>
|
||||
if ($this->fetchMode != MYSQL_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)
|
||||
{
|
||||
return @mysql_data_seek($this->_queryID,$row);
|
||||
}
|
||||
|
||||
/*function &FetchRow()
|
||||
{
|
||||
if ($this->EOF) return false;
|
||||
|
||||
$arr = $this->fields;
|
||||
$this->_currentRow++;
|
||||
// using & below slows things down by 20%!
|
||||
$this->fields = @mysql_fetch_array($this->_queryID,$this->fetchMode);
|
||||
|
||||
if (is_array($this->fields)) return $arr;
|
||||
$this->EOF = true;
|
||||
return false;
|
||||
} */
|
||||
|
||||
// 10% speedup to move MoveNext to child class
|
||||
function MoveNext()
|
||||
{
|
||||
if (!$this->EOF) {
|
||||
$this->_currentRow++;
|
||||
// using & below slows things down by 20%!
|
||||
$this->fields = @mysql_fetch_array($this->_queryID,$this->fetchMode);
|
||||
|
||||
if (is_array($this->fields)) return true;
|
||||
$this->EOF = true;
|
||||
}
|
||||
/* -- tested raising an error -- appears pointless
|
||||
$conn = $this->connection;
|
||||
if ($conn && $conn->raiseErrorFn && ($errno = $conn->ErrorNo())) {
|
||||
$fn = $conn->raiseErrorFn;
|
||||
$fn($conn->databaseType,'MOVENEXT',$errno,$conn->ErrorMsg().' ('.$this->sql.')',$conn->host,$conn->database);
|
||||
}
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
function _fetch()
|
||||
{
|
||||
$this->fields = @mysql_fetch_array($this->_queryID,$this->fetchMode);
|
||||
return (is_array($this->fields));
|
||||
}
|
||||
|
||||
function _close() {
|
||||
@mysql_free_result($this->_queryID);
|
||||
$this->_queryID = false;
|
||||
}
|
||||
|
||||
function MetaType($t,$len=-1,$fieldobj=false)
|
||||
{
|
||||
$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 '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';
|
||||
|
||||
default: return 'N';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
54
lib/adodb/drivers/adodb-mysqlt.inc.php
Normal file
54
lib/adodb/drivers/adodb-mysqlt.inc.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 8.
|
||||
|
||||
MySQL code that supports transactions. For MySQL 3.23 or later.
|
||||
Code from James Poon <jpoon88@yahoo.com>
|
||||
|
||||
Requires mysql client. Works on Windows and Unix.
|
||||
*/
|
||||
|
||||
|
||||
include_once(ADODB_DIR."/drivers/adodb-mysql.inc.php");
|
||||
|
||||
|
||||
class ADODB_mysqlt extends ADODB_mysql {
|
||||
var $databaseType = 'mysqlt';
|
||||
|
||||
function BeginTrans()
|
||||
{
|
||||
$this->Execute('SET AUTOCOMMIT=0');
|
||||
$this->Execute('BEGIN');
|
||||
return true;
|
||||
}
|
||||
|
||||
function CommitTrans($ok=true)
|
||||
{
|
||||
if (!$ok) return $this->RollbackTrans();
|
||||
$this->Execute('COMMIT');
|
||||
$this->Execute('SET AUTOCOMMIT=1');
|
||||
return true;
|
||||
}
|
||||
|
||||
function RollbackTrans()
|
||||
{
|
||||
$this->Execute('ROLLBACK');
|
||||
$this->Execute('SET AUTOCOMMIT=1');
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ADORecordSet_mysqlt extends ADORecordSet_mysql{
|
||||
var $databaseType = "mysqlt";
|
||||
|
||||
function ADORecordSet_mysqlt($queryID) {
|
||||
return $this->ADORecordSet_mysql($queryID);
|
||||
}
|
||||
}
|
||||
?>
|
818
lib/adodb/drivers/adodb-oci8.inc.php
Normal file
818
lib/adodb/drivers/adodb-oci8.inc.php
Normal file
@ -0,0 +1,818 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 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.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
|
||||
Code contributed by George Fourlanos <fou@infomap.gr>
|
||||
|
||||
13 Nov 2000 jlim - removed all ora_* references.
|
||||
*/
|
||||
|
||||
/*
|
||||
NLS_Date_Format
|
||||
Allows you to use a date format other than the Oracle Lite default. When a literal
|
||||
character string appears where a date value is expected, the Oracle Lite database
|
||||
tests the string to see if it matches the formats of Oracle, SQL-92, or the value
|
||||
specified for this parameter in the POLITE.INI file. Setting this parameter also
|
||||
defines the default format used in the TO_CHAR or TO_DATE functions when no
|
||||
other format string is supplied.
|
||||
|
||||
For Oracle the default is dd-mon-yy or dd-mon-yyyy, and for SQL-92 the default is
|
||||
yy-mm-dd or yyyy-mm-dd.
|
||||
|
||||
Using 'RR' in the format forces two-digit years less than or equal to 49 to be
|
||||
interpreted as years in the 21st century (2000–2049), and years over 50 as years in
|
||||
the 20th century (1950–1999). Setting the RR format as the default for all two-digit
|
||||
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';
|
||||
var $replaceQuote = "''"; // string to use to replace quotes
|
||||
var $concat_operator='||';
|
||||
var $sysDate = "TO_DATE(TO_CHAR(SYSDATE,'YYYY-MM-DD'),'YYYY-MM-DD')";
|
||||
var $sysTimeStamp = 'SYSDATE';
|
||||
|
||||
var $_stmt;
|
||||
var $_commit = OCI_COMMIT_ON_SUCCESS;
|
||||
var $_initdate = true; // init date to YYYY-MM-DD
|
||||
var $metaTablesSQL = "select table_name from cat where table_type in ('TABLE','VIEW')";
|
||||
var $metaColumnsSQL = "select cname,coltype,width from col where tname='%s' order by colno";
|
||||
var $_bindInputArray = true;
|
||||
var $hasGenID = true;
|
||||
var $_genIDSQL = "SELECT %s.nextval FROM DUAL";
|
||||
var $_genSeqSQL = "CREATE SEQUENCE %s START WITH %s";
|
||||
var $hasAffectedRows = true;
|
||||
var $upperCase = 'upper';
|
||||
var $noNullStrings = false;
|
||||
var $connectSID = false;
|
||||
var $_bind = false;
|
||||
var $_hasOCIFetchStatement = false;
|
||||
var $_getarray = false; // currently not working
|
||||
|
||||
function ADODB_oci8()
|
||||
{
|
||||
$this->_hasOCIFetchStatement = (strnatcmp(PHP_VERSION,'4.2.0')>=0);;
|
||||
}
|
||||
|
||||
function Affected_Rows()
|
||||
{
|
||||
return OCIRowCount($this->_stmt);
|
||||
}
|
||||
|
||||
// format and return date string in database date format
|
||||
function DBDate($d)
|
||||
{
|
||||
if (empty($d) && $d !== 0) return 'null';
|
||||
|
||||
if (is_string($d)) $d = ADORecordSet::UnixDate($d);
|
||||
return 'TO_DATE('.date($this->fmtDate,$d).",'YYYY-MM-DD')";
|
||||
}
|
||||
|
||||
// format and return date string in database timestamp format
|
||||
function DBTimeStamp($ts)
|
||||
{
|
||||
if (empty($ts) && $ts !== 0) return 'null';
|
||||
if (is_string($ts)) $ts = ADORecordSet::UnixTimeStamp($ts);
|
||||
return 'TO_DATE('.date($this->fmtTimeStamp,$ts).",'RRRR-MM-DD, HH:MI:SS AM')";
|
||||
}
|
||||
|
||||
function RowLock($tables,$where)
|
||||
{
|
||||
if ($this->autoCommit) $this->BeginTrans();
|
||||
return $this->GetOne("select 1 as ignore from $tables where $where for update");
|
||||
}
|
||||
|
||||
function BeginTrans()
|
||||
{
|
||||
$this->autoCommit = false;
|
||||
$this->_commit = OCI_DEFAULT;
|
||||
return true;
|
||||
}
|
||||
|
||||
function CommitTrans($ok=true)
|
||||
{
|
||||
if (!$ok) return $this->RollbackTrans();
|
||||
$ret = OCIcommit($this->_connectionID);
|
||||
$this->_commit = OCI_COMMIT_ON_SUCCESS;
|
||||
$this->autoCommit = true;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function RollbackTrans()
|
||||
{
|
||||
$ret = OCIrollback($this->_connectionID);
|
||||
$this->_commit = OCI_COMMIT_ON_SUCCESS;
|
||||
$this->autoCommit = true;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
function SelectDB($dbName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/* there seems to be a bug in the oracle extension -- always returns ORA-00000 - no error */
|
||||
function ErrorMsg()
|
||||
{
|
||||
$arr = @OCIerror($this->_stmt);
|
||||
if ($arr === false) {
|
||||
$arr = @OCIerror($this->_connectionID);
|
||||
if ($arr === false) $arr = @OCIError();
|
||||
if ($arr === false) return '';
|
||||
}
|
||||
$this->_errorMsg = $arr['message'];
|
||||
return $this->_errorMsg;
|
||||
}
|
||||
|
||||
function ErrorNo()
|
||||
{
|
||||
if (is_resource($this->_stmt))
|
||||
$arr = @ocierror($this->_stmt);
|
||||
else {
|
||||
$arr = @ocierror($this->_connectionID);
|
||||
if ($arr === false) $arr = @ocierror();
|
||||
if ($arr == false) return '';
|
||||
}
|
||||
return $arr['code'];
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Example TNSName:
|
||||
---------------
|
||||
NATSOFT.DOMAIN =
|
||||
(DESCRIPTION =
|
||||
(ADDRESS_LIST =
|
||||
(ADDRESS = (PROTOCOL = TCP)(HOST = kermit)(PORT = 1523))
|
||||
)
|
||||
(CONNECT_DATA =
|
||||
(SERVICE_NAME = natsoft.domain)
|
||||
)
|
||||
)
|
||||
*/
|
||||
// returns true or false
|
||||
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename,$persist=false)
|
||||
{
|
||||
|
||||
if($argHostname) { // added by Jorma Tuomainen <jorma.tuomainen@ppoy.fi>
|
||||
if(strpos($argHostname,":")) {
|
||||
$argHostinfo=explode(":",$argHostname);
|
||||
$argHostname=$argHostinfo[0];
|
||||
$argHostport=$argHostinfo[1];
|
||||
} else {
|
||||
$argHostport="1521";
|
||||
}
|
||||
|
||||
if ($this->connectSID) {
|
||||
$argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname
|
||||
.")(PORT=$argHostport))(CONNECT_DATA=(SID=$argDatabasename)))";
|
||||
} else
|
||||
$argDatabasename="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=".$argHostname
|
||||
.")(PORT=$argHostport))(CONNECT_DATA=(SERVICE_NAME=$argDatabasename)))";
|
||||
}
|
||||
|
||||
//if ($argHostname) print "<p>Connect: 1st argument should be left blank for $this->databaseType</p>";
|
||||
if ($persist)$this->_connectionID = OCIPLogon($argUsername,$argPassword, $argDatabasename);
|
||||
else $this->_connectionID = OCILogon($argUsername,$argPassword, $argDatabasename);
|
||||
|
||||
if ($this->_connectionID === false) return false;
|
||||
if ($this->_initdate) {
|
||||
$this->Execute("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD'");
|
||||
}
|
||||
|
||||
//print OCIServerVersion($this->_connectionID);
|
||||
return true;
|
||||
}
|
||||
// returns true or false
|
||||
function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
|
||||
{
|
||||
return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename,true);
|
||||
}
|
||||
|
||||
/*
|
||||
This algorithm makes use of
|
||||
|
||||
a. FIRST_ROWS hint
|
||||
The FIRST_ROWS hint explicitly chooses the approach to optimize response time,
|
||||
that is, minimum resource usage to return the first row. Results will be returned
|
||||
as soon as they are identified.
|
||||
|
||||
b. Uses rownum tricks to obtain only the required rows from a given offset.
|
||||
As this uses complicated sql statements, we only use this if the $offset >= 100.
|
||||
This idea by Tomas V V Cox.
|
||||
|
||||
This implementation does not appear to work with oracle 8.0.5 or earlier. Comment
|
||||
out this function then, and the slower SelectLimit() in the base class will be used.
|
||||
*/
|
||||
function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$arg3=false,$secs2cache=0)
|
||||
{
|
||||
// seems that oracle only supports 1 hint comment in 8i
|
||||
if (strpos($sql,'/*+') !== false)
|
||||
$sql = str_replace('/*+ ','/*+FIRST_ROWS ',$sql);
|
||||
else
|
||||
$sql = preg_replace('/^[ \t\n]*select/i','SELECT /*+FIRST_ROWS*/',$sql);
|
||||
|
||||
if ($offset < 100) {
|
||||
if ($nrows > 0) {
|
||||
if ($offset > 0) $nrows += $offset;
|
||||
//$inputarr['adodb_rownum'] = $nrows;
|
||||
$sql = "select * from ($sql) where rownum <= $nrows";
|
||||
$nrows = -1;
|
||||
}
|
||||
// note that $nrows = 0 still has to work ==> no rows returned
|
||||
|
||||
return ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$arg3,$secs2cache);
|
||||
} else {
|
||||
// Algorithm by Tomas V V Cox, from PEAR DB oci8.php
|
||||
|
||||
// Let Oracle return the name of the columns
|
||||
$q_fields = "SELECT * FROM ($sql) WHERE NULL = NULL";
|
||||
if (!$result = OCIParse($this->_connectionID, $q_fields)) {
|
||||
return false;
|
||||
}
|
||||
if (!$success = OCIExecute($result, OCI_DEFAULT)) {
|
||||
return false;
|
||||
}
|
||||
$ncols = OCINumCols($result);
|
||||
for ( $i = 1; $i <= $ncols; $i++ ) {
|
||||
$cols[] = OCIColumnName($result, $i);
|
||||
}
|
||||
$result = false;
|
||||
|
||||
$fields = implode(',', $cols);
|
||||
$nrows += $offset;
|
||||
$offset += 1; // in Oracle rownum starts at 1
|
||||
|
||||
$sql = "SELECT $fields FROM".
|
||||
"(SELECT rownum as adodb_rownum, $fields FROM".
|
||||
" ($sql) WHERE rownum <= $nrows".
|
||||
") WHERE adodb_rownum >= $offset";
|
||||
|
||||
if ($secs2cache>0) return $this->CacheExecute($secs2cache, $sql,$inputarr,$arg3);
|
||||
else return $this->Execute($sql,$inputarr,$arg3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Usage:
|
||||
* Store BLOBs and CLOBs
|
||||
*
|
||||
* Example: to store $var in a blob
|
||||
*
|
||||
* $conn->Execute('insert into TABLE (id,ablob) values(12,empty_blob())');
|
||||
* $conn->UpdateBlob('TABLE', 'ablob', $varHoldingBlob, 'ID=12', 'BLOB');
|
||||
*
|
||||
* $blobtype supports 'BLOB' and 'CLOB', but you need to change to 'empty_clob()'.
|
||||
*
|
||||
* to get length of LOB:
|
||||
* select DBMS_LOB.GETLENGTH(ablob) from TABLE
|
||||
*
|
||||
* If you are using CURSOR_SHARING = force, it appears this will case a segfault
|
||||
* under oracle 8.1.7.0. Run:
|
||||
* $db->Execute('ALTER SESSION SET CURSOR_SHARING=EXACT');
|
||||
* before UpdateBlob() then...
|
||||
*/
|
||||
|
||||
function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB',$commit=true)
|
||||
{
|
||||
switch(strtoupper($blobtype)) {
|
||||
default: print "<b>UpdateBlob</b>: Unknown blobtype=$blobtype<br>"; return false;
|
||||
case 'BLOB': $type = OCI_B_BLOB; break;
|
||||
case 'CLOB': $type = OCI_B_CLOB; break;
|
||||
}
|
||||
|
||||
if ($this->databaseType == 'oci8po')
|
||||
$sql = "UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO ?";
|
||||
else
|
||||
$sql = "UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO :blob";
|
||||
|
||||
$desc = OCINewDescriptor($this->_connectionID, OCI_D_LOB);
|
||||
$arr['blob'] = array($desc,-1,$type);
|
||||
|
||||
if ($commit) $this->BeginTrans();
|
||||
$rs = ADODB_oci8::Execute($sql,$arr);
|
||||
if ($rez = !empty($rs)) $desc->save($val);
|
||||
$desc->free();
|
||||
if ($commit) $this->CommitTrans();
|
||||
|
||||
if ($rez) $rs->Close();
|
||||
return $rez;
|
||||
}
|
||||
|
||||
/**
|
||||
* Usage: store file pointed to by $var in a blob
|
||||
*/
|
||||
function UpdateBlobFile($table,$column,$val,$where,$blobtype='BLOB')
|
||||
{
|
||||
switch(strtoupper($blobtype)) {
|
||||
default: print "<b>UpdateBlob</b>: Unknown blobtype=$blobtype<br>"; return false;
|
||||
case 'BLOB': $type = OCI_B_BLOB; break;
|
||||
case 'CLOB': $type = OCI_B_CLOB; break;
|
||||
}
|
||||
|
||||
if ($this->databaseType == 'oci8po')
|
||||
$sql = "UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO ?";
|
||||
else
|
||||
$sql = "UPDATE $table set $column=EMPTY_{$blobtype}() WHERE $where RETURNING $column INTO :blob";
|
||||
|
||||
$desc = OCINewDescriptor($this->_connectionID, OCI_D_LOB);
|
||||
$arr['blob'] = array($desc,-1,$type);
|
||||
|
||||
$this->BeginTrans();
|
||||
$rs = ADODB_oci8::Execute($sql,$arr);
|
||||
if ($rez = !empty($rs)) $desc->savefile($val);
|
||||
$desc->free();
|
||||
$this->CommitTrans();
|
||||
|
||||
if ($rez) $rs->Close();
|
||||
return $rez;
|
||||
}
|
||||
|
||||
/*
|
||||
Example of usage:
|
||||
|
||||
$stmt = $this->Prepare('insert into emp (empno, ename) values (:empno, :ename)');
|
||||
*/
|
||||
function Prepare($sql)
|
||||
{
|
||||
static $BINDNUM = 0;
|
||||
|
||||
$stmt = OCIParse($this->_connectionID,$sql);
|
||||
if (!$stmt) return $sql; // error in statement, let Execute() handle the error
|
||||
|
||||
$BINDNUM += 1;
|
||||
return array($sql,$stmt,0,$BINDNUM);
|
||||
}
|
||||
|
||||
/*
|
||||
Bind a variable -- very, very fast for executing repeated statements in oracle.
|
||||
Better than using
|
||||
for ($i = 0; $i < $max; $i++) {
|
||||
$p1 = ?; $p2 = ?; $p3 = ?;
|
||||
$this->Execute("insert into table (col0, col1, col2) values (:0, :1, :2)",
|
||||
array($p1,$p2,$p3));
|
||||
}
|
||||
|
||||
Usage:
|
||||
$stmt = $DB->Prepare("insert into table (col0, col1, col2) values (:0, :1, :2)");
|
||||
$DB->Bind($stmt, $p1);
|
||||
$DB->Bind($stmt, $p2);
|
||||
$DB->Bind($stmt, $p3);
|
||||
for ($i = 0; $i < $max; $i++) {
|
||||
$p1 = ?; $p2 = ?; $p3 = ?;
|
||||
$DB->Execute($stmt);
|
||||
}
|
||||
|
||||
Some timings:
|
||||
** Test table has 3 cols, and 1 index. Test to insert 1000 records
|
||||
Time 0.6081s (1644.60 inserts/sec) with direct OCIParse/OCIExecute
|
||||
Time 0.6341s (1577.16 inserts/sec) with ADOdb Prepare/Bind/Execute
|
||||
Time 1.5533s ( 643.77 inserts/sec) with pure SQL using Execute
|
||||
|
||||
Now if PHP only had batch/bulk updating like Java or PL/SQL...
|
||||
|
||||
Note that the order of parameters differs from OCIBindByName,
|
||||
because we default the names to :0, :1, :2
|
||||
*/
|
||||
function Bind(&$stmt,&$var,$size=4000,$type=false,$name=false)
|
||||
{
|
||||
if (!is_array($stmt)) return false;
|
||||
if ($name == false) {
|
||||
if ($type !== false) $rez = OCIBindByName($stmt[1],":".$name,$var,$size,$type);
|
||||
else $rez = OCIBindByName($stmt[1],":".$stmt[2],$var,$size); // +1 byte for null terminator
|
||||
$stmt[2] += 1;
|
||||
} else {
|
||||
if ($type !== false) $rez = OCIBindByName($stmt[1],":".$name,$var,$size,$type);
|
||||
else $rez = OCIBindByName($stmt[1],":".$name,$var,$size); // +1 byte for null terminator
|
||||
}
|
||||
|
||||
return $rez;
|
||||
}
|
||||
|
||||
/*
|
||||
Usage:
|
||||
$stmt = $db->Prepare('select * from table where id =:myid and group=:group');
|
||||
$db->Parameter($stmt,$id,'myid');
|
||||
$db->Parameter($stmt,$group,'group');
|
||||
$db->Execute($stmt);
|
||||
|
||||
@param $stmt Statement returned by Prepare() or PrepareSP().
|
||||
@param $var PHP variable to bind to
|
||||
@param $name Name of stored procedure variable name to bind to.
|
||||
@param [$isOutput] Indicates direction of parameter 0/false=IN 1=OUT 2= IN/OUT. This is ignored in oci8.
|
||||
@param [$maxLen] Holds an maximum length of the variable.
|
||||
@param [$type] The data type of $var. Legal values depend on driver.
|
||||
|
||||
See OCIBindByName documentation at php.net.
|
||||
*/
|
||||
function Parameter(&$stmt,&$var,$name,$isOutput=false,$maxLen=4000,$type=false)
|
||||
{
|
||||
if ($this->debug) {
|
||||
print "Parameter(\$stmt, \$php_var='$var', \$name='$name');<br>\n";
|
||||
}
|
||||
return $this->Bind($stmt,$var,$maxLen,$type,$name);
|
||||
}
|
||||
|
||||
/*
|
||||
returns query ID if successful, otherwise false
|
||||
this version supports:
|
||||
|
||||
1. $db->execute('select * from table');
|
||||
|
||||
2. $db->prepare('insert into table (a,b,c) values (:0,:1,:2)');
|
||||
$db->execute($prepared_statement, array(1,2,3));
|
||||
|
||||
3. $db->execute('insert into table (a,b,c) values (:a,:b,:c)',array('a'=>1,'b'=>2,'c'=>3));
|
||||
|
||||
4. $db->prepare('insert into table (a,b,c) values (:0,:1,:2)');
|
||||
$db->$bind($stmt,1); $db->bind($stmt,2); $db->bind($stmt,3);
|
||||
$db->execute($stmt);
|
||||
*/
|
||||
function _query($sql,$inputarr)
|
||||
{
|
||||
if (is_array($sql)) { // is prepared sql
|
||||
$stmt = $sql[1];
|
||||
|
||||
// we try to bind to permanent array, so that OCIBindByName is persistent
|
||||
// and carried out once only - note that max array element size is 4000 chars
|
||||
if (is_array($inputarr)) {
|
||||
$bindpos = $sql[3];
|
||||
if (isset($this->_bind[$bindpos])) {
|
||||
// all tied up already
|
||||
$bindarr = &$this->_bind[$bindpos];
|
||||
} else {
|
||||
// one statement to bind them all
|
||||
$bindarr = array();
|
||||
foreach($inputarr as $k => $v) {
|
||||
$bindarr[$k] = $v;
|
||||
OCIBindByName($stmt,":$k",$bindarr[$k],4000);
|
||||
}
|
||||
$this->_bind[$bindpos] = &$bindarr;
|
||||
}
|
||||
}
|
||||
} else
|
||||
$stmt=@OCIParse($this->_connectionID,$sql);
|
||||
|
||||
$this->_stmt = $stmt;
|
||||
if (!$stmt) return false;
|
||||
|
||||
if (defined('ADODB_PREFETCH_ROWS')) @OCISetPrefetch($stmt,ADODB_PREFETCH_ROWS);
|
||||
|
||||
if (is_array($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]);
|
||||
else
|
||||
OCIBindByName($stmt,":$k",$inputarr[$k][0],$v[1],$v[2]);
|
||||
} else {
|
||||
$len = -1;
|
||||
if ($v === ' ') $len = 1;
|
||||
if (isset($bindarr)) { // is prepared sql, so no need to ocibindbyname again
|
||||
$bindarr[$k] = $v;
|
||||
} else { // dynamic sql, so rebind every time
|
||||
OCIBindByName($stmt,":$k",$inputarr[$k],$len);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (OCIExecute($stmt,$this->_commit)) {
|
||||
/* Now this could be an Update/Insert or Delete */
|
||||
if (@OCIStatementType($stmt) != 'SELECT') return true;
|
||||
return $stmt;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
function _close()
|
||||
{
|
||||
if (!$this->autoCommit) OCIRollback($this->_connectionID);
|
||||
OCILogoff($this->_connectionID);
|
||||
$this->_stmt = false;
|
||||
$this->_connectionID = false;
|
||||
}
|
||||
|
||||
function MetaPrimaryKeys($table)
|
||||
{
|
||||
// tested with oracle 8.1.7
|
||||
$table = strtoupper($table);
|
||||
$sql = "SELECT /*+ RULE */ distinct b.column_name
|
||||
FROM ALL_CONSTRAINTS a
|
||||
, ALL_CONS_COLUMNS b
|
||||
WHERE ( UPPER(b.table_name) = ('$table'))
|
||||
AND (UPPER(a.table_name) = ('$table') and a.constraint_type = 'P')
|
||||
AND (a.constraint_name = b.constraint_name)";
|
||||
$rs = $this->Execute($sql);
|
||||
if ($rs && !$rs->EOF) {
|
||||
$arr = $rs->GetArray();
|
||||
$a = array();
|
||||
foreach($arr as $v) {
|
||||
$a[] = $v[0];
|
||||
}
|
||||
return $a;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
|
||||
function ActualType($meta)
|
||||
{
|
||||
switch($meta) {
|
||||
case 'C': return 'VARCHAR';
|
||||
case 'X': return 'VARCHAR(4000)';
|
||||
|
||||
case 'C2': return 'NVARCHAR';
|
||||
case 'X2': return 'NVARCHAR(4000)';
|
||||
|
||||
case 'B': return 'BLOB';
|
||||
|
||||
case 'D':
|
||||
case 'T': return 'DATE';
|
||||
case 'L': return 'NUMBER(1)';
|
||||
case 'R': return false;
|
||||
case 'I': return 'NUMBER(16)'; // enough for 9 petabytes!
|
||||
|
||||
case 'F': return 'NUMBER';
|
||||
case 'N': return 'NUMBER';
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function CharMax()
|
||||
{
|
||||
return 4000;
|
||||
}
|
||||
|
||||
function TextMax()
|
||||
{
|
||||
return 4000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Quotes a string.
|
||||
* An example is $db->qstr("Don't bother",magic_quotes_runtime());
|
||||
*
|
||||
* @param s the string to quote
|
||||
* @param [magic_quotes] if $s is GET/POST var, set to get_magic_quotes_gpc().
|
||||
* This undoes the stupidity of magic quotes for GPC.
|
||||
*
|
||||
* @return quoted string to be sent back to database
|
||||
*/
|
||||
function qstr($s,$magic_quotes=false)
|
||||
{
|
||||
$nofixquotes=false;
|
||||
|
||||
|
||||
if ($this->noNullStrings && $s === '')$s = ' ';
|
||||
if (!$magic_quotes) {
|
||||
if ($this->replaceQuote[0] == '\\'){
|
||||
$s = str_replace('\\','\\\\',$s);
|
||||
}
|
||||
return "'".str_replace("'",$this->replaceQuote,$s)."'";
|
||||
}
|
||||
|
||||
// undo magic quotes for "
|
||||
$s = str_replace('\\"','"',$s);
|
||||
|
||||
if ($this->replaceQuote == "\\'") // ' already quoted, no need to change anything
|
||||
return "'$s'";
|
||||
else {// change \' to '' for sybase/mssql
|
||||
$s = str_replace('\\\\','\\',$s);
|
||||
return "'".str_replace("\\'",$this->replaceQuote,$s)."'";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------------------
|
||||
Class Name: Recordset
|
||||
--------------------------------------------------------------------------------------*/
|
||||
|
||||
class ADORecordset_oci8 extends ADORecordSet {
|
||||
|
||||
var $databaseType = 'oci8';
|
||||
var $bind=false;
|
||||
var $_fieldobjs;
|
||||
//var $_arr = false;
|
||||
|
||||
function ADORecordset_oci8($queryID)
|
||||
{
|
||||
global $ADODB_FETCH_MODE;
|
||||
|
||||
switch ($ADODB_FETCH_MODE)
|
||||
{
|
||||
default:
|
||||
case ADODB_FETCH_NUM: $this->fetchMode = OCI_NUM+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break;
|
||||
case ADODB_FETCH_ASSOC:$this->fetchMode = OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break;
|
||||
case ADODB_FETCH_DEFAULT:
|
||||
case ADODB_FETCH_BOTH:$this->fetchMode = OCI_NUM+OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS; break;
|
||||
}
|
||||
$this->_queryID = $queryID;
|
||||
}
|
||||
|
||||
|
||||
function Init()
|
||||
{
|
||||
if ($this->_inited) return;
|
||||
|
||||
$this->_inited = true;
|
||||
$this->fields = array();
|
||||
|
||||
if ($this->_queryID) {
|
||||
/*
|
||||
if ($this->connection->_getarray) {
|
||||
if ($this->connection->_hasOCIFetchStatement) {
|
||||
$arr = array();
|
||||
if (OCIFetchStatement($this->_queryID,$arr,0,(integer)-1,OCI_FETCHSTATEMENT_BY_ROW|$this->fetchMode)) {
|
||||
$this->_arr = $arr;
|
||||
}
|
||||
$this->EOF = false;
|
||||
}
|
||||
} else */
|
||||
{
|
||||
$this->EOF = !$this->_fetch();
|
||||
$this->_currentRow = 0;
|
||||
}
|
||||
|
||||
@$this->_initrs();
|
||||
|
||||
} else {
|
||||
$this->_numOfRows = 0;
|
||||
$this->_numOfFields = 0;
|
||||
$this->EOF = true;
|
||||
}
|
||||
}
|
||||
|
||||
function _initrs()
|
||||
{
|
||||
$this->_numOfRows = -1;
|
||||
$this->_numOfFields = OCInumcols($this->_queryID);
|
||||
if ($this->_numOfFields>0) {
|
||||
$this->_fieldobjs = array();
|
||||
$max = $this->_numOfFields;
|
||||
for ($i=0;$i<$max; $i++) $this->_fieldobjs[] = $this->_FetchField($i);
|
||||
}
|
||||
}
|
||||
|
||||
/* Returns: an object containing field information.
|
||||
Get column information in the Recordset object. fetchField() can be used in order to obtain information about
|
||||
fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by
|
||||
fetchField() is retrieved. */
|
||||
|
||||
function &_FetchField($fieldOffset = -1)
|
||||
{
|
||||
$fld = new ADOFieldObject;
|
||||
$fieldOffset += 1;
|
||||
$fld->name =OCIcolumnname($this->_queryID, $fieldOffset);
|
||||
$fld->type = OCIcolumntype($this->_queryID, $fieldOffset);
|
||||
$fld->max_length = OCIcolumnsize($this->_queryID, $fieldOffset);
|
||||
if ($fld->type == 'NUMBER') {
|
||||
//$p = OCIColumnPrecision($this->_queryID, $fieldOffset);
|
||||
$sc = OCIColumnScale($this->_queryID, $fieldOffset);
|
||||
if ($sc == 0) $fld->type = 'INT';
|
||||
}
|
||||
return $fld;
|
||||
}
|
||||
|
||||
/* For some reason, OCIcolumnname fails when called after _initrs() so we cache it */
|
||||
function &FetchField($fieldOffset = -1)
|
||||
{
|
||||
return $this->_fieldobjs[$fieldOffset];
|
||||
}
|
||||
|
||||
/**
|
||||
* return recordset as a 2-dimensional array.
|
||||
*
|
||||
* @param [nRows] is the number of rows to return. -1 means every row.
|
||||
*
|
||||
* @return an array indexed by the rows (0-based) from the recordset
|
||||
*/
|
||||
function GetArray($nRows = -1)
|
||||
{
|
||||
// if ($this->_arr) return $this->_arr;
|
||||
$results = array();
|
||||
$cnt = 0;
|
||||
while (!$this->EOF && $nRows != $cnt) {
|
||||
$results[$cnt++] = $this->fields;
|
||||
$this->MoveNext();
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
// 10% speedup to move MoveNext to child class
|
||||
function MoveNext()
|
||||
{
|
||||
if (!$this->EOF) {
|
||||
$this->_currentRow++;
|
||||
if(@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode))
|
||||
return true;
|
||||
|
||||
$this->EOF = true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Optimize SelectLimit() by using OCIFetch() instead of OCIFetchInto() */
|
||||
function GetArrayLimit($nrows,$offset=-1)
|
||||
{
|
||||
if ($offset <= 0) return $this->GetArray($nrows);
|
||||
for ($i=1; $i < $offset; $i++)
|
||||
if (!@OCIFetch($this->_queryID)) return array();
|
||||
|
||||
if (!@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) return array();
|
||||
$results = array();
|
||||
$cnt = 0;
|
||||
while (!$this->EOF && $nrows != $cnt) {
|
||||
$results[$cnt++] = $this->fields;
|
||||
$this->MoveNext();
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
|
||||
/* Use associative array to get fields array */
|
||||
function 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)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
function _fetch()
|
||||
{
|
||||
return @OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode);
|
||||
}
|
||||
|
||||
/* close() only needs to be called if you are worried about using too much memory while your script
|
||||
is running. All associated result memory for the specified result identifier will automatically be freed. */
|
||||
|
||||
function _close()
|
||||
{
|
||||
OCIFreeStatement($this->_queryID);
|
||||
$this->_queryID = false;
|
||||
}
|
||||
|
||||
function MetaType($t,$len=-1)
|
||||
{
|
||||
switch (strtoupper($t)) {
|
||||
case 'VARCHAR':
|
||||
case 'VARCHAR2':
|
||||
case 'CHAR':
|
||||
case 'VARBINARY':
|
||||
case 'BINARY':
|
||||
case 'NCHAR':
|
||||
case 'NVARCHAR':
|
||||
if ($len <= $this->blobSize) return 'C';
|
||||
|
||||
case 'NCLOB':
|
||||
case 'LONG':
|
||||
case 'LONG VARCHAR':
|
||||
case 'CLOB';
|
||||
return 'X';
|
||||
|
||||
case 'LONG RAW':
|
||||
case 'LONG VARBINARY':
|
||||
case 'BLOB':
|
||||
return 'B';
|
||||
|
||||
case 'DATE':
|
||||
return 'D';
|
||||
|
||||
//case 'T': return 'T';
|
||||
|
||||
case 'INT':
|
||||
case 'SMALLINT':
|
||||
case 'INTEGER':
|
||||
return 'I';
|
||||
|
||||
default: return 'N';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
51
lib/adodb/drivers/adodb-oci805.inc.php
Normal file
51
lib/adodb/drivers/adodb-oci805.inc.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* @version V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
* Released under both BSD license and Lesser GPL library license.
|
||||
* Whenever there is any discrepancy between the two licenses,
|
||||
* the BSD license will take precedence.
|
||||
*
|
||||
* Set tabs to 4 for best viewing.
|
||||
*
|
||||
* Latest version is available at http://php.weblogs.com
|
||||
*
|
||||
* Oracle 8.0.5 driver
|
||||
*/
|
||||
|
||||
include_once(ADODB_DIR.'/drivers/adodb-oci8.inc.php');
|
||||
|
||||
class ADODB_oci805 extends ADODB_oci8 {
|
||||
var $databaseType = "oci805";
|
||||
var $connectSID = true;
|
||||
|
||||
function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$arg3=false,$secs2cache=0)
|
||||
{
|
||||
// seems that oracle only supports 1 hint comment in 8i
|
||||
if (strpos($sql,'/*+') !== false)
|
||||
$sql = str_replace('/*+ ','/*+FIRST_ROWS ',$sql);
|
||||
else
|
||||
$sql = preg_replace('/^[ \t\n]*select/i','SELECT /*+FIRST_ROWS*/',$sql);
|
||||
|
||||
/*
|
||||
The following is only available from 8.1.5 because order by in inline views not
|
||||
available before then...
|
||||
http://www.jlcomp.demon.co.uk/faq/top_sql.html
|
||||
if ($nrows > 0) {
|
||||
if ($offset > 0) $nrows += $offset;
|
||||
$sql = "select * from ($sql) where rownum <= $nrows";
|
||||
$nrows = -1;
|
||||
}
|
||||
*/
|
||||
|
||||
return ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$arg3,$secs2cache);
|
||||
}
|
||||
}
|
||||
|
||||
class ADORecordset_oci805 extends ADORecordset_oci8 {
|
||||
var $databaseType = "oci805";
|
||||
function ADORecordset_oci805($id)
|
||||
{
|
||||
$this->ADORecordset_oci8($id);
|
||||
}
|
||||
}
|
||||
?>
|
154
lib/adodb/drivers/adodb-oci8po.inc.php
Normal file
154
lib/adodb/drivers/adodb-oci8po.inc.php
Normal file
@ -0,0 +1,154 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 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.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
|
||||
Portable version of oci8 driver, to make it more similar to other database drivers.
|
||||
The main differences are
|
||||
|
||||
1. that the OCI_ASSOC names are in lowercase instead of uppercase.
|
||||
2. bind variables are mapped using ? instead of :<bindvar>
|
||||
|
||||
Should some emulation of RecordCount() be implemented?
|
||||
|
||||
*/
|
||||
|
||||
include_once(ADODB_DIR.'/drivers/adodb-oci8.inc.php');
|
||||
|
||||
class ADODB_oci8po extends ADODB_oci8 {
|
||||
var $databaseType = 'oci8po';
|
||||
var $dataProvider = 'oci8';
|
||||
|
||||
function Prepare($sql)
|
||||
{
|
||||
$sqlarr = explode('?',$sql);
|
||||
$sql = $sqlarr[0];
|
||||
for ($i = 1, $max = sizeof($sqlarr); $i < $max; $i++) {
|
||||
$sql .= ':'.($i-1) . $sqlarr[$i];
|
||||
}
|
||||
return ADODB_oci8::Prepare($sql);
|
||||
}
|
||||
|
||||
// emulate handling of parameters ? ?, replacing with :bind0 :bind1
|
||||
function _query($sql,$inputarr)
|
||||
{
|
||||
if (is_array($inputarr)) {
|
||||
$i = 0;
|
||||
if (is_array($sql)) {
|
||||
foreach($inputarr as $v) {
|
||||
$arr['bind'.$i++] = $v;
|
||||
}
|
||||
} else {
|
||||
$sqlarr = explode('?',$sql);
|
||||
$sql = $sqlarr[0];
|
||||
foreach($inputarr as $k => $v) {
|
||||
$sql .= ":$k" . $sqlarr[++$i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return ADODB_oci8::_query($sql,$inputarr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------------------
|
||||
Class Name: Recordset
|
||||
--------------------------------------------------------------------------------------*/
|
||||
|
||||
class ADORecordset_oci8po extends ADORecordset_oci8 {
|
||||
|
||||
var $databaseType = 'oci8po';
|
||||
|
||||
function ADORecordset_oci8po($queryID)
|
||||
{
|
||||
$this->ADORecordset_oci8($queryID);
|
||||
}
|
||||
|
||||
function Fields($colname)
|
||||
{
|
||||
if ($this->fetchMode & OCI_ASSOC) 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)]];
|
||||
}
|
||||
|
||||
// lowercase field names...
|
||||
function &_FetchField($fieldOffset = -1)
|
||||
{
|
||||
$fld = new ADOFieldObject;
|
||||
$fieldOffset += 1;
|
||||
$fld->name = strtolower(OCIcolumnname($this->_queryID, $fieldOffset));
|
||||
$fld->type = OCIcolumntype($this->_queryID, $fieldOffset);
|
||||
$fld->max_length = OCIcolumnsize($this->_queryID, $fieldOffset);
|
||||
if ($fld->type == 'NUMBER') {
|
||||
//$p = OCIColumnPrecision($this->_queryID, $fieldOffset);
|
||||
$sc = OCIColumnScale($this->_queryID, $fieldOffset);
|
||||
if ($sc == 0) $fld->type = 'INT';
|
||||
}
|
||||
return $fld;
|
||||
}
|
||||
|
||||
// 10% speedup to move MoveNext to child class
|
||||
function MoveNext()
|
||||
{
|
||||
if (!$this->EOF) {
|
||||
$this->_currentRow++;
|
||||
if(@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) {
|
||||
if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->EOF = true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Optimize SelectLimit() by using OCIFetch() instead of OCIFetchInto() */
|
||||
function &GetArrayLimit($nrows,$offset=-1)
|
||||
{
|
||||
if ($offset <= 0) return $this->GetArray($nrows);
|
||||
for ($i=1; $i < $offset; $i++)
|
||||
if (!@OCIFetch($this->_queryID)) return array();
|
||||
|
||||
if (!@OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode)) return array();
|
||||
if ($this->fetchMode & OCI_ASSOC) $this->_updatefields();
|
||||
$results = array();
|
||||
$cnt = 0;
|
||||
while (!$this->EOF && $nrows != $cnt) {
|
||||
$results[$cnt++] = $this->fields;
|
||||
$this->MoveNext();
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
// Uggh - a useless slowdown
|
||||
function _updatefields()
|
||||
{
|
||||
$arr = array();
|
||||
foreach ($this->fields as $k => $v) {
|
||||
if (is_integer($k)) $arr[$k] = $v;
|
||||
else $arr[strtolower($k)] = $v;
|
||||
}
|
||||
$this->fields = $arr;
|
||||
}
|
||||
|
||||
function _fetch()
|
||||
{
|
||||
$ret = @OCIfetchinto($this->_queryID,$this->fields,$this->fetchMode);
|
||||
if ($ret && $this->fetchMode & OCI_ASSOC) $this->_updatefields();
|
||||
return $ret;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
493
lib/adodb/drivers/adodb-odbc.inc.php
Normal file
493
lib/adodb/drivers/adodb-odbc.inc.php
Normal file
@ -0,0 +1,493 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
|
||||
Requires ODBC. Works on Windows and Unix.
|
||||
*/
|
||||
define("_ADODB_ODBC_LAYER", 1 );
|
||||
|
||||
/*--------------------------------------------------------------------------------------
|
||||
--------------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
class ADODB_odbc extends ADOConnection {
|
||||
var $databaseType = "odbc";
|
||||
var $fmtDate = "'Y-m-d'";
|
||||
var $fmtTimeStamp = "'Y-m-d, h:i:sA'";
|
||||
var $replaceQuote = "''"; // string to use to replace quotes
|
||||
var $dataProvider = "odbc";
|
||||
var $hasAffectedRows = true;
|
||||
var $binmode = ODBC_BINMODE_RETURN;
|
||||
//var $longreadlen = 8000; // default number of chars to return for a Blob/Long field
|
||||
var $_bindInputArray = false;
|
||||
var $curmode = SQL_CUR_USE_DRIVER; // See sqlext.h, SQL_CUR_DEFAULT == SQL_CUR_USE_DRIVER == 2L
|
||||
var $_genSeqSQL = "create table %s (id integer)";
|
||||
var $_autocommit = true;
|
||||
var $_haserrorfunctions = true;
|
||||
var $_has_stupid_odbc_fetch_api_change = true;
|
||||
|
||||
function ADODB_odbc()
|
||||
{
|
||||
$this->_haserrorfunctions = (strnatcmp(PHP_VERSION,'4.0.5')>=0);
|
||||
$this->_has_stupid_odbc_fetch_api_change = (strnatcmp(PHP_VERSION,'4.2.0')>=0);
|
||||
}
|
||||
|
||||
function ErrorMsg()
|
||||
{
|
||||
if ($this->_haserrorfunctions) {
|
||||
if (empty($this->_connectionID)) return @odbc_errormsg();
|
||||
return @odbc_errormsg($this->_connectionID);
|
||||
} else return ADOConnection::ErrorMsg();
|
||||
}
|
||||
|
||||
/*
|
||||
This algorithm is not very efficient, but works even if table locking
|
||||
is not available.
|
||||
|
||||
Will return false if unable to generate an ID after $MAXLOOPS attempts.
|
||||
*/
|
||||
function GenID($seq='adodbseq',$start=1)
|
||||
{
|
||||
// if you have to modify the parameter below, your database is overloaded,
|
||||
// or you need to implement generation of id's yourself!
|
||||
$MAXLOOPS = 100;
|
||||
|
||||
while (--$MAXLOOPS>=0) {
|
||||
$num = $this->GetOne("select id from $seq");
|
||||
if ($num === false) {
|
||||
$this->Execute(sprintf($this->_genSeqSQL ,$seq));
|
||||
$start -= 1;
|
||||
$num = '0';
|
||||
$ok = $this->Execute("insert into $seq values($start)");
|
||||
if (!$ok) return false;
|
||||
}
|
||||
$this->Execute("update $seq set id=id+1 where id=$num");
|
||||
|
||||
if ($this->affected_rows() == 1) {
|
||||
$num += 1;
|
||||
$this->genID = $num;
|
||||
return $num;
|
||||
}
|
||||
}
|
||||
if ($fn = $this->raiseErrorFn) {
|
||||
$fn($this->databaseType,'GENID',-32000,"Unable to generate unique id after $MAXLOOP attempts",$seq,$num);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function ErrorNo()
|
||||
{
|
||||
if ($this->_haserrorfunctions) {
|
||||
if (empty($this->_connectionID)) $e = @odbc_error();
|
||||
else $e = @odbc_error($this->_connectionID);
|
||||
|
||||
// bug in 4.0.6, error number can be corrupted string (should be 6 digits)
|
||||
// so we check and patch
|
||||
if (strlen($e)<=2) return 0;
|
||||
return $e;
|
||||
} else return ADOConnection::ErrorNo();
|
||||
}
|
||||
|
||||
|
||||
// returns true or false
|
||||
function _connect($argDSN, $argUsername, $argPassword, $argDatabasename)
|
||||
{
|
||||
global $php_errormsg;
|
||||
|
||||
$php_errormsg = '';
|
||||
$this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword,$this->curmode);
|
||||
$this->_errorMsg = $php_errormsg;
|
||||
|
||||
//if ($this->_connectionID) odbc_autocommit($this->_connectionID,true);
|
||||
return $this->_connectionID != false;
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename)
|
||||
{
|
||||
global $php_errormsg;
|
||||
$php_errormsg = '';
|
||||
$this->_connectionID = odbc_pconnect($argDSN,$argUsername,$argPassword,$this->curmode);
|
||||
$this->_errorMsg = $php_errormsg;
|
||||
|
||||
//if ($this->_connectionID) odbc_autocommit($this->_connectionID,true);
|
||||
return $this->_connectionID != false;
|
||||
}
|
||||
|
||||
function BeginTrans()
|
||||
{
|
||||
$this->_autocommit = false;
|
||||
return odbc_autocommit($this->_connectionID,false);
|
||||
}
|
||||
|
||||
function CommitTrans($ok=true)
|
||||
{
|
||||
if (!$ok) return $this->RollbackTrans();
|
||||
$this->_autocommit = true;
|
||||
$ret = odbc_commit($this->_connectionID);
|
||||
odbc_autocommit($this->_connectionID,true);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function RollbackTrans()
|
||||
{
|
||||
$this->_autocommit = true;
|
||||
$ret = odbc_rollback($this->_connectionID);
|
||||
odbc_autocommit($this->_connectionID,true);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function MetaTables()
|
||||
{
|
||||
global $ADODB_FETCH_MODE;
|
||||
|
||||
$savem = $ADODB_FETCH_MODE;
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
||||
$qid = odbc_tables($this->_connectionID);
|
||||
$ADODB_FETCH_MODE = $savem;
|
||||
|
||||
$rs = new ADORecordSet_odbc($qid);
|
||||
if (!$rs) return false;
|
||||
|
||||
$rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change;
|
||||
|
||||
//print_r($rs);
|
||||
$arr = $rs->GetArray();
|
||||
$rs->Close();
|
||||
$arr2 = array();
|
||||
for ($i=0; $i < sizeof($arr); $i++) {
|
||||
if ($arr[$i][2]) $arr2[] = $arr[$i][2];
|
||||
}
|
||||
return $arr2;
|
||||
}
|
||||
|
||||
/*
|
||||
/ SQL data type codes /
|
||||
#define SQL_UNKNOWN_TYPE 0
|
||||
#define SQL_CHAR 1
|
||||
#define SQL_NUMERIC 2
|
||||
#define SQL_DECIMAL 3
|
||||
#define SQL_INTEGER 4
|
||||
#define SQL_SMALLINT 5
|
||||
#define SQL_FLOAT 6
|
||||
#define SQL_REAL 7
|
||||
#define SQL_DOUBLE 8
|
||||
#if (ODBCVER >= 0x0300)
|
||||
#define SQL_DATETIME 9
|
||||
#endif
|
||||
#define SQL_VARCHAR 12
|
||||
|
||||
/ One-parameter shortcuts for date/time data types /
|
||||
#if (ODBCVER >= 0x0300)
|
||||
#define SQL_TYPE_DATE 91
|
||||
#define SQL_TYPE_TIME 92
|
||||
#define SQL_TYPE_TIMESTAMP 93
|
||||
*/
|
||||
function ODBCTypes($t)
|
||||
{
|
||||
switch ((integer)$t) {
|
||||
case 1:
|
||||
case 12:
|
||||
case 0:
|
||||
return 'C';
|
||||
case -1: //text
|
||||
return 'X';
|
||||
case -4: //image
|
||||
return 'B';
|
||||
|
||||
case 91:
|
||||
case 11:
|
||||
return 'D';
|
||||
|
||||
case 92:
|
||||
case 93:
|
||||
case 9: return 'T';
|
||||
case 4:
|
||||
case 5:
|
||||
case -6:
|
||||
return 'I';
|
||||
|
||||
case -11: // uniqidentifier
|
||||
return 'R';
|
||||
case -7: //bit
|
||||
return 'L';
|
||||
|
||||
default:
|
||||
return 'N';
|
||||
}
|
||||
}
|
||||
|
||||
function MetaColumns($table)
|
||||
{
|
||||
global $ADODB_FETCH_MODE;
|
||||
|
||||
$table = strtoupper($table);
|
||||
|
||||
/* // for some reason, cannot view only 1 table with odbc_columns -- bug?
|
||||
$qid = odbc_tables($this->_connectionID);
|
||||
$rs = new ADORecordSet_odbc($qid);
|
||||
if (!$rs) return false;
|
||||
while (!$rs->EOF) {
|
||||
if ($table == strtoupper($rs->fields[2])) {
|
||||
$q = $rs->fields[0];
|
||||
$o = $rs->fields[1];
|
||||
break;
|
||||
}
|
||||
$rs->MoveNext();
|
||||
}
|
||||
$rs->Close();
|
||||
|
||||
$qid = odbc_columns($this->_connectionID,$q,$o,strtoupper($table),'%');
|
||||
*/
|
||||
$savem = $ADODB_FETCH_MODE;
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
||||
$qid = odbc_columns($this->_connectionID);
|
||||
$rs = new ADORecordSet_odbc($qid);
|
||||
$ADODB_FETCH_MODE = $savem;
|
||||
|
||||
if (!$rs) return false;
|
||||
|
||||
$rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change;
|
||||
|
||||
$retarr = array();
|
||||
while (!$rs->EOF) {
|
||||
if (strtoupper($rs->fields[2]) == $table) {
|
||||
$fld = new ADOFieldObject();
|
||||
$fld->name = $rs->fields[3];
|
||||
$fld->type = $this->ODBCTypes($rs->fields[4]);
|
||||
$fld->max_length = $rs->fields[7];
|
||||
$retarr[strtoupper($fld->name)] = $fld;
|
||||
} else if (sizeof($retarr)>0)
|
||||
break;
|
||||
$rs->MoveNext();
|
||||
}
|
||||
$rs->Close(); //-- crashes 4.03pl1 -- why?
|
||||
|
||||
return $retarr;
|
||||
}
|
||||
|
||||
function Prepare($sql)
|
||||
{
|
||||
if (! $this->_bindInputArray) return $sql; // no binding
|
||||
$stmt = odbc_prepare($this->_connectionID,$sql);
|
||||
if (!$stmt) {
|
||||
// print "Prepare Error for ($sql) ".$this->ErrorMsg()."<br>";
|
||||
return $sql;
|
||||
}
|
||||
return array($sql,$stmt,false);
|
||||
}
|
||||
|
||||
/* returns queryID or false */
|
||||
function _query($sql,$inputarr=false)
|
||||
{
|
||||
GLOBAL $php_errormsg;
|
||||
$php_errormsg = '';
|
||||
$this->_error = '';
|
||||
|
||||
if ($inputarr) {
|
||||
if (is_array($sql)) $stmtid = $sql[1];
|
||||
else $stmtid = odbc_prepare($this->_connectionID,$sql);
|
||||
|
||||
if ($stmtid == false) {
|
||||
$this->_errorMsg = $php_errormsg;
|
||||
return false;
|
||||
}
|
||||
if (! odbc_execute($stmtid,$inputarr)) {
|
||||
@odbc_free_result($stmtid);
|
||||
return false;
|
||||
}
|
||||
|
||||
} else if (is_array($sql)) {
|
||||
$stmtid = $sql[1];
|
||||
if (!odbc_execute($stmtid)) {
|
||||
@odbc_free_result($stmtid);
|
||||
return false;
|
||||
}
|
||||
} else
|
||||
$stmtid = odbc_exec($this->_connectionID,$sql);
|
||||
|
||||
if ($stmtid) {
|
||||
odbc_binmode($stmtid,$this->binmode);
|
||||
odbc_longreadlen($stmtid,$this->maxblobsize);
|
||||
}
|
||||
$this->_errorMsg = $php_errormsg;
|
||||
return $stmtid;
|
||||
}
|
||||
|
||||
/*
|
||||
Insert a null into the blob field of the table first.
|
||||
Then use UpdateBlob to store the blob.
|
||||
|
||||
Usage:
|
||||
|
||||
$conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)');
|
||||
$conn->UpdateBlob('blobtable','blobcol',$blob,'id=1');
|
||||
*/
|
||||
function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB')
|
||||
{
|
||||
return $this->Execute("UPDATE $table SET $column=? WHERE $where",array($val)) != false;
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
function _close()
|
||||
{
|
||||
$ret = @odbc_close($this->_connectionID);
|
||||
$this->_connectionID = false;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function _affectedrows()
|
||||
{
|
||||
return odbc_num_rows($this->_queryID);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------------------
|
||||
Class Name: Recordset
|
||||
--------------------------------------------------------------------------------------*/
|
||||
|
||||
class ADORecordSet_odbc extends ADORecordSet {
|
||||
|
||||
var $bind = false;
|
||||
var $databaseType = "odbc";
|
||||
var $dataProvider = "odbc";
|
||||
var $_has_stupid_odbc_fetch_api_change;
|
||||
|
||||
function ADORecordSet_odbc($id)
|
||||
{
|
||||
global $ADODB_FETCH_MODE;
|
||||
|
||||
$this->fetchMode = $ADODB_FETCH_MODE;
|
||||
return $this->ADORecordSet($id);
|
||||
}
|
||||
|
||||
|
||||
// returns the field object
|
||||
function &FetchField($fieldOffset = -1) {
|
||||
|
||||
$off=$fieldOffset+1; // offsets begin at 1
|
||||
|
||||
$o= new ADOFieldObject();
|
||||
$o->name = @odbc_field_name($this->_queryID,$off);
|
||||
$o->type = @odbc_field_type($this->_queryID,$off);
|
||||
$o->max_length = @odbc_field_len($this->_queryID,$off);
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
/* Use associative array to get fields array */
|
||||
function Fields($colname)
|
||||
{
|
||||
if ($this->fetchMode & ADODB_FETCH_ASSOC) 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 _initrs()
|
||||
{
|
||||
global $ADODB_COUNTRECS;
|
||||
$this->_numOfRows = ($ADODB_COUNT_RECS) ? @odbc_num_rows($this->_queryID) : -1;
|
||||
$this->_numOfFields = @odbc_num_fields($this->_queryID);
|
||||
|
||||
$this->_has_stupid_odbc_fetch_api_change = $this->connection->_has_stupid_odbc_fetch_api_change;
|
||||
}
|
||||
|
||||
function _seek($row)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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);
|
||||
$savem = $this->fetchMode;
|
||||
$this->fetchMode = ADODB_FETCH_NUM;
|
||||
$this->Move($offset);
|
||||
$this->fetchMode = $savem;
|
||||
|
||||
if ($this->fetchMode & ADODB_FETCH_ASSOC) {
|
||||
$this->fields = $this->GetRowAssoc(false);
|
||||
}
|
||||
|
||||
$results = array();
|
||||
$cnt = 0;
|
||||
while (!$this->EOF && $nrows != $cnt) {
|
||||
$results[$cnt++] = $this->fields;
|
||||
$this->MoveNext();
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
|
||||
function MoveNext()
|
||||
{
|
||||
if ($this->_numOfRows != 0 && !$this->EOF) {
|
||||
$this->_currentRow++;
|
||||
$row = 0;
|
||||
if ($this->_has_stupid_odbc_fetch_api_change)
|
||||
$rez = odbc_fetch_into($this->_queryID,$this->fields,$row);
|
||||
else
|
||||
$rez = odbc_fetch_into($this->_queryID,$row,$this->fields);
|
||||
if ($rez) {
|
||||
if ($this->fetchMode & ADODB_FETCH_ASSOC) {
|
||||
$this->fields = $this->GetRowAssoc(false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
$this->EOF = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function _fetch()
|
||||
{
|
||||
$row = 0;
|
||||
/*
|
||||
if ($this->fetchMode & ADODB_FETCH_ASSOC) {
|
||||
$this->fields = odbc_fetch_array($this->_queryID,$row);
|
||||
return is_array($this->fields);
|
||||
} else {
|
||||
return odbc_fetch_into($this->_queryID,$row,$this->fields);
|
||||
}*/
|
||||
|
||||
if ($this->_has_stupid_odbc_fetch_api_change)
|
||||
$rez = odbc_fetch_into($this->_queryID,$this->fields,$row);
|
||||
else
|
||||
$rez = odbc_fetch_into($this->_queryID,$row,$this->fields);
|
||||
|
||||
if ($rez) {
|
||||
if ($this->fetchMode & ADODB_FETCH_ASSOC) {
|
||||
$this->fields = $this->GetRowAssoc(false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function _close() {
|
||||
|
||||
return @odbc_free_result($this->_queryID);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
44
lib/adodb/drivers/adodb-odbc_mssql.inc.php
Normal file
44
lib/adodb/drivers/adodb-odbc_mssql.inc.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
|
||||
MSSQL support via ODBC. Requires ODBC. Works on Windows and Unix.
|
||||
For Unix configuration, see http://phpbuilder.com/columns/alberto20000919.php3
|
||||
*/
|
||||
|
||||
if (!defined('_ADODB_ODBC_LAYER')) {
|
||||
include(ADODB_DIR."/drivers/adodb-odbc.inc.php");
|
||||
}
|
||||
|
||||
|
||||
class ADODB_odbc_mssql extends ADODB_odbc {
|
||||
var $databaseType = 'odbc_mssql';
|
||||
var $fmtDate = "'Y-m-d'";
|
||||
var $fmtTimeStamp = "'Y-m-d h:i:sA'";
|
||||
var $_bindInputArray = true;
|
||||
var $hasTop = 'top'; // support mssql/interbase SELECT TOP 10 * FROM TABLE
|
||||
var $sysDate = 'GetDate()';
|
||||
var $sysTimeStamp = 'GetDate()';
|
||||
|
||||
function ADODB_odbc_mssql()
|
||||
{
|
||||
$this->ADODB_odbc();
|
||||
}
|
||||
}
|
||||
|
||||
class ADORecordSet_odbc_mssql extends ADORecordSet_odbc {
|
||||
|
||||
var $databaseType = 'odbc_mssql';
|
||||
|
||||
function ADORecordSet_odbc_mssql($id)
|
||||
{
|
||||
return $this->ADORecordSet_odbc($id);
|
||||
}
|
||||
}
|
||||
?>
|
112
lib/adodb/drivers/adodb-odbc_oracle.inc.php
Normal file
112
lib/adodb/drivers/adodb-odbc_oracle.inc.php
Normal file
@ -0,0 +1,112 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
|
||||
Oracle support via ODBC. Requires ODBC. Works on Windows.
|
||||
*/
|
||||
|
||||
if (!defined('_ADODB_ODBC_LAYER')) {
|
||||
include(ADODB_DIR."/drivers/adodb-odbc.inc.php");
|
||||
}
|
||||
|
||||
|
||||
class ADODB_odbc_oracle extends ADODB_odbc {
|
||||
var $databaseType = 'odbc_oracle';
|
||||
var $replaceQuote = "''"; // string to use to replace quotes
|
||||
var $concat_operator='||';
|
||||
var $fmtDate = "'Y-m-d 00:00:00'";
|
||||
var $fmtTimeStamp = "'Y-m-d h:i:sA'";
|
||||
var $metaTablesSQL = 'select table_name from cat';
|
||||
var $metaColumnsSQL = "select cname,coltype,width from col where tname='%s' order by colno";
|
||||
var $sysDate = "TO_DATE(TO_CHAR(SYSDATE,'YYYY-MM-DD'),'YYYY-MM-DD')";
|
||||
var $sysTimeStamp = 'SYSDATE';
|
||||
|
||||
//var $_bindInputArray = false;
|
||||
|
||||
function ADODB_odbc_oracle()
|
||||
{
|
||||
$this->ADODB_odbc();
|
||||
}
|
||||
|
||||
function &MetaTables()
|
||||
{
|
||||
if ($this->metaTablesSQL) {
|
||||
$rs = $this->Execute($this->metaTablesSQL);
|
||||
if ($rs === false) return false;
|
||||
$arr = $rs->GetArray();
|
||||
$arr2 = array();
|
||||
for ($i=0; $i < sizeof($arr); $i++) {
|
||||
$arr2[] = $arr[$i][0];
|
||||
}
|
||||
$rs->Close();
|
||||
return $arr2;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function &MetaColumns($table)
|
||||
{
|
||||
if (!empty($this->metaColumnsSQL)) {
|
||||
|
||||
$rs = $this->Execute(sprintf($this->metaColumnsSQL,strtoupper($table)));
|
||||
if ($rs === false) return false;
|
||||
|
||||
$retarr = array();
|
||||
while (!$rs->EOF) { //print_r($rs->fields);
|
||||
$fld = new ADOFieldObject();
|
||||
$fld->name = $rs->fields[0];
|
||||
$fld->type = $rs->fields[1];
|
||||
$fld->max_length = $rs->fields[2];
|
||||
$retarr[strtoupper($fld->name)] = $fld;
|
||||
|
||||
$rs->MoveNext();
|
||||
}
|
||||
$rs->Close();
|
||||
return $retarr;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
function _connect($argDSN, $argUsername, $argPassword, $argDatabasename)
|
||||
{
|
||||
global $php_errormsg;
|
||||
|
||||
$php_errormsg = '';
|
||||
$this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword,SQL_CUR_USE_ODBC );
|
||||
$this->_errorMsg = $php_errormsg;
|
||||
|
||||
$this->Execute("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'");
|
||||
//if ($this->_connectionID) odbc_autocommit($this->_connectionID,true);
|
||||
return $this->_connectionID != false;
|
||||
}
|
||||
// returns true or false
|
||||
function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename)
|
||||
{
|
||||
global $php_errormsg;
|
||||
$php_errormsg = '';
|
||||
$this->_connectionID = odbc_pconnect($argDSN,$argUsername,$argPassword,SQL_CUR_USE_ODBC );
|
||||
$this->_errorMsg = $php_errormsg;
|
||||
|
||||
$this->Execute("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'");
|
||||
//if ($this->_connectionID) odbc_autocommit($this->_connectionID,true);
|
||||
return $this->_connectionID != false;
|
||||
}
|
||||
}
|
||||
|
||||
class ADORecordSet_odbc_oracle extends ADORecordSet_odbc {
|
||||
|
||||
var $databaseType = 'odbc_oracle';
|
||||
|
||||
function ADORecordSet_odbc_oracle($id)
|
||||
{
|
||||
return $this->ADORecordSet_odbc($id);
|
||||
}
|
||||
}
|
||||
?>
|
255
lib/adodb/drivers/adodb-oracle.inc.php
Normal file
255
lib/adodb/drivers/adodb-oracle.inc.php
Normal file
@ -0,0 +1,255 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
|
||||
Oracle data driver. Requires Oracle client. Works on Windows and Unix and Oracle 7 and 8.
|
||||
|
||||
If you are using Oracle 8, use the oci8 driver which is much better and more reliable.
|
||||
|
||||
*/
|
||||
|
||||
// select table_name from cat -- MetaTables
|
||||
//
|
||||
class ADODB_oracle extends ADOConnection {
|
||||
var $databaseType = "oracle";
|
||||
var $replaceQuote = "\'"; // string to use to replace quotes
|
||||
var $concat_operator='||';
|
||||
var $_curs;
|
||||
var $_initdate = true; // init date to YYYY-MM-DD
|
||||
var $metaTablesSQL = 'select table_name from cat';
|
||||
var $metaColumnsSQL = "select cname,coltype,width from col where tname='%s' order by colno";
|
||||
var $sysDate = "TO_DATE(TO_CHAR(SYSDATE,'YYYY-MM-DD'),'YYYY-MM-DD')";
|
||||
var $sysTimeStamp = 'SYSDATE';
|
||||
|
||||
function ADODB_oracle()
|
||||
{
|
||||
}
|
||||
|
||||
// format and return date string in database date format
|
||||
function DBDate($d)
|
||||
{
|
||||
if (is_string($d)) $d = ADORecordSet::UnixDate($d);
|
||||
return 'TO_DATE('.date($this->fmtDate,$d).",'YYYY-MM-DD')";
|
||||
}
|
||||
|
||||
// format and return date string in database timestamp format
|
||||
function DBTimeStamp($ts)
|
||||
{
|
||||
if (is_string($ts)) $d = ADORecordSet::UnixTimeStamp($ts);
|
||||
return 'TO_DATE('.date($this->fmtTimeStamp,$ts).",'RRRR-MM-DD, HH:MI:SS AM')";
|
||||
}
|
||||
|
||||
function BeginTrans()
|
||||
{
|
||||
$this->autoCommit = false;
|
||||
ora_commitoff($this->_connectionID);
|
||||
return true;
|
||||
}
|
||||
|
||||
function CommitTrans($ok=true)
|
||||
{
|
||||
if (!$ok) return $this->RollbackTrans();
|
||||
$ret = ora_commit($this->_connectionID);
|
||||
ora_commiton($this->_connectionID);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function RollbackTrans()
|
||||
{
|
||||
$ret = ora_rollback($this->_connectionID);
|
||||
ora_commiton($this->_connectionID);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/* there seems to be a bug in the oracle extension -- always returns ORA-00000 - no error */
|
||||
function ErrorMsg()
|
||||
{
|
||||
$this->_errorMsg = @ora_error($this->_curs);
|
||||
if (!$this->_errorMsg) $this->_errorMsg = @ora_error($this->_connectionID);
|
||||
return $this->_errorMsg;
|
||||
}
|
||||
|
||||
function ErrorNo()
|
||||
{
|
||||
$err = @ora_errorcode($this->_curs);
|
||||
if (!$err) return @ora_errorcode($this->_connectionID);
|
||||
}
|
||||
|
||||
|
||||
// returns true or false
|
||||
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
|
||||
{
|
||||
if ($argHostname) putenv("ORACLE_HOME=$argHostname");
|
||||
if ($argDatabasename) $argUsername .= "@$argDatabasename";
|
||||
//if ($argHostname) print "<p>Connect: 1st argument should be left blank for $this->databaseType</p>";
|
||||
$this->_connectionID = ora_logon($argUsername,$argPassword);
|
||||
if ($this->_connectionID === false) return false;
|
||||
if ($this->autoCommit) ora_commiton($this->_connectionID);
|
||||
if ($this->_initdate) $this->Execute("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD'");
|
||||
|
||||
return true;
|
||||
}
|
||||
// returns true or false
|
||||
function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
|
||||
{
|
||||
if ($argHostname) putenv("ORACLE_HOME=$argHostname");
|
||||
if ($argDatabasename) $argUsername .= "@$argDatabasename";
|
||||
//if ($argHostname) print "<p>PConnect: 1st argument should be left blank for $this->databaseType</p>";
|
||||
$this->_connectionID = ora_plogon($argUsername,$argPassword);
|
||||
if ($this->_connectionID === false) return false;
|
||||
if ($this->autoCommit) ora_commiton($this->_connectionID);
|
||||
if ($this->_initdate) $this->Execute("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD'");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// returns query ID if successful, otherwise false
|
||||
function _query($sql,$inputarr)
|
||||
{
|
||||
$curs = ora_open($this->_connectionID);
|
||||
|
||||
if ($curs === false) return false;
|
||||
$this->_curs = $curs;
|
||||
if (!ora_parse($curs,$sql)) return false;
|
||||
if (ora_exec($curs)) return $curs;
|
||||
|
||||
@ora_close($curs);
|
||||
return false;
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
function _close()
|
||||
{
|
||||
if (!$this->autoCommit) ora_rollback($this->_connectionID);
|
||||
return @ora_close($this->_connectionID);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------------------
|
||||
Class Name: Recordset
|
||||
--------------------------------------------------------------------------------------*/
|
||||
|
||||
class ADORecordset_oracle extends ADORecordSet {
|
||||
|
||||
var $databaseType = "oracle";
|
||||
var $bind = false;
|
||||
|
||||
function ADORecordset_oracle($queryID)
|
||||
{
|
||||
global $ADODB_FETCH_MODE;
|
||||
|
||||
$this->fetchMode = $ADODB_FETCH_MODE;
|
||||
|
||||
$this->_queryID = $queryID;
|
||||
|
||||
$this->_inited = true;
|
||||
$this->fields = array();
|
||||
if ($queryID) {
|
||||
$this->_currentRow = 0;
|
||||
$this->EOF = !$this->_fetch();
|
||||
@$this->_initrs();
|
||||
} else {
|
||||
$this->_numOfRows = 0;
|
||||
$this->_numOfFields = 0;
|
||||
$this->EOF = true;
|
||||
}
|
||||
|
||||
return $this->_queryID;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Returns: an object containing field information.
|
||||
Get column information in the Recordset object. fetchField() can be used in order to obtain information about
|
||||
fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by
|
||||
fetchField() is retrieved. */
|
||||
|
||||
function FetchField($fieldOffset = -1)
|
||||
{
|
||||
$fld = new ADOFieldObject;
|
||||
$fld->name = ora_columnname($this->_queryID, $fieldOffset);
|
||||
$fld->type = ora_columntype($this->_queryID, $fieldOffset);
|
||||
$fld->max_length = ora_columnsize($this->_queryID, $fieldOffset);
|
||||
return $fld;
|
||||
}
|
||||
|
||||
/* Use associative array to get fields array */
|
||||
function 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 _initrs()
|
||||
{
|
||||
$this->_numOfRows = -1;
|
||||
$this->_numOfFields = @ora_numcols($this->_queryID);
|
||||
}
|
||||
|
||||
|
||||
function _seek($row)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
function _fetch($ignore_fields=false) {
|
||||
// should remove call by reference, but ora_fetch_into requires it in 4.0.3pl1
|
||||
if ($this->fetchMode & ADODB_FETCH_ASSOC)
|
||||
return @ora_fetch_into($this->_queryID,&$this->fields,ORA_FETCHINTO_NULLS|ORA_FETCHINTO_ASSOC);
|
||||
else
|
||||
return @ora_fetch_into($this->_queryID,&$this->fields,ORA_FETCHINTO_NULLS);
|
||||
}
|
||||
|
||||
/* close() only needs to be called if you are worried about using too much memory while your script
|
||||
is running. All associated result memory for the specified result identifier will automatically be freed. */
|
||||
|
||||
function _close()
|
||||
{
|
||||
return @ora_close($this->_queryID);
|
||||
}
|
||||
|
||||
function MetaType($t,$len=-1)
|
||||
{
|
||||
switch (strtoupper($t)) {
|
||||
case 'VARCHAR':
|
||||
case 'VARCHAR2':
|
||||
case 'CHAR':
|
||||
case 'VARBINARY':
|
||||
case 'BINARY':
|
||||
if ($len <= $this->blobSize) return 'C';
|
||||
case 'LONG':
|
||||
case 'LONG VARCHAR':
|
||||
case 'CLOB':
|
||||
return 'X';
|
||||
case 'LONG RAW':
|
||||
case 'LONG VARBINARY':
|
||||
case 'BLOB':
|
||||
return 'B';
|
||||
|
||||
case 'DATE': return 'D';
|
||||
|
||||
//case 'T': return 'T';
|
||||
|
||||
case 'BIT': return 'L';
|
||||
case 'INT':
|
||||
case 'SMALLINT':
|
||||
case 'INTEGER': return 'I';
|
||||
default: return 'N';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
64
lib/adodb/drivers/adodb-postgres.inc.php
Normal file
64
lib/adodb/drivers/adodb-postgres.inc.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 4.
|
||||
|
||||
Postgres7 support.
|
||||
28 Feb 2001: Currently indicate that we support LIMIT
|
||||
01 Dec 2001: dannym added support for default values
|
||||
*/
|
||||
|
||||
include_once(ADODB_DIR."/drivers/adodb-postgres64.inc.php");
|
||||
|
||||
class ADODB_postgres extends ADODB_postgres64 {
|
||||
var $databaseType = 'postgres';
|
||||
var $hasLimit = true; // set to true for pgsql 6.5+ only. support pgsql/mysql SELECT * FROM TABLE LIMIT 10
|
||||
|
||||
function ADODB_postgres()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// the following should be compat with postgresql 7.2,
|
||||
// which makes obsolete the LIMIT limit,offset syntax
|
||||
function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$arg3=false,$secs2cache=0)
|
||||
{
|
||||
$offsetStr = ($offset >= 0) ? " OFFSET $offset" : '';
|
||||
$limitStr = ($nrows >= 0) ? " LIMIT $nrows" : '';
|
||||
return $secs2cache ?
|
||||
$this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr,$arg3)
|
||||
:
|
||||
$this->Execute($sql."$limitStr$offsetStr",$inputarr,$arg3);
|
||||
}
|
||||
|
||||
// 10% speedup to move MoveNext to child class
|
||||
function MoveNext()
|
||||
{
|
||||
if (!$this->EOF) {
|
||||
$this->_currentRow++;
|
||||
$this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);
|
||||
if (is_array($this->fields)) return true;
|
||||
}
|
||||
$this->EOF = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------------------
|
||||
Class Name: Recordset
|
||||
--------------------------------------------------------------------------------------*/
|
||||
|
||||
class ADORecordSet_postgres extends ADORecordSet_postgres64{
|
||||
|
||||
var $databaseType = "postgres";
|
||||
|
||||
function ADORecordSet_postgres($queryID)
|
||||
{
|
||||
$this->ADORecordSet_postgres64($queryID);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
536
lib/adodb/drivers/adodb-postgres64.inc.php
Normal file
536
lib/adodb/drivers/adodb-postgres64.inc.php
Normal file
@ -0,0 +1,536 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 8.
|
||||
|
||||
Original version derived from Alberto Cerezal (acerezalp@dbnet.es) - DBNet Informatica & Comunicaciones.
|
||||
08 Nov 2000 jlim - Minor corrections, removing mysql stuff
|
||||
09 Nov 2000 jlim - added insertid support suggested by "Christopher Kings-Lynne" <chriskl@familyhealth.com.au>
|
||||
jlim - changed concat operator to || and data types to MetaType to match documented pgsql types
|
||||
see http://www.postgresql.org/devel-corner/docs/postgres/datatype.htm
|
||||
22 Nov 2000 jlim - added changes to FetchField() and MetaTables() contributed by "raser" <raser@mail.zen.com.tw>
|
||||
27 Nov 2000 jlim - added changes to _connect/_pconnect from ideas by "Lennie" <leen@wirehub.nl>
|
||||
15 Dec 2000 jlim - added changes suggested by Additional code changes by "Eric G. Werk" egw@netguide.dk.
|
||||
31 Jan 2002 jlim - finally installed postgresql. testing
|
||||
01 Mar 2001 jlim - Freek Dijkstra changes, also support for text type
|
||||
*/
|
||||
|
||||
class ADODB_postgres64 extends ADOConnection{
|
||||
var $databaseType = 'postgres64';
|
||||
var $dataProvider = 'postgres';
|
||||
var $hasInsertID = true;
|
||||
var $_resultid = false;
|
||||
var $concat_operator='||';
|
||||
var $metaTablesSQL = "select tablename from pg_tables where tablename not like 'pg_%' order by 1";
|
||||
var $isoDates = true; // accepts dates in ISO format
|
||||
var $sysDate = "CURRENT_DATE";
|
||||
var $sysTimeStamp = "CURRENT_TIMESTAMP";
|
||||
|
||||
/*
|
||||
# show tables and views suggestion
|
||||
"SELECT c.relname AS tablename FROM pg_class c
|
||||
WHERE (c.relhasrules AND (EXISTS (
|
||||
SELECT r.rulename FROM pg_rewrite r WHERE r.ev_class = c.oid AND bpchar(r.ev_type) = '1'
|
||||
))) OR (c.relkind = 'v') AND c.relname NOT LIKE 'pg_%'
|
||||
UNION
|
||||
SELECT tablename FROM pg_tables WHERE tablename NOT LIKE 'pg_%' ORDER BY 1"
|
||||
*/
|
||||
var $metaColumnsSQL = "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 WHERE relkind = 'r' AND c.relname='%s' 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 $_hastrans = false;
|
||||
var $hasAffectedRows = true;
|
||||
var $hasLimit = false; // set to true for pgsql 7 only. support pgsql/mysql SELECT * FROM TABLE LIMIT 10
|
||||
// below suggested by Freek Dijkstra
|
||||
var $true = 't'; // string that represents TRUE for a database
|
||||
var $false = 'f'; // string that represents FALSE for a database
|
||||
var $fmtDate = "'Y-m-d'"; // used by DBDate() as the default date format used by the database
|
||||
var $fmtTimeStamp = "'Y-m-d G:i:s'"; // used by DBTimeStamp as the default timestamp fmt.
|
||||
var $hasMoveFirst = true;
|
||||
var $hasGenID = true;
|
||||
var $_genIDSQL = "SELECT NEXTVAL('%s')";
|
||||
var $_genSeqSQL = "CREATE SEQUENCE %s START %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";
|
||||
|
||||
// The last (fmtTimeStamp is not entirely correct:
|
||||
// PostgreSQL also has support for time zones,
|
||||
// and writes these time in this format: "2001-03-01 18:59:26+02".
|
||||
// There is no code for the "+02" time zone information, so I just left that out.
|
||||
// I'm not familiar enough with both ADODB as well as Postgres
|
||||
// to know what the concequences are. The other values are correct (wheren't in 0.94)
|
||||
// -- Freek Dijkstra
|
||||
|
||||
function ADODB_postgres64()
|
||||
{
|
||||
// changes the metaColumnsSQL, adds columns: attnum[6]
|
||||
|
||||
}
|
||||
|
||||
// get the last id - never tested
|
||||
function pg_insert_id($tablename,$fieldname)
|
||||
{
|
||||
$result=pg_exec($this->_connectionID, "SELECT last_value FROM ${tablename}_${fieldname}_seq");
|
||||
if ($result) {
|
||||
$arr = @pg_fetch_row($result,0);
|
||||
pg_freeresult($result);
|
||||
if (isset($arr[0])) return $arr[0];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Warning from http://www.php.net/manual/function.pg-getlastoid.php:
|
||||
Using a OID as a unique identifier is not generally wise.
|
||||
Unless you are very careful, you might end up with a tuple having
|
||||
a different OID if a database must be reloaded. */
|
||||
function _insertid()
|
||||
{
|
||||
return pg_getlastoid($this->_resultid);
|
||||
}
|
||||
|
||||
// I get this error with PHP before 4.0.6 - jlim
|
||||
// Warning: This compilation does not support pg_cmdtuples() in d:/inetpub/wwwroot/php/adodb/adodb-postgres.inc.php on line 44
|
||||
function _affectedrows()
|
||||
{
|
||||
return pg_cmdtuples($this->_resultid);
|
||||
}
|
||||
|
||||
|
||||
// returns true/false
|
||||
function BeginTrans()
|
||||
{
|
||||
$this->_hastrans = true;
|
||||
return @pg_Exec($this->_connectionID, "begin");
|
||||
}
|
||||
|
||||
function RowLock($tables,$where)
|
||||
{
|
||||
if (!$this->_hastrans) $this->BeginTrans();
|
||||
return $this->GetOne("select 1 as ignore from $tables where $where for update");
|
||||
}
|
||||
|
||||
// returns true/false.
|
||||
function CommitTrans($ok=true)
|
||||
{
|
||||
if (!$ok) return $this->RollbackTrans();
|
||||
$this->_hastrans = false;
|
||||
return @pg_Exec($this->_connectionID, "commit");
|
||||
}
|
||||
|
||||
// returns true/false
|
||||
function RollbackTrans()
|
||||
{
|
||||
$this->_hastrans = false;
|
||||
return @pg_Exec($this->_connectionID, "rollback");
|
||||
}
|
||||
|
||||
/*
|
||||
* Load a Large Object from a file
|
||||
* - the procedure stores the object id in the table and imports the object using
|
||||
* postgres proprietary blob handling routines
|
||||
*
|
||||
* contributed by Mattia Rossi mattia@technologist.com
|
||||
*/
|
||||
function UpdateBlobFile($table,$column,$val,$where,$blobtype='BLOB')
|
||||
{
|
||||
pg_exec ($this->_connectionID, "begin");
|
||||
$oid = pg_lo_import ($val);
|
||||
pg_exec ($this->_connectionID, "commit");
|
||||
$rs = ADOConnection::UpdateBlob($table,$column,$oid,$where,$blobtype);
|
||||
$rez = !empty($rs);
|
||||
return $rez;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reads the real blob from the db using the oid supplied as a parameter
|
||||
*
|
||||
* contributed by Mattia Rossi mattia@technologist.com
|
||||
*/
|
||||
function BlobDecode( $blob )
|
||||
{
|
||||
@pg_exec("begin");
|
||||
$fd = @pg_lo_open($blob,"r");
|
||||
$realblob = @pg_loreadall($fd);
|
||||
@pg_loclose($fd);
|
||||
@pg_exec("commit");
|
||||
return( $realblob );
|
||||
}
|
||||
|
||||
|
||||
// converts table names to lowercase
|
||||
function &MetaColumns($table)
|
||||
{
|
||||
global $ADODB_FETCH_MODE;
|
||||
|
||||
if (!empty($this->metaColumnsSQL)) {
|
||||
// the following is the only difference -- we lowercase it
|
||||
$save = $ADODB_FETCH_MODE;
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
||||
|
||||
$rs = $this->Execute(sprintf($this->metaColumnsSQL,strtolower($table)));
|
||||
|
||||
$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_NUM;
|
||||
|
||||
$rskey = $this->Execute(sprintf($this->metaKeySQL,strtolower($table)));
|
||||
// fetch all result in once for performance.
|
||||
$keys = $rskey->GetArray();
|
||||
|
||||
$ADODB_FETCH_MODE = $save;
|
||||
|
||||
$rskey->Close();
|
||||
unset($rskey);
|
||||
}
|
||||
|
||||
$rsdefa = array();
|
||||
if (!empty($this->metaDefaultsSQL)) {
|
||||
$sql = sprintf($this->metaDefaultsSQL, strtolower($table));
|
||||
$rsdef = $this->Execute($sql);
|
||||
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 {
|
||||
print "==> SQL => " . $sql . "\n";
|
||||
}
|
||||
unset($rsdef);
|
||||
}
|
||||
|
||||
$retarr = array();
|
||||
while (!$rs->EOF) { //print_r($rs->fields);
|
||||
$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?
|
||||
}
|
||||
}
|
||||
|
||||
$retarr[strtoupper($fld->name)] = $fld;
|
||||
|
||||
$rs->MoveNext();
|
||||
}
|
||||
$rs->Close();
|
||||
return $retarr;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function &MetaDatabases()
|
||||
{
|
||||
$arr = array();
|
||||
$sql="select datname from pg_database";
|
||||
$rs = $this->Execute($sql);
|
||||
if (!$rs) return false;
|
||||
while (!$rs->EOF) {
|
||||
$arr[] = $rs->fields[0];
|
||||
$rs->MoveNext();
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
|
||||
// returns true or false
|
||||
//
|
||||
// examples:
|
||||
// $db->Connect("host=host1 user=user1 password=secret port=4341");
|
||||
// $db->Connect('host1','user1','secret');
|
||||
function _connect($str,$user='',$pwd='',$db='')
|
||||
{
|
||||
if ($user || $pwd || $db) {
|
||||
if ($str) {
|
||||
$host = split(":", $str);
|
||||
if ($host[0]) $str = "host=$host[0]";
|
||||
else $str = 'localhost';
|
||||
if (isset($host[1])) $str .= " port=$host[1]";
|
||||
}
|
||||
if ($user) $str .= " user=".$user;
|
||||
if ($pwd) $str .= " password=".$pwd;
|
||||
if ($db) $str .= " dbname=".$db;
|
||||
}
|
||||
|
||||
//if ($user) $linea = "user=$user host=$linea password=$pwd dbname=$db port=5432";
|
||||
$this->_connectionID = pg_connect($str);
|
||||
if ($this->_connectionID === false) return false;
|
||||
$this->Execute("set datestyle='ISO'");
|
||||
return true;
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
//
|
||||
// examples:
|
||||
// $db->PConnect("host=host1 user=user1 password=secret port=4341");
|
||||
// $db->PConnect('host1','user1','secret');
|
||||
function _pconnect($str,$user='',$pwd='',$db='')
|
||||
{
|
||||
if ($user || $pwd || $db) {
|
||||
if ($str) {
|
||||
$host = split(":", $str);
|
||||
if ($host[0]) $str = "host=$host[0]";
|
||||
else $str = 'localhost';
|
||||
if (isset($host[1])) $str .= " port=$host[1]";
|
||||
}
|
||||
if ($user) $str .= " user=".$user;
|
||||
if ($pwd) $str .= " password=".$pwd;
|
||||
if ($db) $str .= " dbname=".$db;
|
||||
}//print $str;
|
||||
$this->_connectionID = pg_pconnect($str);
|
||||
if ($this->_connectionID === false) return false;
|
||||
$this->Execute("set datestyle='ISO'");
|
||||
return true;
|
||||
}
|
||||
|
||||
// returns queryID or false
|
||||
function _query($sql,$inputarr)
|
||||
{
|
||||
$this->_resultid= pg_Exec($this->_connectionID,$sql);
|
||||
return $this->_resultid;
|
||||
}
|
||||
|
||||
|
||||
/* Returns: the last error message from previous database operation */
|
||||
function ErrorMsg()
|
||||
{
|
||||
if (empty($this->_connectionID)) $this->_errorMsg = @pg_errormessage();
|
||||
else $this->_errorMsg = @pg_errormessage($this->_connectionID);
|
||||
return $this->_errorMsg;
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
function _close()
|
||||
{
|
||||
if ($this->_hastrans) $this->RollbackTrans();
|
||||
@pg_close($this->_connectionID);
|
||||
$this->_resultid = false;
|
||||
$this->_connectionID = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
function ActualType($meta)
|
||||
{
|
||||
switch($meta) {
|
||||
case 'C': return 'VARCHAR';
|
||||
case 'X': return 'TEXT';
|
||||
|
||||
case 'C2': return 'VARCHAR';
|
||||
case 'X2': return 'TEXT';
|
||||
|
||||
case 'B': return 'BYTEA';
|
||||
|
||||
case 'D': return 'DATE';
|
||||
case 'T': return 'DATETIME';
|
||||
case 'L': return 'SMALLINT';
|
||||
case 'R': return 'SERIAL';
|
||||
case 'I': return 'INTEGER';
|
||||
|
||||
case 'F': return 'FLOAT8';
|
||||
case 'N': return 'NUMERIC';
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Maximum size of C field
|
||||
*/
|
||||
function CharMax()
|
||||
{
|
||||
return 1000000000; // should be 1 Gb?
|
||||
}
|
||||
|
||||
/*
|
||||
* Maximum size of X field
|
||||
*/
|
||||
function TextMax()
|
||||
{
|
||||
return 1000000000; // should be 1 Gb?
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------------------
|
||||
Class Name: Recordset
|
||||
--------------------------------------------------------------------------------------*/
|
||||
|
||||
class ADORecordSet_postgres64 extends ADORecordSet{
|
||||
|
||||
var $databaseType = "postgres64";
|
||||
var $canSeek = true;
|
||||
function ADORecordSet_postgres64($queryID)
|
||||
{
|
||||
global $ADODB_FETCH_MODE;
|
||||
|
||||
switch ($ADODB_FETCH_MODE)
|
||||
{
|
||||
case ADODB_FETCH_NUM: $this->fetchMode = PGSQL_NUM; break;
|
||||
case ADODB_FETCH_ASSOC:$this->fetchMode = PGSQL_ASSOC; break;
|
||||
default:
|
||||
case ADODB_FETCH_DEFAULT:
|
||||
case ADODB_FETCH_BOTH:$this->fetchMode = PGSQL_BOTH; break;
|
||||
}
|
||||
|
||||
$this->ADORecordSet($queryID);
|
||||
}
|
||||
|
||||
function &GetRowAssoc($upper=true)
|
||||
{
|
||||
if ($this->fetchMode == PGSQL_ASSOC && !$upper) return $rs->fields;
|
||||
return ADORecordSet::GetRowAssoc($upper);
|
||||
}
|
||||
|
||||
function _initrs()
|
||||
{
|
||||
global $ADODB_COUNTRECS;
|
||||
$this->_numOfRows = ($ADODB_COUNTRECS)? @pg_numrows($this->_queryID):-1;
|
||||
$this->_numOfFields = @pg_numfields($this->_queryID);
|
||||
}
|
||||
|
||||
/* Use associative array to get fields array */
|
||||
function Fields($colname)
|
||||
{
|
||||
if ($this->fetchMode != PGSQL_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 &FetchField($fieldOffset = 0)
|
||||
{
|
||||
$off=$fieldOffset; // offsets begin at 0
|
||||
|
||||
$o= new ADOFieldObject();
|
||||
$o->name = @pg_fieldname($this->_queryID,$off);
|
||||
$o->type = @pg_fieldtype($this->_queryID,$off);
|
||||
$o->max_length = @pg_fieldsize($this->_queryID,$off);
|
||||
//print_r($o);
|
||||
//print "off=$off name=$o->name type=$o->type len=$o->max_length<br>";
|
||||
return $o;
|
||||
}
|
||||
|
||||
function _seek($row)
|
||||
{
|
||||
return @pg_fetch_row($this->_queryID,$row);
|
||||
}
|
||||
|
||||
// 10% speedup to move MoveNext to child class
|
||||
function MoveNext()
|
||||
{
|
||||
if (!$this->EOF) {
|
||||
$this->_currentRow++;
|
||||
$this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);
|
||||
if (is_array($this->fields)) return true;
|
||||
}
|
||||
$this->EOF = true;
|
||||
return false;
|
||||
}
|
||||
function _fetch()
|
||||
{
|
||||
$this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);
|
||||
return (is_array($this->fields));
|
||||
}
|
||||
|
||||
function _close() {
|
||||
return @pg_freeresult($this->_queryID);
|
||||
}
|
||||
|
||||
function MetaType($t,$len=-1,$fieldobj=false)
|
||||
{
|
||||
switch (strtoupper($t)) {
|
||||
case 'CHAR':
|
||||
case 'CHARACTER':
|
||||
case 'VARCHAR':
|
||||
case 'NAME':
|
||||
case 'BPCHAR':
|
||||
if ($len <= $this->blobSize) return 'C';
|
||||
|
||||
case 'TEXT':
|
||||
return 'X';
|
||||
|
||||
case 'IMAGE': // user defined type
|
||||
case 'BLOB': // user defined type
|
||||
case 'BIT': // This is a bit string, not a single bit, so don't return 'L'
|
||||
case 'VARBIT':
|
||||
case 'BYTEA':
|
||||
return 'B';
|
||||
|
||||
case 'BOOL':
|
||||
case 'BOOLEAN':
|
||||
return 'L';
|
||||
|
||||
case 'DATE':
|
||||
return 'D';
|
||||
|
||||
case 'TIME':
|
||||
case 'DATETIME':
|
||||
case 'TIMESTAMP':
|
||||
return 'T';
|
||||
|
||||
case 'SMALLINT':
|
||||
case 'BIGINT':
|
||||
case 'INTEGER':
|
||||
case 'INT8':
|
||||
case 'INT4':
|
||||
case 'INT2':
|
||||
if (isset($fieldobj) &&
|
||||
empty($fieldobj->primary_key) && empty($fieldobj->unique)) return 'I';
|
||||
|
||||
case 'OID':
|
||||
case 'SERIAL':
|
||||
return 'R';
|
||||
|
||||
default:
|
||||
return 'N';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
64
lib/adodb/drivers/adodb-postgres7.inc.php
Normal file
64
lib/adodb/drivers/adodb-postgres7.inc.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 4.
|
||||
|
||||
Postgres7 support.
|
||||
28 Feb 2001: Currently indicate that we support LIMIT
|
||||
01 Dec 2001: dannym added support for default values
|
||||
*/
|
||||
|
||||
include_once(ADODB_DIR."/drivers/adodb-postgres64.inc.php");
|
||||
|
||||
class ADODB_postgres7 extends ADODB_postgres64 {
|
||||
var $databaseType = 'postgres7';
|
||||
var $hasLimit = true; // set to true for pgsql 6.5+ only. support pgsql/mysql SELECT * FROM TABLE LIMIT 10
|
||||
|
||||
function ADODB_postgres7()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// the following should be compat with postgresql 7.2,
|
||||
// which makes obsolete the LIMIT limit,offset syntax
|
||||
function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$arg3=false,$secs2cache=0)
|
||||
{
|
||||
$offsetStr = ($offset >= 0) ? " OFFSET $offset" : '';
|
||||
$limitStr = ($nrows >= 0) ? " LIMIT $nrows" : '';
|
||||
return $secs2cache ?
|
||||
$this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr,$arg3)
|
||||
:
|
||||
$this->Execute($sql."$limitStr$offsetStr",$inputarr,$arg3);
|
||||
}
|
||||
|
||||
// 10% speedup to move MoveNext to child class
|
||||
function MoveNext()
|
||||
{
|
||||
if (!$this->EOF) {
|
||||
$this->_currentRow++;
|
||||
$this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);
|
||||
if (is_array($this->fields)) return true;
|
||||
}
|
||||
$this->EOF = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------------------
|
||||
Class Name: Recordset
|
||||
--------------------------------------------------------------------------------------*/
|
||||
|
||||
class ADORecordSet_postgres7 extends ADORecordSet_postgres64{
|
||||
|
||||
var $databaseType = "postgres7";
|
||||
|
||||
function ADORecordSet_postgres7($queryID)
|
||||
{
|
||||
$this->ADORecordSet_postgres64($queryID);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
30
lib/adodb/drivers/adodb-proxy.inc.php
Normal file
30
lib/adodb/drivers/adodb-proxy.inc.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 4.
|
||||
|
||||
Synonym for csv driver.
|
||||
*/
|
||||
|
||||
if (! defined("_ADODB_PROXY_LAYER")) {
|
||||
define("_ADODB_PROXY_LAYER", 1 );
|
||||
include(ADODB_DIR."/drivers/adodb-csv.inc.php");
|
||||
|
||||
class ADODB_proxy extends ADODB_csv {
|
||||
var $databaseType = 'proxy';
|
||||
|
||||
}
|
||||
class ADORecordset_proxy extends ADORecordset_csv {
|
||||
var $databaseType = "proxy";
|
||||
|
||||
function ADORecordset_proxy($id)
|
||||
{
|
||||
$this->ADORecordset($id);
|
||||
}
|
||||
};
|
||||
} // define
|
||||
|
||||
?>
|
166
lib/adodb/drivers/adodb-sqlanywhere.inc.php
Normal file
166
lib/adodb/drivers/adodb-sqlanywhere.inc.php
Normal file
@ -0,0 +1,166 @@
|
||||
<?php
|
||||
/*
|
||||
version V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights
|
||||
reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
|
||||
21.02.2002 - Wade Johnson wade@wadejohnson.de
|
||||
Extended ODBC class for Sybase SQLAnywhere.
|
||||
1) Added support to retrieve the last row insert ID on tables with
|
||||
primary key column using autoincrement function.
|
||||
|
||||
2) Added blob support. Usage:
|
||||
a) create blob variable on db server:
|
||||
|
||||
$dbconn->create_blobvar($blobVarName);
|
||||
|
||||
b) load blob var from file. $filename must be complete path
|
||||
|
||||
$dbcon->load_blobvar_from_file($blobVarName, $filename);
|
||||
|
||||
c) Use the $blobVarName in SQL insert or update statement in the values
|
||||
clause:
|
||||
|
||||
$recordSet = $dbconn->Execute('INSERT INTO tabname (idcol, blobcol) '
|
||||
.
|
||||
'VALUES (\'test\', ' . $blobVarName . ')');
|
||||
|
||||
instead of loading blob from a file, you can also load from
|
||||
an unformatted (raw) blob variable:
|
||||
$dbcon->load_blobvar_from_var($blobVarName, $varName);
|
||||
|
||||
d) drop blob variable on db server to free up resources:
|
||||
$dbconn->drop_blobvar($blobVarName);
|
||||
|
||||
Sybase_SQLAnywhere data driver. Requires ODBC.
|
||||
|
||||
*/
|
||||
|
||||
if (!defined('_ADODB_ODBC_LAYER')) {
|
||||
include(ADODB_DIR."/drivers/adodb-odbc.inc.php");
|
||||
}
|
||||
|
||||
if (!defined('ADODB_SYBASE_SQLANYWHERE')){
|
||||
|
||||
define('ADODB_SYBASE_SQLANYWHERE',1);
|
||||
|
||||
class ADODB_sqlanywhere extends ADODB_odbc {
|
||||
var $databaseType = "sqlanywhere";
|
||||
var $hasInsertID = true;
|
||||
|
||||
function ADODB_sqlanywhere()
|
||||
{
|
||||
$this->ADODB_odbc();
|
||||
}
|
||||
|
||||
function _insertid() {
|
||||
return $this->GetOne('select @@identity');
|
||||
}
|
||||
|
||||
function create_blobvar($blobVarName) {
|
||||
$this->Execute("create variable $blobVarName long binary");
|
||||
return;
|
||||
}
|
||||
|
||||
function drop_blobvar($blobVarName) {
|
||||
$this->Execute("drop variable $blobVarName");
|
||||
return;
|
||||
}
|
||||
|
||||
function load_blobvar_from_file($blobVarName, $filename) {
|
||||
$chunk_size = 1000;
|
||||
|
||||
$fd = fopen ($filename, "rb");
|
||||
|
||||
$integer_chunks = (integer)filesize($filename) / $chunk_size;
|
||||
$modulus = filesize($filename) % $chunk_size;
|
||||
if ($modulus != 0){
|
||||
$integer_chunks += 1;
|
||||
}
|
||||
|
||||
for($loop=1;$loop<=$integer_chunks;$loop++){
|
||||
$contents = fread ($fd, $chunk_size);
|
||||
$contents = bin2hex($contents);
|
||||
|
||||
$hexstring = '';
|
||||
|
||||
for($loop2=0;$loop2<strlen($contents);$loop2+=2){
|
||||
$hexstring .= '\x' . substr($contents,$loop2,2);
|
||||
}
|
||||
|
||||
$hexstring = $this->qstr($hexstring);
|
||||
|
||||
$this->Execute("set $blobVarName = $blobVarName || " . $hexstring);
|
||||
}
|
||||
|
||||
fclose ($fd);
|
||||
return;
|
||||
}
|
||||
|
||||
function load_blobvar_from_var($blobVarName, &$varName) {
|
||||
$chunk_size = 1000;
|
||||
|
||||
$integer_chunks = (integer)strlen($varName) / $chunk_size;
|
||||
$modulus = strlen($varName) % $chunk_size;
|
||||
if ($modulus != 0){
|
||||
$integer_chunks += 1;
|
||||
}
|
||||
|
||||
for($loop=1;$loop<=$integer_chunks;$loop++){
|
||||
$contents = substr ($varName, (($loop - 1) * $chunk_size), $chunk_size);
|
||||
$contents = bin2hex($contents);
|
||||
|
||||
$hexstring = '';
|
||||
|
||||
for($loop2=0;$loop2<strlen($contents);$loop2+=2){
|
||||
$hexstring .= '\x' . substr($contents,$loop2,2);
|
||||
}
|
||||
|
||||
$hexstring = $this->qstr($hexstring);
|
||||
|
||||
$this->Execute("set $blobVarName = $blobVarName || " . $hexstring);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
Insert a null into the blob field of the table first.
|
||||
Then use UpdateBlob to store the blob.
|
||||
|
||||
Usage:
|
||||
|
||||
$conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)');
|
||||
$conn->UpdateBlob('blobtable','blobcol',$blob,'id=1');
|
||||
*/
|
||||
function UpdateBlob($table,$column,&$val,$where,$blobtype='BLOB')
|
||||
{
|
||||
$blobVarName = 'hold_blob';
|
||||
$this->create_blobvar($blobVarName);
|
||||
$this->load_blobvar_from_var($blobVarName, $val);
|
||||
$this->Execute("UPDATE $table SET $column=$blobVarName WHERE $where");
|
||||
$this->drop_blobvar($blobVarName);
|
||||
return true;
|
||||
}
|
||||
}; //class
|
||||
|
||||
class ADORecordSet_sqlanywhere extends ADORecordSet_odbc {
|
||||
|
||||
var $databaseType = "sqlanywhere";
|
||||
|
||||
function ADORecordSet_sqlanywhere($id)
|
||||
{
|
||||
$this->ADORecordSet_odbc($id);
|
||||
}
|
||||
|
||||
|
||||
}; //class
|
||||
|
||||
|
||||
} //define
|
||||
?>
|
275
lib/adodb/drivers/adodb-sybase.inc.php
Normal file
275
lib/adodb/drivers/adodb-sybase.inc.php
Normal file
@ -0,0 +1,275 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 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.
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
|
||||
Sybase driver contributed by Toni (toni.tunkkari@finebyte.com)
|
||||
|
||||
- MSSQL date patch applied.
|
||||
|
||||
Date patch by Toni 15 Feb 2002
|
||||
*/
|
||||
|
||||
class ADODB_sybase extends ADOConnection {
|
||||
var $databaseType = "sybase";
|
||||
var $replaceQuote = "''"; // string to use to replace quotes
|
||||
var $fmtDate = "'Y-m-d'";
|
||||
var $fmtTimeStamp = "'Y-m-d H:i:s'";
|
||||
var $hasInsertID = true;
|
||||
var $hasAffectedRows = true;
|
||||
var $metaTablesSQL="select name from sysobjects where type='U' or type='V'";
|
||||
var $metaColumnsSQL = "select c.name,t.name,c.length from syscolumns c join systypes t on t.xusertype=c.xusertype join sysobjects o on o.id=c.id where o.name='%s'";
|
||||
var $concat_operator = '+';
|
||||
var $sysDate = 'GetDate()';
|
||||
var $arrayClass = 'ADORecordSet_array_sybase';
|
||||
var $sysDate = 'GetDate()';
|
||||
|
||||
function ADODB_sybase()
|
||||
{
|
||||
}
|
||||
|
||||
// might require begintrans -- committrans
|
||||
function _insertid()
|
||||
{
|
||||
return $this->GetOne('select @@identity');
|
||||
}
|
||||
// might require begintrans -- committrans
|
||||
function _affectedrows()
|
||||
{
|
||||
return $this->GetOne('select @@rowcount');
|
||||
}
|
||||
|
||||
|
||||
function BeginTrans()
|
||||
{
|
||||
$this->Execute('BEGIN TRAN');
|
||||
return true;
|
||||
}
|
||||
|
||||
function CommitTrans($ok=true)
|
||||
{
|
||||
if (!$ok) return $this->RollbackTrans();
|
||||
$this->Execute('COMMIT TRAN');
|
||||
return true;
|
||||
}
|
||||
|
||||
function RollbackTrans()
|
||||
{
|
||||
$this->Execute('ROLLBACK TRAN');
|
||||
return true;
|
||||
}
|
||||
|
||||
// http://www.isug.com/Sybase_FAQ/ASE/section6.1.html#6.1.4
|
||||
function RowLock($tables,$where)
|
||||
{
|
||||
if (!$this->_hastrans) $this->BeginTrans();
|
||||
$tables = str_replace(',',' HOLDLOCK,',$tables);
|
||||
return $this->GetOne("select top 1 null as ignore from $tables HOLDLOCK where $where");
|
||||
|
||||
}
|
||||
|
||||
function SelectDB($dbName) {
|
||||
$this->databaseName = $dbName;
|
||||
if ($this->_connectionID) {
|
||||
return @sybase_select_db($dbName);
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
/* Returns: the last error message from previous database operation
|
||||
Note: This function is NOT available for Microsoft SQL Server. */
|
||||
|
||||
function ErrorMsg() {
|
||||
$this->_errorMsg = sybase_get_last_message();
|
||||
return $this->_errorMsg;
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
|
||||
{
|
||||
$this->_connectionID = sybase_connect($argHostname,$argUsername,$argPassword);
|
||||
if ($this->_connectionID === false) return false;
|
||||
if ($argDatabasename) return $this->SelectDB($argDatabasename);
|
||||
return true;
|
||||
}
|
||||
// returns true or false
|
||||
function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
|
||||
{
|
||||
$this->_connectionID = sybase_pconnect($argHostname,$argUsername,$argPassword);
|
||||
if ($this->_connectionID === false) return false;
|
||||
if ($argDatabasename) return $this->SelectDB($argDatabasename);
|
||||
return true;
|
||||
}
|
||||
|
||||
// returns query ID if successful, otherwise false
|
||||
function _query($sql,$inputarr)
|
||||
{
|
||||
//@sybase_free_result($this->_queryID);
|
||||
return sybase_query($sql,$this->_connectionID);
|
||||
}
|
||||
|
||||
// See http://www.isug.com/Sybase_FAQ/ASE/section6.2.html#6.2.12
|
||||
function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$arg3=false,$secs2cache=0)
|
||||
{
|
||||
$cnt = ($nrows > 0) ? $nrows : 0;
|
||||
if ($offset > 0 && $cnt) $cnt += $offset;
|
||||
|
||||
$this->Execute("set rowcount $cnt");
|
||||
$rs = &ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$arg3,$secs2cache);
|
||||
$this->Execute("set rowcount 0");
|
||||
|
||||
return $rs;
|
||||
}
|
||||
|
||||
// returns true or false
|
||||
function _close()
|
||||
{
|
||||
return @sybase_close($this->_connectionID);
|
||||
}
|
||||
|
||||
function UnixDate($v)
|
||||
{
|
||||
return ADORecordSet_array_sybase::UnixDate($v);
|
||||
}
|
||||
|
||||
function UnixTimeStamp($v)
|
||||
{
|
||||
return ADORecordSet_array_sybase::UnixTimeStamp($v);
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------------------
|
||||
Class Name: Recordset
|
||||
--------------------------------------------------------------------------------------*/
|
||||
global $ADODB_sybase_mths;
|
||||
$ADODB_sybase_mths = array(
|
||||
'JAN'=>1,'FEB'=>2,'MAR'=>3,'APR'=>4,'MAY'=>5,'JUN'=>6,
|
||||
'JUL'=>7,'AUG'=>8,'SEP'=>9,'OCT'=>10,'NOV'=>11,'DEC'=>12);
|
||||
|
||||
class ADORecordset_sybase extends ADORecordSet {
|
||||
|
||||
var $databaseType = "sybase";
|
||||
var $canSeek = true;
|
||||
// _mths works only in non-localised system
|
||||
var $_mths = array('JAN'=>1,'FEB'=>2,'MAR'=>3,'APR'=>4,'MAY'=>5,'JUN'=>6,'JUL'=>7,'AUG'=>8,'SEP'=>9,'OCT'=>10,'NOV'=>11,'DEC'=>12);
|
||||
|
||||
function ADORecordset_sybase($id)
|
||||
{
|
||||
global $ADODB_FETCH_MODE;
|
||||
|
||||
if (!$ADODB_FETCH_MODE) $this->fetchMode = ADODB_FETCH_ASSOC;
|
||||
else $this->fetchMode = $ADODB_FETCH_MODE;
|
||||
return $this->ADORecordSet($id);
|
||||
}
|
||||
|
||||
/* Returns: an object containing field information.
|
||||
Get column information in the Recordset object. fetchField() can be used in order to obtain information about
|
||||
fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by
|
||||
fetchField() is retrieved. */
|
||||
function &FetchField($fieldOffset = -1)
|
||||
{
|
||||
if ($fieldOffset != -1) {
|
||||
$o = @sybase_fetch_field($this->_queryID, $fieldOffset);
|
||||
}
|
||||
else if ($fieldOffset == -1) { /* The $fieldOffset argument is not provided thus its -1 */
|
||||
$o = @sybase_fetch_field($this->_queryID);
|
||||
}
|
||||
// older versions of PHP did not support type, only numeric
|
||||
if ($o && !isset($o->type)) $o->type = ($o->numeric) ? 'float' : 'varchar';
|
||||
return $o;
|
||||
}
|
||||
|
||||
function _initrs()
|
||||
{
|
||||
global $ADODB_COUNTRECS;
|
||||
$this->_numOfRows = ($ADODB_COUNTRECS)? @sybase_num_rows($this->_queryID):-1;
|
||||
$this->_numOfFields = @sybase_num_fields($this->_queryID);
|
||||
}
|
||||
|
||||
function _seek($row)
|
||||
{
|
||||
return @sybase_data_seek($this->_queryID, $row);
|
||||
}
|
||||
|
||||
function _fetch($ignore_fields=false) {
|
||||
|
||||
if ($this->fetchMode == ADODB_FETCH_NUM) $this->fields = @sybase_fetch_row($this->_queryID);
|
||||
else $this->fields = @sybase_fetch_array($this->_queryID);
|
||||
return is_array($this->fields);
|
||||
}
|
||||
|
||||
/* close() only needs to be called if you are worried about using too much memory while your script
|
||||
is running. All associated result memory for the specified result identifier will automatically be freed. */
|
||||
function _close() {
|
||||
return @sybase_free_result($this->_queryID);
|
||||
}
|
||||
|
||||
// sybase/mssql uses a default date like Dec 30 2000 12:00AM
|
||||
function UnixDate($v)
|
||||
{
|
||||
return ADORecordSet_array_sybase::UnixDate($v);
|
||||
}
|
||||
|
||||
function UnixTimeStamp($v)
|
||||
{
|
||||
return ADORecordSet_array_sybase::UnixTimeStamp($v);
|
||||
}
|
||||
}
|
||||
|
||||
class ADORecordSet_array_sybase extends ADORecordSet_array {
|
||||
function ADORecordSet_array_sybase($id=-1)
|
||||
{
|
||||
$this->ADORecordSet_array($id);
|
||||
}
|
||||
|
||||
// sybase/mssql uses a default date like Dec 30 2000 12:00AM
|
||||
function UnixDate($v)
|
||||
{
|
||||
global $ADODB_sybase_mths;
|
||||
|
||||
//Dec 30 2000 12:00AM
|
||||
if (!ereg( "([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4})"
|
||||
,$v, $rr)) return parent::UnixDate($v);
|
||||
|
||||
if ($rr[3] <= 1970) return 0;
|
||||
|
||||
$themth = substr(strtoupper($rr[1]),0,3);
|
||||
$themth = $ADODB_sybase_mths[$themth];
|
||||
if ($themth <= 0) return false;
|
||||
// h-m-s-MM-DD-YY
|
||||
return mktime(0,0,0,$themth,$rr[2],$rr[3]);
|
||||
}
|
||||
|
||||
function UnixTimeStamp($v)
|
||||
{
|
||||
global $ADODB_sybase_mths;
|
||||
//11.02.2001 Toni Tunkkari toni.tunkkari@finebyte.com
|
||||
//Changed [0-9] to [0-9 ] in day conversion
|
||||
if (!ereg( "([A-Za-z]{3})[-/\. ]([0-9 ]{1,2})[-/\. ]([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})"
|
||||
,$v, $rr)) return parent::UnixTimeStamp($v);
|
||||
if ($rr[3] <= 1970) return 0;
|
||||
|
||||
$themth = substr(strtoupper($rr[1]),0,3);
|
||||
$themth = $ADODB_sybase_mths[$themth];
|
||||
if ($themth <= 0) return false;
|
||||
|
||||
switch (strtoupper($rr[6])) {
|
||||
case 'P':
|
||||
if ($rr[4]<12) $rr[4] += 12;
|
||||
break;
|
||||
case 'A':
|
||||
if ($rr[4]==12) $rr[4] = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// h-m-s-MM-DD-YY
|
||||
return mktime($rr[4],$rr[5],0,$themth,$rr[2],$rr[3]);
|
||||
}
|
||||
}
|
||||
?>
|
89
lib/adodb/drivers/adodb-vfp.inc.php
Normal file
89
lib/adodb/drivers/adodb-vfp.inc.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Latest version is available at http://php.weblogs.com/
|
||||
|
||||
Microsoft Visual FoxPro data driver. Requires ODBC. Works only on MS Windows.
|
||||
*/
|
||||
|
||||
if (!defined('_ADODB_ODBC_LAYER')) {
|
||||
include(ADODB_DIR."/drivers/adodb-odbc.inc.php");
|
||||
}
|
||||
if (!defined('ADODB_VFP')){
|
||||
define('ADODB_VFP',1);
|
||||
class ADODB_vfp extends ADODB_odbc {
|
||||
var $databaseType = "vfp";
|
||||
var $fmtDate = "{^Y-m-d}";
|
||||
var $fmtTimeStamp = "{^Y-m-d, h:i:sA}";
|
||||
var $replaceQuote = "'+chr(39)+'" ;
|
||||
var $true = '.T.';
|
||||
var $false = '.F.';
|
||||
var $hasTop = 'top'; // support mssql SELECT TOP 10 * FROM TABLE
|
||||
var $upperCase = 'upper';
|
||||
var $_bindInputArray = false; // strangely enough, setting to true does not work reliably
|
||||
var $sysTimeStamp = 'datetime()';
|
||||
var $sysDate = 'date()';
|
||||
|
||||
function ADODB_vfp()
|
||||
{
|
||||
$this->ADODB_odbc();
|
||||
}
|
||||
|
||||
function BeginTrans() { return false;}
|
||||
|
||||
// quote string to be sent back to database
|
||||
function qstr($s,$nofixquotes=false)
|
||||
{
|
||||
if (!$nofixquotes) return "'".str_replace("\r\n","'+chr(13)+'",str_replace("'",$this->replaceQuote,$s))."'";
|
||||
return "'".$s."'";
|
||||
}
|
||||
|
||||
// TOP requires ORDER BY for VFP
|
||||
function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$arg3=false,$secs2cache=0)
|
||||
{
|
||||
if (!preg_match('/ORDER[ \t\r\n]+BY/i',$sql)) $sql .= ' ORDER BY 1';
|
||||
return ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$arg3,$secs2cache);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
class ADORecordSet_vfp extends ADORecordSet_odbc {
|
||||
|
||||
var $databaseType = "vfp";
|
||||
|
||||
|
||||
function ADORecordSet_vfp($id)
|
||||
{
|
||||
return $this->ADORecordSet_odbc($id);
|
||||
}
|
||||
|
||||
function MetaType($t,$len=-1)
|
||||
{
|
||||
switch (strtoupper($t)) {
|
||||
case 'C':
|
||||
if ($len <= $this->blobSize) return 'C';
|
||||
case 'M':
|
||||
return 'X';
|
||||
|
||||
case 'D': return 'D';
|
||||
|
||||
case 'T': return 'T';
|
||||
|
||||
case 'L': return 'L';
|
||||
|
||||
case 'I': return 'I';
|
||||
|
||||
default: return 'N';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} //define
|
||||
?>
|
161
lib/adodb/license.txt
Normal file
161
lib/adodb/license.txt
Normal file
@ -0,0 +1,161 @@
|
||||
This software is dual licensed using BSD-Style and LGPL. Where there is any discrepancy, the BSD-Style license will take precedence.
|
||||
|
||||
BSD Style-License
|
||||
=================
|
||||
|
||||
Copyright (c) 2000, 2001 John Lim
|
||||
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.
|
||||
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.
|
||||
|
||||
==========================================================
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
|
||||
Preamble
|
||||
The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run.
|
||||
|
||||
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
|
||||
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change.
|
||||
c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License.
|
||||
d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful.
|
||||
(For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things:
|
||||
|
||||
|
||||
a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.)
|
||||
b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with.
|
||||
c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution.
|
||||
d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place.
|
||||
e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy.
|
||||
For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things:
|
||||
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above.
|
||||
b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.
|
||||
8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
2217
lib/adodb/readme.htm
Normal file
2217
lib/adodb/readme.htm
Normal file
File diff suppressed because it is too large
Load Diff
59
lib/adodb/readme.txt
Normal file
59
lib/adodb/readme.txt
Normal file
@ -0,0 +1,59 @@
|
||||
>> ADODB Library for PHP4
|
||||
|
||||
(c) 2000-2002 John Lim (jlim@natsoft.com.my)
|
||||
|
||||
Released under both BSD and GNU Lesser GPL library license.
|
||||
This means you can use it in proprietary products.
|
||||
|
||||
|
||||
>> Introduction
|
||||
|
||||
PHP's database access functions are not standardised. This creates a
|
||||
need for a database class library to hide the differences between the
|
||||
different databases (encapsulate the differences) so we can easily
|
||||
switch databases.
|
||||
|
||||
We currently support MySQL, Interbase, Sybase, PostgreSQL, Oracle,
|
||||
Microsoft SQL server, Foxpro ODBC, Access ODBC, Informix, DB2 ODBC,
|
||||
Sybase SQL Anywhere, generic ODBC and Microsoft's ADO.
|
||||
|
||||
We hope more people will contribute drivers to support other databases.
|
||||
|
||||
|
||||
>> Documentation and Examples
|
||||
|
||||
Refer to readme.htm for full documentation and examples. There is also a
|
||||
tutorial tute.htm that contrasts ADODB code with mysql code.
|
||||
|
||||
|
||||
>>> Files
|
||||
Adodb.inc.php is the main file. You need to include only this file.
|
||||
|
||||
Adodb-*.inc.php are the database specific driver code.
|
||||
|
||||
Test.php contains a list of test commands to exercise the class library.
|
||||
|
||||
Adodb-session.php is the PHP4 session handling code.
|
||||
|
||||
Testdatabases.inc.php contains the list of databases to apply the tests on.
|
||||
|
||||
Benchmark.php is a simple benchmark to test the throughput of a simple SELECT
|
||||
statement for databases described in testdatabases.inc.php. The benchmark
|
||||
tables are created in test.php.
|
||||
|
||||
readme.htm is the main documentation.
|
||||
|
||||
tute.htm is the tutorial.
|
||||
|
||||
|
||||
>> More Info
|
||||
|
||||
For more information, including installation see readme.htm
|
||||
|
||||
|
||||
>> Feature Requests and Bug Reports
|
||||
|
||||
Email to jlim@natsoft.com.my
|
||||
|
||||
|
||||
|
96
lib/adodb/server.php
Normal file
96
lib/adodb/server.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* @version V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
* Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
*/
|
||||
|
||||
/* Documentation on usage is at http://php.weblogs.com/adodb_csv
|
||||
*
|
||||
* Legal query string parameters:
|
||||
*
|
||||
* sql = holds sql string
|
||||
* nrows = number of rows to return
|
||||
* offset = skip offset rows of data
|
||||
* fetch = $ADODB_FETCH_MODE
|
||||
*
|
||||
* example:
|
||||
*
|
||||
* http://localhost/php/server.php?select+*+from+table&nrows=10&offset=2
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Define the IP address you want to accept requests from
|
||||
* as a security measure. If blank we accept anyone promisciously!
|
||||
*/
|
||||
$ACCEPTIP = '';
|
||||
|
||||
/*
|
||||
* Connection parameters
|
||||
*/
|
||||
$driver = 'mysql';
|
||||
$host = 'localhost'; // DSN for odbc
|
||||
$uid = 'root';
|
||||
$pwd = '';
|
||||
$database = 'northwind';
|
||||
|
||||
/*============================ DO NOT MODIFY BELOW HERE =================================*/
|
||||
// $sep must match csv2rs() in adodb.inc.php
|
||||
$sep = ' :::: ';
|
||||
|
||||
include('./adodb.inc.php');
|
||||
include_once(ADODB_DIR.'/adodb-csvlib.inc.php');
|
||||
|
||||
function err($s)
|
||||
{
|
||||
die('**** '.$s.' ');
|
||||
}
|
||||
|
||||
// undo stupid magic quotes
|
||||
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;
|
||||
}
|
||||
|
||||
///////////////////////////////////////// DEFINITIONS
|
||||
|
||||
|
||||
$remote = $HTTP_SERVER_VARS["REMOTE_ADDR"];
|
||||
|
||||
if (empty($HTTP_GET_VARS['sql'])) err('No SQL');
|
||||
|
||||
if (!empty($ACCEPTIP))
|
||||
if ($remote != '127.0.0.1' && $remote != $ACCEPTIP)
|
||||
err("Unauthorised client: '$remote'");
|
||||
|
||||
|
||||
$conn = &ADONewConnection($driver);
|
||||
if (!$conn->Connect($host,$uid,$pwd,$database)) err($conn->ErrorNo(). $sep . $conn->ErrorMsg());
|
||||
$sql = undomq($HTTP_GET_VARS['sql']);
|
||||
|
||||
if (isset($HTTP_GET_VARS['fetch']))
|
||||
$ADODB_FETCH_MODE = $HTTP_GET_VARS['fetch'];
|
||||
|
||||
if (isset($HTTP_GET_VARS['nrows'])) {
|
||||
$nrows = $HTTP_GET_VARS['nrows'];
|
||||
$offset = isset($HTTP_GET_VARS['offset']) ? $HTTP_GET_VARS['offset'] : -1;
|
||||
$rs = $conn->SelectLimit($sql,$nrows,$offset);
|
||||
} else
|
||||
$rs = $conn->Execute($sql);
|
||||
if ($rs){
|
||||
//$rs->timeToLive = 1;
|
||||
echo rs2csv($rs,$conn,$sql);
|
||||
$rs->Close();
|
||||
} else
|
||||
err($conn->ErrorNo(). $sep .$conn->ErrorMsg());
|
||||
|
||||
?>
|
265
lib/adodb/tips_portable_sql.htm
Normal file
265
lib/adodb/tips_portable_sql.htm
Normal file
@ -0,0 +1,265 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Tips on Writing Portable SQL for Multiple Databases for PHP</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor=white>
|
||||
<table width=100% border=0><tr><td><h2>Tips on Writing Portable SQL </h2></td><td>
|
||||
<div align=right><img src="cute_icons_for_site/adodb.gif"></div></td></tr></table>
|
||||
|
||||
If you are writing an application that is used in multiple environments and
|
||||
operating systems, you need to plan to support multiple databases. This article
|
||||
is based on my experiences with multiple database systems, stretching from 4th
|
||||
Dimension in my Mac days, to the databases I currently use, which are: Oracle,
|
||||
FoxPro, Access, MS SQL Server and MySQL. Although most of the advice here applies
|
||||
to using SQL with Perl, Python and other programming languages, I will focus on PHP and how
|
||||
the <a href="http://php.weblogs.com/adodb">ADOdb</a> database abstraction library
|
||||
offers some solutions.<p></p>
|
||||
<p>Most database vendors practice product lock-in. The best or fastest way to
|
||||
do things is often implemented using proprietary extensions to SQL. This makes
|
||||
it extremely hard to write portable SQL code that performs well under all conditions.
|
||||
When the first ANSI committee got together in 1984 to standardize SQL, the database
|
||||
vendors had such different implementations that they could only agree on the
|
||||
core functionality of SQL. Many important application specific requirements
|
||||
were not standardized, and after so many years since the ANSI effort began,
|
||||
it looks as if much useful database functionality will never be standardized.
|
||||
Even though ANSI-92 SQL has codified much more, we still have to implement portability
|
||||
at the application level.</p>
|
||||
<h3><b>Selects</b></h3>
|
||||
<p>The SELECT statement has been standardized to a great degree. Nearly every
|
||||
database supports the following:</p>
|
||||
<p>SELECT [cols] FROM [tables]<br>
|
||||
[WHERE conditions]<br>
|
||||
[GROUP BY cols]<br>
|
||||
[HAVING conditions] <br>
|
||||
[ORDER BY cols]</p>
|
||||
<p>But so many useful techniques can only be implemented by using proprietary
|
||||
extensions. For example, when writing SQL to retrieve the first 10 rows for
|
||||
paging, you could write...</p>
|
||||
<table width="80%" border="1" cellspacing="0" cellpadding="0" align="center">
|
||||
<tr>
|
||||
<td><b>Database</b></td>
|
||||
<td><b>SQL Syntax</b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>DB2</td>
|
||||
<td>select * from table fetch first 10 rows only</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Informix</td>
|
||||
<td>select first 10 * from table</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Microsoft SQL Server and Access</td>
|
||||
<td>select top 10 * from table</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>MySQL and PostgreSQL</td>
|
||||
<td>select * from table limit 10</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Oracle</td>
|
||||
<td>select * from (select * from table) where rownum <= 10</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>This feature of getting a subset of data is so useful that in the PHP class
|
||||
library ADOdb, we have a SelectLimit( ) function that allows you to hide the
|
||||
implementation details within a function that will rewrite your SQL for you:</p>
|
||||
<pre>$connection->SelectLimit('select * from table', 10);
|
||||
</pre>
|
||||
<p><b>Selects: Fetch Modes</b></p>
|
||||
<p>PHP allows you to retrieve database records as arrays. You can choose to have
|
||||
the arrays indexed by field name or number. However different low-level PHP
|
||||
database drivers are inconsistent in their indexing efforts. ADOdb allows you
|
||||
to determine your prefered mode. You set this by setting the variable $ADODB_FETCH_MODE
|
||||
to either of the constants ADODB_FETCH_NUM (for numeric indexes) or ADODB_FETCH_ASSOC
|
||||
(using field names as an associative index).</p>
|
||||
<p>The default behaviour of ADOdb varies depending on the database you are using.
|
||||
For consistency, set the fetch mode to either ADODB_FETCH_NUM (for speed) or
|
||||
ADODB_FETCH_ASSOC (for convenience) at the beginning of your code. </p>
|
||||
<p><b>Selects: Counting Records</b></p>
|
||||
<p>Another problem with SELECTs is that some databases do not return the number
|
||||
of rows retrieved from a select statement. This is because the highest performance
|
||||
databases will return records to you even before the last record has been found.
|
||||
</p>
|
||||
<p>In ADOdb, RecordCount( ) returns the number of rows returned, or will emulate
|
||||
it by buffering the rows and returning the count after all rows have been returned.
|
||||
This can be disabled for performance reasons when retrieving large recordsets
|
||||
by setting the global variable $ADODB_COUNTRECS = false. This variable is checked
|
||||
every time a query is executed, so you can selectively choose which recordsets
|
||||
to count.</p>
|
||||
<p>If you prefer to set $ADODB_COUNTRECS = false, ADOdb still has the PO_RecordCount(
|
||||
) function. This will return the number of rows, or if it is not found, it will
|
||||
return an estimate using SELECT COUNT(*):</p>
|
||||
<pre>$rs = $db->Execute("select * from table where state=$state");
|
||||
$numrows = $rs->PO_RecordCount('table', "state=$state");</pre>
|
||||
<p><b>Selects: Locking</b> </p>
|
||||
<p>SELECT statements are commonly used to implement row-level locking of tables.
|
||||
Other databases such as Oracle, Interbase, PostgreSQL and MySQL with InnoDB
|
||||
do not require row-level locking because they use versioning to display data
|
||||
consistent with a specific point in time.</p>
|
||||
<p>Currently, I recommend encapsulating the row-level locking in a separate function,
|
||||
such as RowLock($table, $where):</p>
|
||||
<pre>$connection->BeginTrans( );
|
||||
$connection->RowLock($table, $where); </pre>
|
||||
<pre><font color=green># some operation</font></pre>
|
||||
<pre>if ($ok) $connection->CommitTrans( );
|
||||
else $connection->RollbackTrans( );
|
||||
</pre>
|
||||
<p><b>Selects: Outer Joins</b></p>
|
||||
<p>Not all databases support outer joins. Furthermore the syntax for outer joins
|
||||
differs dramatically between database vendors. One portable (and possibly slower)
|
||||
method of implementing outer joins is using UNION.</p>
|
||||
<p>In Microsoft SQL Server a left outer join between two tables t1 and t2 could
|
||||
look like:</p>
|
||||
<pre>SELECT t1.col1, t1.col2, t2.cola <br> FROM t1 LEFT JOIN t2 ON t1.col = t2.col</pre>
|
||||
<p>This can be emulated using:</p>
|
||||
<pre>SELECT t1.col1, t1.col2, t2.cola FROM t1, t2 <br> WHERE t1.col = t2.col
|
||||
UNION ALL
|
||||
SELECT col1, col2, null FROM t1 <br> WHERE t1.col not in (select distinct col from t2)</pre>
|
||||
<h3><b>Inserts</b> </h3>
|
||||
<p>When you create records, you need to generate unique id's for each record.
|
||||
There are two common techniques: (1) auto-incrementing columns and (2) sequences.
|
||||
</p>
|
||||
<p>Auto-incrementing columns are supported by MySQL, Sybase and Microsoft Access
|
||||
and SQL Server. However most other databases do not support this feature. So
|
||||
for portability, you have little choice but to use sequences. Sequences are
|
||||
special functions that return a unique incrementing number every time you call
|
||||
it, suitable to be used as database keys. In ADOdb, we use the GenID( ) function.
|
||||
It has takes a parameter, the sequence name. Different tables can have different
|
||||
sequences. </p>
|
||||
<pre>$id = $connection->GenID('sequence_name');<br>$connection->Execute("insert into table (id, firstname, lastname) <br> values ($id, $firstname, $lastname)");</pre>
|
||||
<p>For databases that do not support sequences natively, ADOdb emulates sequences
|
||||
by creating a table for every sequence.</p>
|
||||
<h3><b>Binding</b></h3>
|
||||
<p>Binding variables in an SQL statement is another tricky feature. Binding is
|
||||
useful because it allows pre-compilation of SQL. When inserting multiple records
|
||||
into a database in a loop, binding can offer a 50% (or greater) speedup. However
|
||||
many databases such as Access and MySQL do not support binding natively and
|
||||
there is some overhead in emulating binding. Furthermore, different databases
|
||||
(specificly Oracle!) implement binding differently. My recommendation is to
|
||||
use binding if your database queries are too slow, but make sure you are using
|
||||
a database that supports it like Oracle. </p>
|
||||
<p>ADOdb supports portable Prepare/Execute with:</p>
|
||||
<pre>$stmt = $db->Prepare('select * from customers where custid=? and state=?');
|
||||
$rs = $db->Execute($stmt, array($id,'New York'));</pre>
|
||||
<h2>DDL</h2>
|
||||
<p>There are database design tools such as ERWin or Dezign that allow you to generate
|
||||
data definition language commands such as ALTER TABLE or CREATE INDEX from Entity-Relationship
|
||||
diagrams. Other developers such as Manuel Lemos have developed portable XML
|
||||
based schemas for PHP with Metabase. I think this might suit many developers,
|
||||
but I prefer to manually define the database tables. This is because the placement
|
||||
of tables and selection of the different types of indexes has to be planned
|
||||
based on the number of hard disks and the i/o characteristics of the data. This
|
||||
can only be done manually. Here are some tuning hints:</p>
|
||||
<ul>
|
||||
<li>The most important and frequently used tables deserve to be placed on their
|
||||
own separate hard disks. </li>
|
||||
<li>Indexes and data should be kept on different hard disks. </li>
|
||||
<li>Transaction logs and rollback segments deserve their own hard disks.</li>
|
||||
<li>Be prepared to waste space. You probably need at least 5 hard disks for
|
||||
a high-performance database system:<br>
|
||||
- 1 hard disk for the operating system and temporary data, <br>
|
||||
- 1 for data,<br>
|
||||
- 1 for indexes, <br>
|
||||
- 1 for rollback, <br>
|
||||
- 1 for transaction logs.</li>
|
||||
</ul>
|
||||
<h3>Data Types</h3>
|
||||
<p>Stick to a few data types that are available in most databases. Char, varchar
|
||||
and numeric/number are supported by most databases. Most other data types (including
|
||||
integer, boolean and float) cannot be relied on being available. I recommend
|
||||
using char(1) or number(1) to hold booleans. </p>
|
||||
<p>Different databases have different ways of representing dates and timestamps/datetime.
|
||||
ADOdb attempts to display all dates in ISO (YYYY-MM-DD) format. ADOdb also provides
|
||||
DBDate( ) and DBTimeStamp( ) to convert dates to formats that are acceptable
|
||||
to that database. Both functions accept Unix integer timestamps and date strings
|
||||
in ISO format.</p>
|
||||
<pre>$date1 = $connection->DBDate(time( ));<br>$date2 = $connection->DBTimeStamp('2002-02-23 13:03:33');</pre>
|
||||
<p>We also provide functions to convert database dates to Unix timestamps:</p>
|
||||
<pre>$unixts = $recordset->UnixDate('#2002-02-30#'); <font color="green"># MS Access date => unix timestamp</font></pre>
|
||||
<p>The maximum length of a char/varchar field is also database specific. You can
|
||||
only assume that field lengths of up to 250 characters are supported. This is
|
||||
normally impractical for web based forum or content management systems. You
|
||||
will need to be familiar with how databases handle large objects (LOBs). ADOdb
|
||||
implements two functions, UpdateBlob( ) and UpdateClob( ) that allow you to
|
||||
update fields holding Binary Large Objects (eg. pictures) and Character Large
|
||||
Objects (eg. HTML articles):</p>
|
||||
<pre><font color=green># for oracle </font>
|
||||
$conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1,empty_blob())');
|
||||
$conn->UpdateBlob('blobtable','blobcol',$blobvalue,'id=1');
|
||||
|
||||
<font color=green># non-oracle databases</font>
|
||||
$conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)');
|
||||
$conn->UpdateBlob('blobtable','blobcol',$blobvalue,'id=1');
|
||||
</pre>
|
||||
<p>Null handling is another area where differences can occur. In general, I avoid
|
||||
using nulls except for dates and default all my numeric and character fields
|
||||
to 0 or the empty string. This maintains consistency with PHP, where empty strings
|
||||
and zero are treated as equivalent. However if your database has significant
|
||||
amounts of missing or unknown data, using nulls might be a good idea.
|
||||
<h3><b>Stored Procedures</b></h3>
|
||||
<p>Stored procedures are another problem area. Some databases allow recordsets
|
||||
to be returned in a stored procedure (Microsoft SQL Server and Sybase), and
|
||||
others only allow output parameters to be returned. Stored procedures sometimes
|
||||
need to be wrapped in special syntax. For example, Oracle requires such code
|
||||
to be wrapped in an anonymous block with BEGIN and END. Also internal sql functions
|
||||
such as +, ||, TRIM( ), SUBSTR( ) or INSTR( ) vary between vendors. </p>
|
||||
<p>An example of how to call a stored procedure with 2 parameters and 1 return
|
||||
value follows:</p>
|
||||
<pre> switch ($db->databaseType) {
|
||||
case '<font color="#993300">mssql</font>':
|
||||
$sql = <font color="#000000"><font color="#993333">'<font color="#993300">SP_RUNSOMETHING</font>'</font></font>; break;
|
||||
case '<font color="#993300">oci8</font>':
|
||||
$sql =
|
||||
<font color="#993300"> </font><font color="#000000"><font color="#993300">"declare RETVAL integer;begin :RETVAL := </font><font color="#000000"><font color="#993333"><font color="#993300">SP_RUNSOMETHING</font></font></font><font color="#993300">(:myid,:group);end;";
|
||||
</font> break;</font>
|
||||
default:
|
||||
die('<font color="#993300">Unsupported feature</font>');
|
||||
}
|
||||
<font color="#000000"><font color="green"> # @RETVAL = SP_RUNSOMETHING @myid,@group</font>
|
||||
$stmt = $db->PrepareSP($sql); <br> $db->Parameter($stmt,$id,'<font color="#993300">myid</font>');
|
||||
$db->Parameter($stmt,$group,'<font color="#993300">group</font>');
|
||||
<font color="green"># true indicates output parameter<br> </font>$db->Parameter($stmt,$ret,'<font color="#993300">RETVAL</font>',true);
|
||||
$db->Execute($stmt); </font></pre>
|
||||
<p>As you can see, the ADOdb API is the same for both databases. But the stored
|
||||
procedure SQL syntax is quite different between databases and is not portable,
|
||||
so be forewarned! However sometimes you have little choice as some systems only
|
||||
allow data to be accessed via stored procedures. This is when the ultimate portability
|
||||
solution might be the only solution: <i>treating portable SQL as a localization
|
||||
exercise...</i></p>
|
||||
<h3><b>SQL as a Localization Exercise</b></h3>
|
||||
<p> In general to provide real portability, you will have to treat SQL coding
|
||||
as a localization exercise. In PHP, it has become common to define separate
|
||||
language files for English, Russian, Korean, etc. Similarly, I would suggest
|
||||
you have separate Sybase, Intebase, MySQL, etc files, and conditionally include
|
||||
the SQL based on the database. For example, each MySQL SQL statement would be
|
||||
stored in a separate variable, in a file called 'mysql-lang.inc.php'.</p>
|
||||
<pre>$sqlGetPassword = '<font color="#993300">select password from users where userid=%s</font>';
|
||||
$sqlSearchKeyword = "<font color="#993300">SELECT * FROM articles WHERE match (title,body) against (%s</font>)";</pre>
|
||||
<p>In our main PHP file:</p>
|
||||
<pre><font color=green># define which database to load...</font>
|
||||
<b>$database = '<font color="#993300">mysql</font>';
|
||||
include_once("<font color="#993300">$database-lang.inc.php</font>");</b>
|
||||
|
||||
$db = NewADOConnection($database);
|
||||
$db->PConnect(...) or die('<font color="#993300">Failed to connect to database</font>');
|
||||
|
||||
<font color=green># search for a keyword $word</font>
|
||||
$rs = $db->Execute(sprintf($sqlSearchKeyWord,$db->qstr($word)));</pre>
|
||||
<p>Note that we quote the $word variable using the qstr( ) function. This is because
|
||||
each database quotes strings using different conventions.</p>
|
||||
<p>
|
||||
<h3>Final Thoughts</h3>
|
||||
<p>The best way to ensure that you have portable SQL is to have your data tables designed using
|
||||
sound principles. Learn the theory of normalization and entity-relationship diagrams and model
|
||||
your data carefully. Understand how joins and indexes work and how they are used to tune performance.
|
||||
<p> Visit the following page for more references on database theory and vendors:
|
||||
<a href="http://php.weblogs.com/sql_tutorial">http://php.weblogs.com/sql_tutorial</a>
|
||||
<p>
|
||||
<font size=1>(c) 2002 John Lim.</font>
|
||||
|
||||
</body>
|
||||
</html>
|
155
lib/adodb/tohtml.inc.php
Normal file
155
lib/adodb/tohtml.inc.php
Normal file
@ -0,0 +1,155 @@
|
||||
<?php
|
||||
/*
|
||||
V2.00 13 May 2002 (c) 2000-2002 John Lim (jlim@natsoft.com.my). All rights reserved.
|
||||
Released under both BSD license and Lesser GPL library license.
|
||||
Whenever there is any discrepancy between the two licenses,
|
||||
the BSD license will take precedence.
|
||||
|
||||
Some pretty-printing by Chris Oxenreider <oxenreid@state.net>
|
||||
*/
|
||||
|
||||
// specific code for tohtml
|
||||
GLOBAL $gSQLMaxRows,$gSQLBlockRows;
|
||||
|
||||
$gSQLMaxRows = 1000; // max no of rows to download
|
||||
$gSQLBlockRows=20; // max no of rows per table block
|
||||
|
||||
// RecordSet to HTML Table
|
||||
//------------------------------------------------------------
|
||||
// Convert a recordset to a html table. Multiple tables are generated
|
||||
// if the number of rows is > $gSQLBlockRows. This is because
|
||||
// web browsers normally require the whole table to be downloaded
|
||||
// before it can be rendered, so we break the output into several
|
||||
// smaller faster rendering tables.
|
||||
//
|
||||
// $rs: the recordset
|
||||
// $ztabhtml: the table tag attributes (optional)
|
||||
// $zheaderarray: contains the replacement strings for the headers (optional)
|
||||
//
|
||||
// USAGE:
|
||||
// include('adodb.inc.php');
|
||||
// $db = ADONewConnection('mysql');
|
||||
// $db->Connect('mysql','userid','password','database');
|
||||
// $rs = $db->Execute('select col1,col2,col3 from table');
|
||||
// rs2html($rs, 'BORDER=2', array('Title1', 'Title2', 'Title3'));
|
||||
// $rs->Close();
|
||||
//
|
||||
// RETURNS: number of rows displayed
|
||||
function rs2html(&$rs,$ztabhtml='',$zheaderarray="")
|
||||
{
|
||||
$s ='';$rows=0;$docnt = false;
|
||||
GLOBAL $gSQLMaxRows,$gSQLBlockRows;
|
||||
|
||||
if (!$rs) {
|
||||
printf(ADODB_BAD_RS,'rs2html');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $ztabhtml) $ztabhtml = "BORDER='1' WIDTH='98%'";
|
||||
//else $docnt = true;
|
||||
$typearr = array();
|
||||
$ncols = $rs->FieldCount();
|
||||
$hdr = "<TABLE COLS=$ncols $ztabhtml>\n\n";
|
||||
|
||||
for ($i=0; $i < $ncols; $i++) {
|
||||
$field = $rs->FetchField($i);
|
||||
if ($zheaderarray) $fname = $zheaderarray[$i];
|
||||
else $fname = htmlspecialchars($field->name);
|
||||
$typearr[$i] = $rs->MetaType($field->type,$field->max_length);
|
||||
//print " $field->name $field->type $typearr[$i] ";
|
||||
|
||||
if (empty($fname)) $fname = ' ';
|
||||
$hdr .= "<TH>$fname</TH>";
|
||||
}
|
||||
|
||||
print $hdr."\n\n";
|
||||
|
||||
// smart algorithm - handles ADODB_FETCH_MODE's correctly!
|
||||
$numoffset = isset($rs->fields[0]);
|
||||
while (!$rs->EOF) {
|
||||
$s .= "<TR>\n";
|
||||
|
||||
for ($i=0, $v=($numoffset) ? $rs->fields[0] : reset($rs->fields);
|
||||
$i < $ncols;
|
||||
$i++, $v = ($numoffset) ? @$rs->fields[$i] : next($rs->fields)) {
|
||||
|
||||
$type = $typearr[$i];
|
||||
switch($type) {
|
||||
case 'T':
|
||||
$s .= " <TD>".$rs->UserTimeStamp($v,"D d, M Y, h:i:s") ." </TD>\n";
|
||||
break;
|
||||
case 'D':
|
||||
$s .= " <TD>".$rs->UserDate($v,"D d, M Y") ." </TD>\n";
|
||||
break;
|
||||
case 'I':
|
||||
case 'N':
|
||||
$s .= " <TD align=right>".htmlspecialchars(trim($v)) ." </TD>\n";
|
||||
$s = stripslashes($s);
|
||||
$s = urldecode($s);
|
||||
break;
|
||||
default:
|
||||
$s .= " <TD>".htmlspecialchars(trim($v)) ." </TD>\n";
|
||||
$s = stripslashes($s);
|
||||
$s = urldecode($s);
|
||||
}
|
||||
} // for
|
||||
$s .= "</TR>\n\n";
|
||||
|
||||
$rows += 1;
|
||||
if ($rows >= $gSQLMaxRows) {
|
||||
$rows = "<p>Truncated at $gSQLMaxRows</p>";
|
||||
break;
|
||||
} // switch
|
||||
|
||||
$rs->MoveNext();
|
||||
|
||||
// additional EOF check to prevent a widow header
|
||||
if (!$rs->EOF && $rows % $gSQLBlockRows == 0) {
|
||||
|
||||
//if (connection_aborted()) break;// not needed as PHP aborts script, unlike ASP
|
||||
print $s . "</TABLE>\n\n";
|
||||
$s = $hdr;
|
||||
}
|
||||
} // while
|
||||
|
||||
print $s."</TABLE>\n\n";
|
||||
|
||||
if ($docnt) print "<H2>".$rows." Rows</H2>";
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
|
||||
function arr2html(&$arr,$ztabhtml='',$zheaderarray='')
|
||||
{
|
||||
if (!$ztabhtml) $ztabhtml = 'BORDER=1';
|
||||
|
||||
$s = "<TABLE $ztabhtml>";//';print_r($arr);
|
||||
|
||||
if ($zheaderarray) {
|
||||
$s .= '<TR>';
|
||||
for ($i=0; $i<sizeof($zheaderarray); $i++) {
|
||||
$s .= " <TD>{$zheaderarray[$i]}</TD>\n";
|
||||
}
|
||||
$s .= "\n</TR>";
|
||||
}
|
||||
|
||||
for ($i=0; $i<sizeof($arr); $i++) {
|
||||
$s .= '<TR>';
|
||||
$a = &$arr[$i];
|
||||
if (is_array($a))
|
||||
for ($j=0; $j<sizeof($a); $j++) {
|
||||
$val = $a[$j];
|
||||
if (empty($val)) $val = ' ';
|
||||
$s .= " <TD>$val</TD>\n";
|
||||
}
|
||||
else if ($a) {
|
||||
$s .= ' <TD>'.$a."</TD>\n";
|
||||
} else $s .= " <TD> </TD>\n";
|
||||
$s .= "\n</TR>\n";
|
||||
}
|
||||
$s .= '</TABLE>';
|
||||
print $s;
|
||||
}
|
||||
|
||||
|
290
lib/adodb/tute.htm
Normal file
290
lib/adodb/tute.htm
Normal file
@ -0,0 +1,290 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Tutorial: Moving from MySQL to ADODB</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Tutorial: Moving from MySQL to ADODB</h1>
|
||||
|
||||
<pre> You say eether and I say eyether,
|
||||
You say neether and I say nyther;
|
||||
Eether, eyether, neether, nyther -
|
||||
Let's call the whole thing off !
|
||||
<br>
|
||||
You like potato and I like po-tah-to,
|
||||
You like tomato and I like to-mah-to;
|
||||
Potato, po-tah-to, tomato, to-mah-to -
|
||||
Let's call the whole thing off !
|
||||
</pre>
|
||||
<p>I love this song, especially the version with Louis Armstrong and Ella singing
|
||||
duet. It is all about how hard it is for two people in love to be compatible
|
||||
with each other. It's about compromise and finding a common ground, and that's
|
||||
what this article is all about.
|
||||
<p>PHP is all about creating dynamic web-sites with the least fuss and the most
|
||||
fun. To create these websites we need to use databases to retrieve login information,
|
||||
to splash dynamic news onto the web page and store forum postings. So let's
|
||||
say we were using the popular MySQL database for this. Your company has done
|
||||
such a fantastic job that the Web site is more popular than your wildest dreams.
|
||||
You find that MySQL cannot scale to handle the workload; time to switch databases.
|
||||
<p> Unfortunately in PHP every database is accessed slightly differently. To connect
|
||||
to MySQL, you would use <i>mysql_connect()</i>; when you decide to upgrade to
|
||||
Oracle or Microsoft SQL Server, you would use <i>ocilogon() </i>or <i>mssql_connect()</i>
|
||||
respectively. What is worse is that the parameters you use for the different
|
||||
connect functions are different also.. One database says po-tato, the other
|
||||
database says pota-to. Oh-oh.
|
||||
<h3>Let's NOT call the whole thing off</h3>
|
||||
<p>A database wrapper library such as ADODB comes in handy when you need to ensure portability. It provides
|
||||
you with a common API to communicate with any supported database so you don't have to call things off. <p>
|
||||
|
||||
<p>ADODB stands for Active Data Objects DataBase (sorry computer guys are sometimes
|
||||
not very original). ADODB currently supports MySQL, PostgreSQL, Oracle, Interbase,
|
||||
Microsoft SQL Server, Access, FoxPro, Sybase, ODBC and ADO. You can download
|
||||
ADODB from <a href=http://php.weblogs.com/adodb><a href="http://php.weblogs.com/adodb">http://php.weblogs.com/adodb</a></a>.
|
||||
<h3>MySQL Example</h3>
|
||||
<p>The most common database used with PHP is MySQL, so I guess you should be familiar
|
||||
with the following code. It connects to a MySQL server at <i>localhost</i>,
|
||||
database <i>mydb</i>, and executes an SQL select statement. The results are
|
||||
printed, one line per row.
|
||||
<pre><font color="#666600">$db = <b>mysql_connect</b>("localhost", "root", "password");
|
||||
<b>mysql_select_db</b>("mydb",$db);</font>
|
||||
<font color="#660000">$result = <b>mysql_query</b>("SELECT * FROM employees",$db)</font><code><font color="#663300">;
|
||||
if ($result === false) die("failed");</font></code>
|
||||
<font color="#006666"><b>while</b> ($fields =<b> mysql_fetch_row</b>($result)) {
|
||||
<b>for</b> ($i=0, $max=sizeof($fields); $i < $max; $i++) {
|
||||
<b>print</b> $fields[$i].' ';
|
||||
}
|
||||
<b>print</b> "<br>\n";
|
||||
}</font>
|
||||
</pre>
|
||||
<p>The above code has been color-coded by section. The first section is the connection
|
||||
phase. The second is the execution of the SQL, and the last section is displaying
|
||||
the fields. The <i>while</i> loop scans the rows of the result, while the <i>for</i>
|
||||
loop scans the fields in one row.</p>
|
||||
<p>Here is the equivalent code in ADODB</p>
|
||||
<pre><b><font color="#666600"> include("adodb.inc.php");</b>
|
||||
$db = <b>NewADOConnection</b>('mysql');
|
||||
$db-><b>Connect</b>("localhost", "root", "password", "mydb");</font>
|
||||
<font color="#663300">$result = $db-><b>Execute</b>("SELECT * FROM employees");
|
||||
</font><font color="#663300"></font><code><font color="#663300">if ($result === false) die("failed")</font></code><code><font color="#663300">;</font></code>
|
||||
<font color="#006666"><b>while</b> (!$result->EOF) {
|
||||
<b>for</b> ($i=0, $max=$result-><b>FieldCount</b>(); $i < $max; $i++)
|
||||
<b>print</b> $result->fields[$i].' ';
|
||||
$result-><b>MoveNext</b>();
|
||||
<b>print</b> "<br>\n";
|
||||
}</font> </pre>
|
||||
<p></p>
|
||||
<p>Now porting to Oracle is as simple as changing the second line to <code>NewADOConnection('oracle')</code>.
|
||||
Let's walk through the code...</p>
|
||||
<h3>Connecting to the Database</h3>
|
||||
<p></p>
|
||||
<pre><b><font color="#666600">include("adodb.inc.php");</b>
|
||||
$db = <b>NewADOConnection</b>('mysql');
|
||||
$db-><b>Connect</b>("localhost", "root", "password", "mydb");</font></pre>
|
||||
<p>The connection code is a bit more sophisticated than MySQL's because our needs
|
||||
are more sophisticated. In ADODB, we use an object-oriented approach to managing
|
||||
the complexity of handling multiple databases. We have different classes to
|
||||
handle different databases. If you aren't familiar with object-oriented programing,
|
||||
don't worry -- the complexity is all hidden away in the<code> NewADOConnection()</code>
|
||||
function.</p>
|
||||
<p>To conserve memory, we only load the PHP code specific to the database you
|
||||
are connecting to. We do this by calling <code>NewADOConnection(databasedriver)</code>.
|
||||
Legal database drivers include <i>mysql, mssql, oracle, oci8, postgres, sybase,
|
||||
vfp, access, ibase </i>and many others.</p>
|
||||
<p>Then we create a new instance of the connection class by calling <code>NewADOConnection()</code>.
|
||||
Finally we connect to the database using <code>$db->Connect(). </code></p>
|
||||
<h3>Executing the SQL</h3>
|
||||
<p><code><font color="#663300">$result = $db-><b>Execute</b>("SELECT *
|
||||
FROM employees");<br>
|
||||
if ($result === false) die("failed")</font></code><code><font color="#663300">;</font></code>
|
||||
<br>
|
||||
</p>
|
||||
<p>Sending the SQL statement to the server is straight forward. Execute() will
|
||||
return a recordset object on successful execution. You should check $result
|
||||
as we do above.
|
||||
<p>An issue that confuses beginners is the fact that we have two types of objects
|
||||
in ADODB, the connection object and the recordset object. When do we use each?
|
||||
<p>The connection object ($db) is responsible for connecting to the database,
|
||||
formatting your SQL and querying the database server. The recordset object ($result)
|
||||
is responsible for retrieving the results and formatting the reply as text or
|
||||
as an array.
|
||||
<p>The only thing I need to add is that ADODB provides several helper functions
|
||||
for making INSERT and UPDATE statements easier, which we will cover in the Advanced
|
||||
section.
|
||||
<h3>Retrieving the Data<br>
|
||||
</h3>
|
||||
<pre><font color="#006666"><b>while</b> (!$result->EOF) {
|
||||
<b>for</b> ($i=0, $max=$result-><b>FieldCount</b>(); $i < $max; $i++)
|
||||
<b>print</b> $result->fields[$i].' ';
|
||||
$result-><b>MoveNext</b>();
|
||||
<b>print</b> "<br>\n";
|
||||
}</font></pre>
|
||||
<p>The paradigm for getting the data is that it's like reading a file. For every
|
||||
line, we check first whether we have reached the end-of-file (EOF). While not
|
||||
end-of-file, loop through each field in the row. Then move to the next line
|
||||
(MoveNext) and repeat.
|
||||
<p>The <code>$result->fields[]</code> array is generated by the PHP database
|
||||
extension. Some database extensions do not index the array by field name.
|
||||
To force indexing by name - that is associative arrays -
|
||||
use the $ADODB_FETCH_MODE global variable.
|
||||
<pre>
|
||||
$<b>ADODB_FETCH_MODE</b> = ADODB_FETCH_NUM;
|
||||
$rs1 = $db->Execute('select * from table');
|
||||
$<b>ADODB_FETCH_MODE</b> = ADODB_FETCH_ASSOC;
|
||||
$rs2 = $db->Execute('select * from table');
|
||||
print_r($rs1->fields); // shows <i>array([0]=>'v0',[1] =>'v1')</i>
|
||||
print_r($rs2->fields); // shows <i>array(['col1']=>'v0',['col2'] =>'v1')</i>
|
||||
</pre>
|
||||
<p>
|
||||
As you can see in the above example, both recordsets store and use different fetch modes
|
||||
based on the $ADODB_FETCH_MODE setting when the recordset was created by Execute().</p>
|
||||
<h2>ADOConnection<a name="ADOConnection"></a></h2>
|
||||
<p>Object that performs the connection to the database, executes SQL statements
|
||||
and has a set of utility functions for standardising the format of SQL statements
|
||||
for issues such as concatenation and date formats.</p>
|
||||
|
||||
<h3>Other Useful Functions</h3>
|
||||
<p><code>$recordset->Move($pos)</code> scrolls to that particular row. ADODB supports forward
|
||||
scrolling for all databases. Some databases will not support backwards scrolling.
|
||||
This is normally not a problem as you can always cache records to simulate backwards
|
||||
scrolling.
|
||||
<p><code>$recordset->RecordCount()</code> returns the number of records accessed by the
|
||||
SQL statement. Some databases will return -1 because it is not supported.
|
||||
<p><code>$recordset->GetArray()</code> returns the result as an array.
|
||||
<p><code>rs2html($recordset)</code> is a function that is generates a HTML table based on the
|
||||
$recordset passed to it. An example with the relevant lines in bold:
|
||||
<pre> include('adodb.inc.php');
|
||||
<b>include('tohtml.inc.php');</b> /* includes the rs2html function */
|
||||
$conn = &ADONewConnection('mysql');
|
||||
$conn->PConnect('localhost','userid','password','database');
|
||||
$rs = $conn->Execute('select * from table');
|
||||
<b> rs2html($rs)</b>; /* recordset to html table */ </pre>
|
||||
<p>There are many other helper functions that are listed in the documentation available at <a href="http://php.weblogs.com/adodb_manual"><a href="http://php.weblogs.com/adodb_manual">http://php.weblogs.com/adodb_manual</a></a>.
|
||||
<h2>Advanced Material</h2>
|
||||
<h3>Inserts and Updates </h3>
|
||||
<p>Let's say you want to insert the following data into a database.
|
||||
<p><b>ID</b> = 3<br>
|
||||
<b>TheDate</b>=mktime(0,0,0,8,31,2001) /* 31st August 2001 */<br>
|
||||
<b>Note</b>= sugar why don't we call it off
|
||||
<p>When you move to another database, your insert might no longer work.</p>
|
||||
<p>The first problem is that each database has a different default date format.
|
||||
MySQL expects YYYY-MM-DD format, while other databases have different defaults.
|
||||
ADODB has a function called DBDate() that addresses this issue by converting
|
||||
converting the date to the correct format.</p>
|
||||
<p>The next problem is that the <b>don't</b> in the Note needs to be quoted. In
|
||||
MySQL, we use <b>don\'t</b> but in some other databases (Sybase, Access, Microsoft
|
||||
SQL Server) we use <b>don''t. </b>The qstr() function addresses this issue.</p>
|
||||
<p>So how do we use the functions? Like this:</p>
|
||||
<pre>$sql = "INSERT INTO table (id, thedate,note) values ("
|
||||
. $<b>ID</b> . ','
|
||||
. $db->DBDate($<b>TheDate</b>) .','
|
||||
. $db->qstr($<b>Note</b>).")";
|
||||
$db->Execute($sql);</pre>
|
||||
<p>ADODB also supports <code>$connection->Affected_Rows()</code> (returns the
|
||||
number of rows affected by last update or delete) and <code>$recordset->Insert_ID()</code>
|
||||
(returns last autoincrement number generated by an insert statement). Be forewarned
|
||||
that not all databases support the two functions.<br>
|
||||
</p>
|
||||
<h3>MetaTypes</h3>
|
||||
<p>You can find out more information about each of the fields (I use the words
|
||||
fields and columns interchangebly) you are selecting by calling the recordset
|
||||
method <code>FetchField($fieldoffset)</code>. This will return an object with
|
||||
3 properties: name, type and max_length.
|
||||
<pre>For example:</pre>
|
||||
<pre>$recordset = $conn->Execute("select adate from table");<br>$f0 = $recordset->FetchField(0);
|
||||
</pre>
|
||||
<p>Then <code>$f0->name</code> will hold <i>'adata'</i>, <code>$f0->type</code>
|
||||
will be set to '<i>date'</i>. If the max_length is unknown, it will be set to
|
||||
-1.
|
||||
<p>One problem with handling different databases is that each database often calls
|
||||
the same type by a different name. For example a <i>timestamp</i> type is called
|
||||
<i>datetime</i> in one database and <i>time</i> in another. So ADODB has a special
|
||||
<code>MetaType($type, $max_length)</code> function that standardises the types
|
||||
to the following:
|
||||
<p>C: character and varchar types<br>
|
||||
X: text or long character (eg. more than 255 bytes wide).<br>
|
||||
B: blob or binary image<br>
|
||||
D: date<br>
|
||||
T: timestamp<br>
|
||||
L: logical (boolean)<br>
|
||||
I: integer<br>
|
||||
N: numeric (float, double, money)
|
||||
<p>In the above date example,
|
||||
<p><code>$recordset = $conn->Execute("select adate from table");<br>
|
||||
$f0 = $recordset->FetchField(0);<br>
|
||||
$type = $recordset->MetaType($f0->type, $f0->max_length);<br>
|
||||
print $type; /* should print 'D'</code> */
|
||||
<p>
|
||||
<p><b>Select Limit and Top Support</b>
|
||||
<p>ADODB has a function called $connection->SelectLimit($sql,$nrows,$offset) that allows
|
||||
you to retrieve a subset of the recordset. This will take advantage of native
|
||||
SELECT TOP on Microsoft products and SELECT ... LIMIT with PostgreSQL and MySQL, and
|
||||
emulated if the database does not support it.
|
||||
<p><b>Caching Support</b>
|
||||
<p>ADODB allows you to cache recordsets in your file system, and only requery the database
|
||||
server after a certain timeout period with $connection->CacheExecute($secs2cache,$sql) and
|
||||
$connection->CacheSelectLimit($secs2cache,$sql,$nrows,$offset).
|
||||
<p><b>PHP4 Session Handler Support</b>
|
||||
<p>ADODB also supports PHP4 session handlers. You can store your session variables
|
||||
in a database for true scalability using ADODB. For further information, visit
|
||||
<a href="http://php.weblogs.com/adodb-sessions"><a href="http://php.weblogs.com/adodb-sessions">http://php.weblogs.com/adodb-sessions</a></a>
|
||||
<h3>Commercial Use Encouraged</h3>
|
||||
<p>If you plan to write commercial PHP applications that you want to resell, you should consider ADODB. It has been released using the lesser GPL, which means you can legally include it in commercial applications, while keeping your code proprietary. Commercial use of ADODB is strongly encouraged! We are using it internally for this reason.<p>
|
||||
|
||||
<h2>Conclusion</h2>
|
||||
<p>As a thank you for finishing this article, here are the complete lyrics for
|
||||
<i>let's call the whole thing off</i>.<br>
|
||||
<br>
|
||||
<pre>
|
||||
Refrain
|
||||
<br>
|
||||
You say eether and I say eyether,
|
||||
You say neether and I say nyther;
|
||||
Eether, eyether, neether, nyther -
|
||||
Let's call the whole thing off !
|
||||
<br>
|
||||
You like potato and I like po-tah-to,
|
||||
You like tomato and I like to-mah-to;
|
||||
Potato, po-tah-to, tomato, to-mah-to -
|
||||
Let's call the whole thing off !
|
||||
<br>
|
||||
But oh, if we call the whole thing off, then we must part.
|
||||
And oh, if we ever part, then that might break my heart.
|
||||
<br>
|
||||
So, if you like pajamas and I like pa-jah-mas,
|
||||
I'll wear pajamas and give up pa-jah-mas.
|
||||
For we know we
|
||||
Need each other, so we
|
||||
Better call the calling off off.
|
||||
Let's call the whole thing off !
|
||||
<br>
|
||||
Second Refrain
|
||||
<br>
|
||||
You say laughter and I say lawfter,
|
||||
You say after and I say awfter;
|
||||
Laughter, lawfter, after, awfter -
|
||||
Let's call the whole thing off !
|
||||
<br>
|
||||
You like vanilla and I like vanella,
|
||||
You, sa's'parilla and I sa's'parella;
|
||||
Vanilla, vanella, choc'late, strawb'ry -
|
||||
Let's call the whole thing off !
|
||||
<br>
|
||||
But oh, if we call the whole thing off, then we must part.
|
||||
And oh, if we ever part, then that might break my heart.
|
||||
<br>
|
||||
So, if you go for oysters and I go for ersters,
|
||||
I'll order oysters and cancel the ersters.
|
||||
For we know we
|
||||
Need each other, so we
|
||||
Better call the calling off off.
|
||||
Let's call the whole thing off !
|
||||
</pre>
|
||||
<p><font size=2>Song and lyrics by George and Ira Gershwin, introduced by Fred Astaire and Ginger Rogers
|
||||
in the film "Shall We Dance?" </font><p>
|
||||
<p>
|
||||
(c)2001-2002 John Lim.
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user