OCIBindByName

(PHP 3>= 3.0.4, PHP 4 )

OCIBindByName --  Lega una variabile PHP ad un segnaposto Oracle

Descrizione

bool OCIBindByName ( int stmt, string ph_name, mixed & variable, int length [, int type])

ocibindbyname() collega la variabile PHP variable al segnaposto Oracle ph_name. L'utilizzo in modalitā input o output sarā determinato a run-time, e lo spazio di memoria necessario sarā allocato. Il parametro length imposta la lunghezza massima del collegamento. Se si imposta length a -1 ocibindbyname() userā l'attuale lunghezza di variable per impostare la lunghezza massima.

Se si deve collegare un Datatype astratto (LOB/ROWID/BFILE) occorre innanzitutto allocarlo usando la funzione ocinewdescriptor(). Il parametro length non č usato con i Datatypes astratti e dovrebbe essere impostato a -1. La veriabile type informa oracle sul tipo di descrittore che si vuole usare. I valori possibili sono: OCI_B_FILE (Binary-File), OCI_B_CFILE (Character-File), OCI_B_CLOB (Character-LOB), OCI_B_BLOB (Binary-LOB) e OCI_B_ROWID (ROWID).

Esempio 1. OCIDefineByName

<?php
/* OCIBindByPos example thies@thieso.net (980221)
  inserisce 3 tuple in emp, e usa ROWID per aggiornare le
  tuple subito dopo l'inserimento.
*/

$conn = OCILogon("scott","tiger");

$stmt = OCIParse($conn,"insert into emp (empno, ename) ".
					   "values (:empno,:ename) ".
					   "returning ROWID into :rid");

$data = array(1111 => "Larry", 2222 => "Bill", 3333 => "Jim");

$rowid = OCINewDescriptor($conn,OCI_D_ROWID);

OCIBindByName($stmt,":empno",&$empno,32);
OCIBindByName($stmt,":ename",&$ename,32);
OCIBindByName($stmt,":rid",&$rowid,-1,OCI_B_ROWID);

$update = OCIParse($conn,"update emp set sal = :sal where ROWID = :rid");
OCIBindByName($update,":rid",&$rowid,-1,OCI_B_ROWID);
OCIBindByName($update,":sal",&$sal,32);

$sal = 10000;

while (list($empno,$ename) = each($data)) {
	OCIExecute($stmt);
	OCIExecute($update);
} 

$rowid->free();

OCIFreeStatement($update);
OCIFreeStatement($stmt);

$stmt = OCIParse($conn,"select * from emp where empno in (1111,2222,3333)");
OCIExecute($stmt);
while (OCIFetchInto($stmt,&$arr,OCI_ASSOC)) {
	var_dump($arr);
}
OCIFreeStatement($stmt);

/* delete our "junk" from the emp table.... */
$stmt = OCIParse($conn,"delete from emp where empno in (1111,2222,3333)");
OCIExecute($stmt);
OCIFreeStatement($stmt);

OCILogoff($conn);
?>

Attenzione

Non č una buona idea utilizzare le magic quotes e ocibindbyname() simultaneamente in quanto le virgolette non sono necessarie nelle variabili e qualsiasi virgoletta agiunta automaticamente verrā scritta nel database dal momento che ocibindbyname() non č in grado di distinguere le virgolette aggiunte automaticamente da quelle intenzionali.