【php开源代码栏目提醒】:网学会员--在 php开源代码编辑为广大网友搜集整理了:adodb-oracle.inc.php绩等信息,祝愿广大网友取得需要的信息,参考学习。
<?php
/*
V4.21 20 Mar 2004 (c) 2000-2004 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.
*/
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';
var $connectSID = true;
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('.adodb_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('.adodb_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, $mode=0)
{
// G. Giunta 2003/08/13 - This looks danegrously suspicious: why should we want to set
// the oracle home to the host name of remote DB?
// if ($argHostname) putenv("ORACLE_HOME=$argHostname");
if($argHostname) { // code copied from version submitted for oci8 by Jorma Tuomainen <jorma.tuomainen@ppoy.fi>
if (empty($argDatabasename)) $argDatabasename = $argHostname;
else {
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 ($argDatabasename) $argUsername .= "@$argDatabasename";
//if ($argHostname) print "<p>Connect: 1st argument should be left blank for $this->databaseType</p>";
if ($mode = 1)
$this->_connectionID = ora_plogon($argUsername,$argPassword);
else
$this->_connectionID = ora_logon($argUsername,$argPass
word);
if ($this->_connectionID === false) return false;
if ($this->autoCommit) ora_commiton($this->_connectionID);
if ($this->_initdate) {
$rs = $this->_query("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD'");
if ($rs) ora_close($rs);
}
return true;
}
// returns true or false
function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
{
return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename, 1);
}
// returns query ID if successful, otherwise false
function _query($sql,$inputarr=false)
{
$curs = ora_open($this->_connectionID);
if ($curs === false) return false;
$this->_cur