home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / PHP / simporac.php3.txt < prev    next >
Encoding:
Text File  |  2002-05-06  |  4.3 KB  |  132 lines

  1. Simple Oracle Class 
  2.  
  3.  
  4.  
  5. <? 
  6. ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
  7. // 
  8. //    ORACLE CLASS BY ROCKTRON CHOI (highgain@unitel.co.kr) 2000,03,27 
  9. //    Digital UNIX, Apache1.3.9, PHP3.0.7 
  10. //     
  11. //    Oracle Class have only 4 function(ExecSQL, Fetch, ColumnName, Close) 
  12. //    Setting only ORACLE_UID, PRACLE_PASS  
  13. //     
  14. ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
  15.  
  16. class Oracle 
  17. {  
  18.     var $ORA_CON; 
  19.     var $ORA_DB; 
  20.     var $CON_CHECK  = FALSE; 
  21.     var $ORA_UID    =  "ORACLE_UID"; 
  22.     var $ORA_PASS   =  "ORACLE_PASS"; 
  23.     var $Error; 
  24.     var $ErrorCode; 
  25.     var $FetchCount = 0; 
  26.     var $ColumCount = 0; 
  27.  
  28.      ////////////////////////////////////////////////////////////////////////////////////////////////////////// 
  29.      // DBConnect, Pase Query, Exec Query, Setting ColumCount  
  30.     function ExecSQL($Query) 
  31.     { 
  32.         if( $this->CON_CHECK == FALSE ) 
  33.         { 
  34.              $this->ORA_CON  = ora_logon($this->ORA_UID, $this->ORA_PASS); 
  35.              $this->ORA_DB   = ora_open($this->ORA_CON); 
  36.              if( Ora_ErrorCode($this->ORA_DB) != 0 ) 
  37.              { 
  38.                  $this->Error     = Ora_Error($this->ORA_DB); 
  39.                  $this->ErrorCode = Ora_ErrorCode($this->ORA_DB); 
  40.                  return FALSE; 
  41.              } 
  42.              $this->CON_CHECK = TRUE; 
  43.         } 
  44.         ora_parse($this->ORA_DB, $Query);    
  45.         if( ora_exec($this->ORA_DB) == FALSE ) 
  46.         { 
  47.             $this->Error     = Ora_Error($this->ORA_DB); 
  48.             $this->ErrorCode = Ora_ErrorCode($this->ORA_DB); 
  49.             return FALSE; 
  50.         } 
  51.         $this->ColumCount = ora_numcols($this->ORA_DB); 
  52.         return TRUE; 
  53.     } 
  54.  
  55.      ////////////////////////////////////////////////////////////////////////////////////////////////////////// 
  56.      // Fetch Record 
  57.     function Fetch() 
  58.     { 
  59.          $i=0; 
  60.          if( !ora_fetch($this->ORA_DB) ) 
  61.          { 
  62.              $this->Error     = Ora_Error($this->ORA_DB); 
  63.              $this->ErrorCode = Ora_ErrorCode($this->ORA_DB); 
  64.              return $FALSE; 
  65.          } 
  66.  
  67.          for($i=0;$i<$this->ColumCount;$i++) 
  68.          { 
  69.               $FiledName1 = strtoupper(Ora_ColumnName($this->ORA_DB, $i)); 
  70.               $FiledName2 = strtolower(Ora_ColumnName($this->ORA_DB, $i)); 
  71.               $DATA       = ora_getcolumn($this->ORA_DB, $i); 
  72.               $RECORD[ "$FiledName1"] = $DATA; 
  73.               $RECORD[ "$FiledName2"] = $DATA; 
  74.               $RECORD[$i]            = $DATA; 
  75.          } 
  76.          return $RECORD; 
  77.     } 
  78.  
  79.      ////////////////////////////////////////////////////////////////////////////////////////////////////////// 
  80.      // return ColumnName  
  81.     function ColumnName($Count) 
  82.     { 
  83.          return Ora_ColumnName($this->ORA_DB, $Count); 
  84.     } 
  85.  
  86.      ////////////////////////////////////////////////////////////////////////////////////////////////////////// 
  87.      // Close Oracle 
  88.     function Close() 
  89.     { 
  90.         return ora_close($this->ORA_DB); 
  91.     } 
  92.  
  93. /************************************************************************************************************ 
  94.     SAMPLE CODE 
  95.     Oracle Class filename is ORACLE.INC, used by require 
  96. ************************************************************************************************************* 
  97.  
  98.     require "ORACLE.INC"; 
  99.  
  100.     $RS  = new Oracle; 
  101.     $RS2 = new Oracle; 
  102.  
  103.     $RS->ExecSQL("SELECT USERNAME, ZIPCODE, ADDR FROM USER WHERE USERID='$USERID'" AND PASSWD='$PASSWD'); 
  104.     if( ($DATA=$RS->Fetch()) == FALSE ) 
  105.     { 
  106.          $ERROR_MSG  = $RS->Error; 
  107.          $ERROR_CODE = $RS->ErrorCode; 
  108.          echo(" ($ERROR_CODE:$ERROR_MSG) "); 
  109.          exit; 
  110.     } 
  111.  
  112.     $USERNAME = $DATA["USERNAME"]; 
  113.     $ZIPCODE  = $DATA["zipcode"]; 
  114.     $ADDR     = $DATA[2]; 
  115.  
  116.     echo(" 
  117.          USERNAME: $USERNAME <BR> 
  118.          ZIPCODE : $ZIPCODE  <BR> 
  119.          ADDRESS : $ADDRESS  <BR> 
  120.     "); 
  121.  
  122.     $RS2->ExecSQL("INSERT INTO LOGIN (USERID, LOGINTIME) VALUES ('$USERID',SYSDATE)"); 
  123.     $RS2->ExecSQL("COMMIT"); 
  124.  
  125.     $RS2->Close(); 
  126.     $RS->Close(); 
  127.  
  128. *************************************************************************************************************/ 
  129.  
  130. ?>
  131.