OCINewDescriptor

OCINewDescriptor -- Initialize a new empty descriptor LOB/FILE (LOB is default)

Description

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

OCINewDescriptor() Allocates storage to hold descriptors or LOB locators. Valid values for the valid type are OCI_D_FILE, OCI_D_LOB, OCI_D_ROWID. For LOB desriptors, the methods load, save, and savefile are associated with the descriptor, for BFILE only the load method exists. See the second example usage hints.

Example 1. OCINewDescriptor

  1 
  2 <?php   
  3     /* This script is designed to be called from a HTML form.
  4      * It expects $user, $password, $table, $where, and $commitsize
  5      * to be passed in from the form.  The script then deletes
  6      * the selected rows using the ROWID and commits after each
  7      * set of $commitsize rows. (Use with care, there is no rollback)
  8      */
  9     $conn = OCILogon($user, $password);
 10     $stmt = OCIParse($conn,"select rowid from $table $where");
 11     $rowid = OCINewDescriptor($conn,OCI_D_ROWID);
 12     OCIDefineByName($stmt,"ROWID",&$rowid);   
 13     OCIExecute($stmt);
 14     while ( OCIFetch($stmt) ) {      
 15        $nrows = OCIRowCount($stmt);
 16        $delete = OCIParse($conn,"delete from $table where ROWID = :rid");
 17        OCIBindByName($delete,":rid",&$rowid,-1,OCI_B_ROWID);
 18        OCIExecute($delete);      
 19        print "$nrows\n";
 20        if ( ($nrows % $commitsize) == 0 ) {
 21            OCICommit($conn);      
 22        }   
 23     }
 24     $nrows = OCIRowCount($stmt);   
 25     print "$nrows deleted...\n";
 26     OCIFreeStatement($stmt);  
 27     OCILogoff($conn);
 28 ?>  
 29    
  1 
  2 <?php
  3     /* This script demonstrates file upload to LOB columns
  4      * The formfield used for this example looks like this
  5      * <form action="upload.php3" method="post" enctype="multipart/form-data">
  6      * <input type="file" name="lob_upload">
  7      * ...
  8      */
  9   if(!isset($lob_upload) || $lob_upload == 'none'){
 10 ?>
 11 <form action="upload.php3" method="post" enctype="multipart/form-data">
 12 Upload file: <input type="file" name="lob_upload"><br>
 13 <input type="submit" value="Upload"> - <input type="reset">
 14 </form>
 15 <?php
 16   } else {
 17      // $lob_upload contains the temporary filename of the uploaded file
 18      $conn = OCILogon($user, $password);
 19      $lob = OCINewDescriptor($conn, OCI_D_LOB);
 20      $stmt = OCIParse($conn,"insert into $table (id, the_blob) values(my_seq.NEXTVAL, EMPTY_BLOB()) returning the_blob into :the_blob");
 21      OCIBindByName($stmt, ':the_blob', &$lob, -1, OCI_B_BLOB);
 22      OCIExecute($stmt);
 23      if($lob->savefile($lob_upload)){
 24         OCICommit($conn);
 25         echo "Blob successfully uploaded\n";
 26      }else{
 27         echo "Couldn't upload Blob\n";
 28      }
 29      OCIFreeDescriptor($lob);
 30      OCIFreeStatement($stmt);
 31      OCILogoff($conn);
 32   }
 33 ?>
 34