ocinewdescriptor

(PHP 3>= 3.0.7, PHP 4 )

ocinewdescriptor -- Initialise un nouveau pointeur vide de LOB/FILE

Description

string ocinewdescriptor ( int connection [, int type])

ocinewdescriptor() alloue l'espace nécessaire pour stocker un descripteur, ou un pointeur de LOB. Les valeurs acceptées pour type sont OCI_D_FILE, OCI_D_LOB et OCI_D_ROWID. Pour les pointeurs de LOB, les méthodes load, save, et savefile sont associées avec le pointeur. Pour les pointeurs de type BFILE, seule la méthode load existe. Voyez le second exemple pour une illustration.

Exemple 1. ocinewdescriptor

<?php   
    /* Ce script est fait pour &ecirc;tre appel&eacute; dans un formulaire HTML
     * Il attends les variables $user, $password, $table, $where, et $commitsize
     * Le script efface alors les lignes s&eacute;lectionn&eacute;es avec ROWID et valide
     * l'effacement apr&egrave;s chaque groupe de $commitsize lignes.
     * (Utilisez avec prudence, car il n'y a pas d'annulation possible).
     */
    $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
    /* Ce script est fait pour &ecirc;tre appel&eacute; depuis un formulaire HTML.
     * Il attends les variables $user, $password, $table, $where, et $commitsize,
     * donn&eacute;es par le formulaire. Le script efface
     * les lignes s&eacute;lectionn&eacute;es avec ROWID est valide les transactions
     * &agrave; chaque jeu de $commitsize lignes. (Attention : il n'y plus d'annulation) */
  if(!isset($lob_upload) || $lob_upload == 'none'){
?>
<form action="upload.php" method="post" enctype="multipart/form-data">
Fichier &agrave; t&eacute;l&eacute;charger : <input type="file" name="lob_upload"><br>
<input type="submit" value="Envoyer"> - <input type="reset">
</form>
<?php
  } else {

     // $lob_upload contains the temporary filename of the uploaded file

     // see also the features section on file upload,
     // if you would like to use secure uploads
     
     $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, OCI_DEFAULT);
     if($lob->savefile($lob_upload)){
        OCICommit($conn);
        echo "Blob successfully uploaded\n";
     }else{
        echo "Couldn't upload Blob\n";
     }
     OCIFreeDesc($lob);
     OCIFreeStatement($stmt);
     OCILogoff($conn);
  }
?>

Exemple 2. Exemple avec ocinewdescriptor()

<?php   
    /* Appel d'une proc&eacute;dure PL/SQL stock&eacute;e qui prend un clobs
     * en entr&eacute;e (PHP 4 >= 4.0.6). 
     * Exemple de signateure de proc&eacute;dure stock&eacute;e PL/SQL :
     *
     * PROCEDURE save_data
     *   Nom de l'argument              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);
?>