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;
}
}
?>