OCINewDescriptor

(PHP 3 = 3.0.7, PHP 4 )

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番目の 例に使用の際のヒントを示します。

例 1OCINewDescriptor

 ?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", amp;$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カラムにアップロードを行うこの例に関するフォームは、
     *  form action="upload.php3" method="post"
enctype="multipart/form-data" 
     *  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";
     }
     OCIFreeDesc($lob);
     OCIFreeStatement($stmt);
     OCILogoff($conn);
  }
? 

例 2OCINewDescriptor

 ?php   
    /* Calling PL/SQL stored procedures which contain clobs as
input
     * parameters (PHP 4  = 4.0.6). 
     * Example PL/SQL stored procedure signature is:
     *
     * PROCEDURE save_data
     *   Argument Name                  Type                   
In/Out Default?
     *   ------------------------------ -----------------------
------ --------
     *   KEY                            NUMBER(38)              IN
     *   DATA                           CLOB                    IN
     *
     */

    $conn = OCILogon($user, $password);
    $stmt = OCIParse($conn, "begin save_data(:key, :data); end;");
    $clob = OCINewDescriptor($conn, OCI_D_LOB);
    OCIBindByName($stmt, ':key', $key);
    OCIBindByName($stmt, ':data', $clob, -1, OCI_B_CLOB);
    $clob- WriteTemporary($data);
    OCIExecute($stmt, OCI_DEFAULT);
    OCICommit($conn);
    $clob- close();
    $clob- free();
    OCIFreeStatement($stmt);
?