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


<?php
    /* このスクリプトは HTML フォームからコールされる前提で作成
     * されており、$user, $passwor, $table, $where, $commitsize
     * がフォームから渡されることを前提にしています。
     * このスクリプトは、ROWID を用いて選択された行を削除し、
     * $commitsize 行毎にコミットします。
     * (ロールバックがないので、注意して使用してください。)
     */
    $conn = OCILogon($user, $password);
    $stmt = OCIParse($conn,"select rowid from $table $where");
    $rowid = OCINewDescriptor($conn,OCI_D_ROWID);
    OCIDefineByName($stmt,"ROWID",&$rowid);   
    OCIExecute($stmt);
    while ( OCIFetch($stmt) ) {      
       $nrows = OCIRowCount($stmt);
       $delete = OCIParse($conn,"delete from $table where ROWID = :rid");
       OCIBindByName($delete,":rid",&$rowid,-1,OCI_B_ROWID);
       OCIExecute($delete);      
       print "$nrows\n";
       if ( ($nrows % $commitsize) == 0 ) {
           OCICommit($conn);      
       }   
    }
    $nrows = OCIRowCount($stmt);   
    print "$nrows deleted...\n";
    OCIFreeStatement($stmt);  
    OCILogoff($conn);
?>  
   

<?php
    /* このスクリプトやLOB カラムにファイルをアップロードする例を示します。
     * LOBカラムにアップロードを行うこの例に関するフォームは、
     * <input type="file" name="lob_upload"> 
     * ... のようなものが使用されます。
     */
  if(!isset($lob_upload) || $lob_upload == 'none'){
?>
<form action="upload.php3" method="post" enctype="multipart/form-data">
Upload file: <input type="file" name="lob_upload"><br>
<input type="submit" value="Upload"> - <input type="reset">
</form>
<?php
  } else {
     // $lob_upload はアップロードファイルのテンポラリファイル名を有しています
     $conn = OCILogon($user, $password);
     $lob = OCINewDescriptor($conn, OCI_D_LOB);
     $stmt = OCIParse($conn,"insert into $table (id, the_blob) values(my_seq.NEXTVAL, EMPTY_BLOB()) returning the_blob into :the_blob");
     OCIBindByName($stmt, ':the_blob', &$lob, -1, OCI_B_BLOB);
     OCIExecute($stmt);
     if($lob->savefile($lob_upload)){
        OCICommit($conn);
        echo "Blob のアップロードは成功しました\n";
     }else{
        echo "Blob をアップロードできませんでした\n";
     }
     OCIFreeDescriptor($lob);
     OCIFreeStatement($stmt);
     OCILogoff($conn);
  }
?>