OCINewDescriptor

OCINewDescriptor -- 空の新規ディスクリプタ LOB/FILE (LOB がデフォル) を初期化する

説明

string OCINewDescriptor(int connection, int [type]);

OCINewDescriptor() は、固定したディスクリプタまたは LOB ロケータに記憶領域を確保します。 type で指定可能な値は、OCI_D_FILE, OCI_D_LOB, OCI_D_ROWID です。 LOB ディスクリプタの場合、メソッド load, save, savefile がディスクリプタに 関連付けられています。BFILE の場合、load メソッドのみが存在します。2番目の 例に使用の際のヒントを示します。

例 1. OCINewDescriptor

  1 
  2 <?php
  3     /* このスクリプトは HTML フォームからコールされる前提で作成
  4      * されており、$user, $passwor, $table, $where, $commitsize
  5      * がフォームから渡されることを前提にしています。
  6      * このスクリプトは、ROWID を用いて選択された行を削除し、
  7      * $commitsize 行毎にコミットします。
  8      * (ロールバックがないので、注意して使用してください。)
  9      */
 10     $conn = OCILogon($user, $password);
 11     $stmt = OCIParse($conn,"select rowid from $table $where");
 12     $rowid = OCINewDescriptor($conn,OCI_D_ROWID);
 13     OCIDefineByName($stmt,"ROWID",&$rowid);   
 14     OCIExecute($stmt);
 15     while ( OCIFetch($stmt) ) {      
 16        $nrows = OCIRowCount($stmt);
 17        $delete = OCIParse($conn,"delete from $table where ROWID = :rid");
 18        OCIBindByName($delete,":rid",&$rowid,-1,OCI_B_ROWID);
 19        OCIExecute($delete);      
 20        print "$nrows\n";
 21        if ( ($nrows % $commitsize) == 0 ) {
 22            OCICommit($conn);      
 23        }   
 24     }
 25     $nrows = OCIRowCount($stmt);   
 26     print "$nrows deleted...\n";
 27     OCIFreeStatement($stmt);  
 28     OCILogoff($conn);
 29 ?>  
 30    
  1 
  2 <?php
  3     /* このスクリプトやLOB カラムにファイルをアップロードする例を示します。
  4      * LOBカラムにアップロードを行うこの例に関するフォームは、
  5      * <input type="file" name="lob_upload"> 
  6      * ... のようなものが使用されます。
  7      */
  8   if(!isset($lob_upload) || $lob_upload == 'none'){
  9 ?>
 10 <form action="upload.php3" method="post" enctype="multipart/form-data">
 11 Upload file: <input type="file" name="lob_upload"><br>
 12 <input type="submit" value="Upload"> - <input type="reset">
 13 </form>
 14 <?php
 15   } else {
 16      // $lob_upload はアップロードファイルのテンポラリファイル名を有しています
 17      $conn = OCILogon($user, $password);
 18      $lob = OCINewDescriptor($conn, OCI_D_LOB);
 19      $stmt = OCIParse($conn,"insert into $table (id, the_blob) values(my_seq.NEXTVAL, EMPTY_BLOB()) returning the_blob into :the_blob");
 20      OCIBindByName($stmt, ':the_blob', &$lob, -1, OCI_B_BLOB);
 21      OCIExecute($stmt);
 22      if($lob->savefile($lob_upload)){
 23         OCICommit($conn);
 24         echo "Blob のアップロードは成功しました\n";
 25      }else{
 26         echo "Blob をアップロードできませんでした\n";
 27      }
 28      OCIFreeDescriptor($lob);
 29      OCIFreeStatement($stmt);
 30      OCILogoff($conn);
 31   }
 32 ?>
 33