首頁 > 後端開發 > php教程 > 操作Oracle的php類別_PHP教程

操作Oracle的php類別_PHP教程

WBOY
發布: 2016-07-21 16:06:46
原創
832 人瀏覽過


//【警告】:未經許可請勿隨便修改
//--------------------------- -------------------------------------------------- -------------
//-------------------------------- -------------------------------------------------- --------
//   
// 【檔案名稱】:                c_ora_db.inc // 【作  者】:天灰
//  
// 【最後修改日期】:       2001/05/11[cxx]      
// 【定義規則]      Sharp ,'N_'=數字型,'L_'=布林型,'A_'=陣列型
//------------------------ -------------------------------------------------- ----------------
//----------------------------- -------------------------------------------------- -----------
//    ※db_logon()                    開啟數據庫連接     
//    ※db_query()                    通用select             
//    ※db_change()                    數據庫改變的通用函數(insert ,delete,update)
//    ※db_insert()                                 delete,直接呼叫db_change()
//    ※db_update()     db_change()                 
//    ※db_commit()      ※db_rollback()                         開資料庫連線
//------ -------------------------------------------------- ----------------------------------


Class c_ora_db
{

     
//---------------------------------------- --------------------------------------------------
//        變數定義
//-------------------------------------- -------------------------------------------------- --
    var $C_user          = "";                       //資料庫口令
    var $C_db              var $ I_linkID        = 0;                                                   //使用「句柄
              //全域色彩
//------------------------------------------------ ------------------------------------------



//-------------------------------------------- ----------------------------------------------
/ /        函數名稱:db_logon()
//        作  使用:開啟資料庫連線
//   柄(整數)
//        備  附註:無
//-------------------------------------------- ----------------------------------------------
    function db_logon()    
    {    
        $this->I_linkID =  .  if ($this->I_linkID == 0){AlertExit('資料庫連結失敗,請聯絡DBA!');}
        return  $this->I_linkID;     }
       
//----------- -------------------------------------------------- -----------------------------
//        函數名稱:db_query($C_sql,$A_define="",$I_start =-1,$I_end=-1)
//        作  使用: lect 🎜>//          
//                $A_define               陣列型         
//                $I_start                  $I_end                    備  註:透過數字0,1,2....可存取對應欄位的值; 或透過查詢欄位名稱也可存取對應欄位的值
//                如透過$A_rs[0][0]或$ A_rs[0]['NAME']或$A_rs[0]['name']都可存取首筆記錄NAME欄位
//                $I_start,$I_end是配合分頁所使用的參數。
//--------------------------------------------- ----------------------------------------------
    function  db_query ($C_sql,$A_define="",$I_start=-1,$I_end=-1)
    {    
       if (!$C_){AlertExitsql("/全!

       //連接偵測
       if ($this->I_linkID == 0){AlertExit('資料庫連結失敗,請與DBA聯絡!');偵測
       $this -> I_stmtID = OCIParse($this -> I_linkID,$C_sql);     
    請聯絡程式設計師');}

       //如果沒有指定綁定的字段,則從SQL語句中去取
       >            $A_Cur = explode("select",$C_sql);
                $A_define = explode(",",$A_Cur[0] );
       }

           //綁定資料庫表欄位
     //查詢列是陣列
        {
            for( $i=0;$i            {
             //大寫並去除空格
            }
            for($i=0;$i I_stmtID,"$A_define_up[$i]", &$$A_define[$i]);    //綁定
            }
                     //查詢列只有一個
        {
$A_define_up = trim(strtoupper($A_define));
            OCIDefineByName($this -> I_stmtID,》 🎜>        //執行綁定良好的SQL語句
        if(!OCIExecute($this -> I_stmtID))
        { $C_sql
";
            return false;
       

        $lower = 0;                                   地🎜>        while (OCIFetchInto($this -> I_stmtID,&$cur,OCI_ASSOC))
                   if ($I_start == -1)
            {
                if (gettype($A_define) == "array")         >                    for ($i=0;$i                    {
             i])
                        {為
     ine[$i] = $cur[$A_define_up[$i ];     
                        )                      //用大寫存取
}         
                }
                elseif (trim($A_define) "")            //查詢列只有一個
                {

                    if ($cur[$A_define_up] $$A_define)
                    {
              
                    }
                    $A_rs[$lower][0] = $$A_define                     $A_rs[$lower][$A_define] = $$A_define;        $A_rs [$lower][$A_define_up] = $$A_define;    //使用大量存取
                         //下標加一
            }

      }

    (配合分頁使用)
            if ($I_start -1)
           $I_start)
                {
                    if ($I_end - $I_start 0)
                    {
                                  if (gettype($A_define) ==array       {
                           i                                                if ($cur[$A_define_up[$i]] $$                  {
                  [$i] = $cur[$A_define_up[$i]];     
                   
                                            //使用數位存取
                     = $$A_define[$ i];        //使用重點使用
                      i]] = $$A_define[$i];    //使用大寫存取
                                        }elseif( trim($A_define) "")
                                       if ($cur[$A_define_up] $$A_define)
                                               🎜>                                          $A_rs[$lower][0] = $$A_define;                                  $A_rs[$lower][$A_define] = $$A_define;        //使用重點使用
                                               
                               $lower ;
                    
                        break;        ///「若$ I_end-$I_start=0  表示有記錄並跳出while循環
                   else
                {
             
                }                      }     //while的結束

        //釋放句柄並回傳查詢資料(一個二維數組)
        OCIFreestatement($this -> I_stmtID);
       🎜>//-- -------------------------------------------------- --------------------------------------


//- -------------------------------------------------- ---------------------------------------
//        函數名稱:db_change($ C_sql,$A_bind)
//        作  使用:db change
//            sql語句
//                $A_bind           數組型         
//        返回值:布林值
//        -------------------------------------------------- ---------------------
    function db_change($C_sql,$A_bind="")
    {
        if (!$C_sql){ AlertExit("參數不全!");}//檢查參數

        //連線偵測
        稍後再連接!       if (!$this -> I_stmtID){AlertExit(' sql格式出錯!請聯絡程式設計師');}

        //綁定
        if(gettype($A_bind       for($i=0;$ i            {
                   $$A_bind[$i] = StripSlashes($$A_bind[$i]);            / /去掉反斜線字元
                $$A_bind[$i] = str_replace("","            for($i=0;$i        $$A_bind[$i ], -1);  //綁定
            }
        }      A_bind;
            $$A_bind = StripSlashes($$A_bind);
                   //濾除PHP標示
            OCIBindByName ($this -> I_stmtID, ":$arrBind", &$$A_bind, -1);                 
          
   🎜>        if(!OCIExecute($this - > I_stmtID,OCI_DEFAULT))
        {
            echo "執行出錯
";
            return false;
        }
        $I_changenum = OCINumrows($this - > I_stmtID);*/

        //釋放句柄,傳回值
        OCIFreement($this -> I_stc>  }
//--------------------------------------------- ---------------------------------------------


//-------------------------------------------- ----------------------------------------------
/ /        函數名稱:db_delete($C_sql)
//        作  使用:delete //        所傳值:布林值
//        備為了使用直覺,本質呼叫db_change()
//------------------------------------ -------------------------------------------------- ----
    function db_delete($C_sql)
    {
        return $this -> db_change($C_--);; -------------------------------------------------- ------------------------------


//--------- -------------------------------------------------- -------------------------------
//        函式名稱:db_insert($C_sql,A_bind)
/ /        作  用:insert
//        參  數:C_sql                    sql語句
//                A_bind                    綁定
//        返回值:布爾值
//        備  注:該函數只是為了使用直觀,本質呼叫db_change()
//----------------------------------------- -------------------------------------------------
    function db_insert($C_sql,$A_bind="")
    {
        return $ -------------------------------------------------- ----------------------------------


//----- -------------------------------------------------- -----------------------------------
//        函數名稱:db_update($C_sql,A_bind)
//        作  使用:以上圖
//                         A_bind                    備  註:此函數只是為了使用直覺,本質呼叫db_change()
//------------------------------------- -------------------------------------------------- ---
    function db_update($C_sql,$A_bind="")
    {
        return $this -> db_change($C_sql,$A_bind);
    }
//-- -------------------------------------------------- --------------------------------------



//------------------------------------------------ ------------------------------------------
//        函數名稱: db_commit()
//          用:事務提交
//        參    備  註:無
//---- -------------------------------------------------- --------------------------------------     
    function db_commit()
    {
return    (OCICommit($this->I_linkID));
    }
//--------------------------------------------- ---------------------------------------------


//-------------------------------------------- ----------------------------------------------
/ /        函數名稱:db_rollback()
//        作  使用:事務回退
//   值
//        備  附註:無
/ /------------------------------------------------- ------------------------------------------     
    function db_rollback()
    {
        return  (OCIRollback($this->I_linkID));
    }    
    }   -------------------------------------------------- ----------------

     
//----------------------- -------------------------------------------------- -----------------
//        術語名稱:db_logoff()
//          使用:斷開資料庫連線🎜>//        返回值:布林值
//        備  注:無
//--------------------------- -------------------------------------------------- -------------     
    function db_logoff()
    {
       -------------------------------------------------- --------------------------------------

     
//- -------------------------------------------------- ---------------------------------------
}
?> 



http://www.bkjia.com/PHPjc/315288.html

www.bkjia.com

truehttp: //www.bkjia.com/PHPjc/315288.htmlTechArticle? //【警告】:未經許可請勿隨便修改//-------- -------------------------------------------------- -------------------------------- //---------------- ----------------------...
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板