oracle database access object
时间:2007-02-17 来源:PHP爱好者
Calling example:
<?
$conn = OCILOGOn("www_cec", "webchn99", "unicorn");
#or you can just inclued file like "include("modcec_OCI_conn.PHP3");"
$newOda= new ODA($conn);
#################
#or you can use login method like this
#$newOda-=new ODA();
#$newOda->LOGOn("www","99","corn");
###############################################
$newOda->CmdString=" update test set nouse='dfs' where login_name='guoyafeng'";
if(!$newOda->Execute()) {
echo $newOda->err;
}
else
{
echo $newOda->Rows; #get the affected row number.
}
#or you can call execute like this####
/*
$newOda->Execute(" update test set nouse='dfs' where login_name='guoyafeng'");
*/
#############################
#the following demostrate the open method.
$newOda->Open("select * from test")) or die $newOda->err;
#Get data from RS
echo "count is" .$newOda->Rows;
for($i=0;$i<$newOda->Rows;$i )
for($j=0;$j<$newOda->Cols;$j )
{
echo $newOda->RS[$i][$j];
}
$newOda->LOGOff();
?>
<?
/********************************************************************************#
# File Name:ODA.PHP3 #
# Author:Guo Yafeng #
# Function: Oracle DB Access. #
# Maint History: #
# Sept 18,2000 first release. #
# #
# #
#********************************************************************************/
/********************************************************************************#
#Object interface description: #
# Properties: #
# conn Connection Object #
# err_no Error No #
# err Error Description #
# CmdString SQL Statements to execute. #
# Rows Affected Rows. #
# RS Return value array.
# Cols #
# #
# Method: #
# Open Execute the CmdString and return value #
# Execute Execute the CmdString. #
#********************************************************************************/
file://$conn = OCILOGOn("www_ce", "ceonline99", "wsgp");
// $conn = OCILOGOn("www_cec", "webchn99", "unicorn");
// if ($SERVER_NAME == "")
// $SERVER_NAME = $HTTP_HOST;
class ODA
{
function ODA($cn="") {
if($cn!="")
$this->conn=$cn;
return TRUE;
}
function LOGOn($user,$pass,$db) {
if(!($this->conn = OCILOGOn($user, $pass, $db))){
$this->err_no=106;
$this->err="Error 106: Failed to LOGOn.";
return FALSE;
};
return TRUE;
}
function Open($sql="") file://$this->CmdString
{
if($this->conn=="") {
$this->err_no=100;
$this->err="Error 100,Connection Object Required.";
return FALSE;
}
if($sql=="" and $this->CmdString=="") {
$this->err_no=101;
$this->err="Error 101,SQL Statement Required.";
return FALSE;
}
if($sql=="")
$sql=$this->CmdString;
if(!($cursor=OCIParse($this->conn,$sql))) {
$this->err_no=102;
$this->err="Server Internal Error: Failed to parse SQL Statement.";
return FALSE;
}
if(!OCIExecute($cursor)) {
$this->err_no=103;
$this->err="Server Internal Error: Failed to execute SQL Statement.";
return FALSE;
}
$this->Rows=0;
while(OCIFetchInto($cursor,$this->RS[$this->Rows])){
$this->Rows ;
}
$this->Cols=OCINumCols($cursor);
if($this->Rows==0) {
$this->err_no=104;
$this->err="Warning: No rows affectted.RS result is not available.";
}
OCIFreeStatement($cursor);
return TRUE;
}
function Execute($sql="") {
if($this->conn=="") {
$this->err_no=100;
$this->err="Error 100,Connection Object Required.";
return FALSE;
}
if($sql=="" and $this->CmdString=="") {
$this->err_no=101;
$this->err="Error 101,SQL Statement Required.";
return FALSE;
}
if($sql=="")
$sql=$this->CmdString;
if(!($cursor=OCIParse($this->conn,$sql))) {
$this->err_no=102;
$this->err="Server Internal Error: Failed to parse SQL Statement.";
return FALSE;
}
if(!OCIExecute($cursor)) {
$this->err_no=103;
$this->err="Server Internal Error: Failed to execute SQL Statement.";
return FALSE;
}
$this->Rows=OCIRowCount($cursor);
OCIFreeStatement($cursor);
return TRUE;
}
function LOGOff(){
if(!OCILOGOff($conn)){
$this->err_no=105;
$this->err="Server Internal Error: Failed to LOGOff database.";
return FALSE;
}
return TRUE;
}
}
?>
php爱好者站 http://www.phpfans.net PHP|MySQL|javascript|ajax|html.
<?
$conn = OCILOGOn("www_cec", "webchn99", "unicorn");
#or you can just inclued file like "include("modcec_OCI_conn.PHP3");"
$newOda= new ODA($conn);
#################
#or you can use login method like this
#$newOda-=new ODA();
#$newOda->LOGOn("www","99","corn");
###############################################
$newOda->CmdString=" update test set nouse='dfs' where login_name='guoyafeng'";
if(!$newOda->Execute()) {
echo $newOda->err;
}
else
{
echo $newOda->Rows; #get the affected row number.
}
#or you can call execute like this####
/*
$newOda->Execute(" update test set nouse='dfs' where login_name='guoyafeng'");
*/
#############################
#the following demostrate the open method.
$newOda->Open("select * from test")) or die $newOda->err;
#Get data from RS
echo "count is" .$newOda->Rows;
for($i=0;$i<$newOda->Rows;$i )
for($j=0;$j<$newOda->Cols;$j )
{
echo $newOda->RS[$i][$j];
}
$newOda->LOGOff();
?>
<?
/********************************************************************************#
# File Name:ODA.PHP3 #
# Author:Guo Yafeng #
# Function: Oracle DB Access. #
# Maint History: #
# Sept 18,2000 first release. #
# #
# #
#********************************************************************************/
/********************************************************************************#
#Object interface description: #
# Properties: #
# conn Connection Object #
# err_no Error No #
# err Error Description #
# CmdString SQL Statements to execute. #
# Rows Affected Rows. #
# RS Return value array.
# Cols #
# #
# Method: #
# Open Execute the CmdString and return value #
# Execute Execute the CmdString. #
#********************************************************************************/
file://$conn = OCILOGOn("www_ce", "ceonline99", "wsgp");
// $conn = OCILOGOn("www_cec", "webchn99", "unicorn");
// if ($SERVER_NAME == "")
// $SERVER_NAME = $HTTP_HOST;
class ODA
{
function ODA($cn="") {
if($cn!="")
$this->conn=$cn;
return TRUE;
}
function LOGOn($user,$pass,$db) {
if(!($this->conn = OCILOGOn($user, $pass, $db))){
$this->err_no=106;
$this->err="Error 106: Failed to LOGOn.";
return FALSE;
};
return TRUE;
}
function Open($sql="") file://$this->CmdString
{
if($this->conn=="") {
$this->err_no=100;
$this->err="Error 100,Connection Object Required.";
return FALSE;
}
if($sql=="" and $this->CmdString=="") {
$this->err_no=101;
$this->err="Error 101,SQL Statement Required.";
return FALSE;
}
if($sql=="")
$sql=$this->CmdString;
if(!($cursor=OCIParse($this->conn,$sql))) {
$this->err_no=102;
$this->err="Server Internal Error: Failed to parse SQL Statement.";
return FALSE;
}
if(!OCIExecute($cursor)) {
$this->err_no=103;
$this->err="Server Internal Error: Failed to execute SQL Statement.";
return FALSE;
}
$this->Rows=0;
while(OCIFetchInto($cursor,$this->RS[$this->Rows])){
$this->Rows ;
}
$this->Cols=OCINumCols($cursor);
if($this->Rows==0) {
$this->err_no=104;
$this->err="Warning: No rows affectted.RS result is not available.";
}
OCIFreeStatement($cursor);
return TRUE;
}
function Execute($sql="") {
if($this->conn=="") {
$this->err_no=100;
$this->err="Error 100,Connection Object Required.";
return FALSE;
}
if($sql=="" and $this->CmdString=="") {
$this->err_no=101;
$this->err="Error 101,SQL Statement Required.";
return FALSE;
}
if($sql=="")
$sql=$this->CmdString;
if(!($cursor=OCIParse($this->conn,$sql))) {
$this->err_no=102;
$this->err="Server Internal Error: Failed to parse SQL Statement.";
return FALSE;
}
if(!OCIExecute($cursor)) {
$this->err_no=103;
$this->err="Server Internal Error: Failed to execute SQL Statement.";
return FALSE;
}
$this->Rows=OCIRowCount($cursor);
OCIFreeStatement($cursor);
return TRUE;
}
function LOGOff(){
if(!OCILOGOff($conn)){
$this->err_no=105;
$this->err="Server Internal Error: Failed to LOGOff database.";
return FALSE;
}
return TRUE;
}
}
?>
php爱好者站 http://www.phpfans.net PHP|MySQL|javascript|ajax|html.
相关阅读 更多 +