首页 > php教程 > php手册 > 正文

oracle database access object

php中文网
发布: 2016-06-21 09:13:12
原创
1802人浏览过

access|object|oracle

 
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;$iRows;$i++)
   for($j=0;$jCols;$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;
  
  }
}
?>



最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号