<?php
/******************************************************************************
Filename : clsDB.php
Author : Kevin Chang
Date/time : 2002-12-16
Purpose : Oracle 数据库连接的类
Description : Oracle 数据库连接的类
Revisions :
******************************************************************************/
/**
@内外网数据库参数不同
@上传时千万要注意指定正确的数据库参数
*/
class clsDB
{
// 类变量
//Oracle 数据库名称 外网172.16.64.81 内网 192.168.200.240
var $Database = "(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.64.240)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = test)
)
)";
var $DB_rac1_port1="1521";
var $DB_rac1_port2="1521";
var $DatabaseStandby = "(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.200.240)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = esal)
)
)";
//var $Database="esal";
//var $Database ="(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.200.240)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=esal)))";
var $ORACLE_SID = "esal"; //ORACLE SID
var $ORACLE_BASE = "/home/oracle"; //ORACLE BASE
//var $ORACLE_HOME = "/home/oracle/product/9.2.0"; //外网 //ORACLE HOME
var $ORACLE_HOME = "/home/oracle/product/9.2.0.4"; //内网 //ORACLE HOME
var $User = "cybercafe"; //Oracle 数据库用户名
var $Password = "cybercafe"; //内网 //Oracle 数据库用户密码
var $Link_ID = 0; //数据库连接标示
var $autoCommit = false; //是否自动提交,缺省为不自动提交
var $Record = array(); //数据库记录数组
var $cLob = array(); // clob类型数组
var $bLob = array(); // blob类型数组
var $Row; //结果数
var $Parse; //查询内容
var $Last_SQL;
var $Error = ""; //数据库错误内容
var $Debug = 0; //调试模式
var $sqoe = 0; //是否在执行检索时显示错误
//var $email = "jyzsql@gotogame.com.cn";
//var $email = "zhangjianhua@untx.com,dingwp@untx.com,confu@untx.com,wangdc@untx.com,wangyj@untx.com,summer@untx.com,xzhang@untx.com"; //邮件
var $email;
var $subject = "测试服务器SQL语句错误"; //主题
var $header = "";
var $content = "";
var $num_rows = -1;
var $debugSql = 0;
// 成员函数
function clsDB($flag = false)
{
// $this->email = $GLOBALS["g_WebMailGotogame"];
//die($this->Database);
if($flag == true) {
$this->connect();
}
}
function useRac1() {
}
function useRac2() {
}
function useStandby() {
$this->Database = $this->DatabaseStandby;
$this->forbidden_standby();
}
function connect()
{
if(rand(0,100)>50 )
{
$DB_rac1_port=$this->DB_rac1_port1;
}else{
$DB_rac1_port=$this->DB_rac1_port2;
}
$this->Database="(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.200.240)(PORT = ".$DB_rac1_port."))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = esal)
)
)";
// 连接数据库
if($this->Link_ID == 0) {
if($this->Debug)
{
printf("<br>Connecting to $this->Database...<br>\n");
}
putenv("ORACLE_SID=$this->ORACLE_SID");
putenv("ORACLE_BASE=$this->ORACLE_BASE");
putenv("ORACLE_HOME=$this->ORACLE_HOME");
$this->Link_ID = OCILogon("$this->User","$this->Password","$this->Database");
//$this->Link_ID = OCILogon("cybercafe","cybercafe","esal");
if (!$this->Link_ID)
{
// $this->halt("Link-ID == false "."($this->Link_ID)".$this->Database.", OCILogon failed");
$this->halt("系统繁忙,请稍后再试!");
}
if($this->Debug)
{
printf("<br>Obtained the Link_ID: $this->Link_ID<br>\n");
}
/*
$sql = "begin dbms_application_info.set_client_info('".substr($_SERVER[PHP_SELF],-64)."'); end;";
$Parse = OCIParse($this->Link_ID,$sql);
@OCIExecute($Parse,OCI_DEFAULT);
*/
$sql = "begin dbms_application_info.set_client_info(:page_addr); end;";
$Parse = OCIParse($this->Link_ID,$sql);
OCIBindByName($Parse, ":page_addr", substr($_SERVER[SERVER_NAME].$_SERVER[PHP_SELF],-64));
OCIExecute($Parse,OCI_DEFAULT);
}
}
function query($Query_String)
{
//print "<pre>\n".$Query_String."\n</pre><br>\n";
//IF($_SERVER[PHP_SELF]=="/cybercafe/buyAgentCard_OK.php") mail("wind@gotogame.com.cn","QQ",$Query_String);
$this->num_rows = -1;
// 执行查询
$this->Last_SQL = $Query_String;
$this->content = "\n\n";
// $this->content .= "HTTP_REFERER: ".$_SERVER["HTTP_REFERER"]."\n\n";
$this->connect();
$this->Parse = OCIParse($this->Link_ID,$Query_String);
if(is_resource($this->Parse)) {
if ($this->autoCommit) {
//@OCIExecute($this->Parse,OCI_COMMIT_ON_SUCCESS) or (mail($this->email,$this->subject,$this->content.implode("\n\n",OCIError($this->Parse)).implode("\n\n",$GLOBALS),$this->header) and die("SQL语句错误,如有问题,请联系天下客服!"));
@OCIExecute($this->Parse,OCI_COMMIT_ON_SUCCESS) or die($this->content.implode("\n\n",OCIError($this->Parse)));
}
else {
//print_r($Query_String);
//@OCIExecute($this->Parse,OCI_DEFAULT) or (mail($this->email,$this->
评论1
最新资源