OCIBindByName

OCIBindByName -- Bind a PHP variable to an Oracle Placeholder

Description

int OCIBindByName(int stmt, string ph_name, mixed &variable, intlength, int [type]);

OCIBindByName() binds the PHP variable variable to the Oracle placeholder ph_name. Whether it will be used for input or output will be determined run-time, and the necessary storage space will be allocated. The length paramter sets the maximum length for the bind. If you set length to -1 OCIBindByName() will use the current length of variable to set the maximum length.

If you need to bind an abstract Datatype (LOB/ROWID/BFILE) you need to allocate it first using OCINewDescriptor() function. The length is not used for abstract Datatypes and should be set to -1. The type variable tells oracle, what kind of descriptor we want to use. Possible values are: OCI_B_FILE (Binary-File), OCI_B_CFILE (Character-File), OCI_B_CLOB (Character-LOB), OCI_B_BLOB (Binary-LOB) and OCI_B_ROWID (ROWID).

Example 1. OCIDefineByName

  1 
  2 <?php
  3 /* OCIBindByPos example thies@digicol.de (980221)
  4 
  5   inserts 3 resords into emp, and uses the ROWID for updating the 
  6   records just after the insert.
  7 */
  8 
  9 $conn = OCILogon("scott","tiger");
 10 
 11 $stmt = OCIParse($conn,"insert into emp (empno, ename) ".
 12 					   "values (:empno,:ename) ".
 13 					   "returning ROWID into :rid");
 14 
 15 $data = array(1111 => "Larry", 2222 => "Bill", 3333 => "Jim");
 16 
 17 $rowid = OCINewDescriptor($conn,OCI_D_ROWID);
 18 
 19 OCIBindByName($stmt,":empno",&$empno,32);
 20 OCIBindByName($stmt,":ename",&$ename,32);
 21 OCIBindByName($stmt,":rid",&$rowid,-1,OCI_B_ROWID);
 22 
 23 $update = OCIParse($conn,"update emp set sal = :sal where ROWID = :rid");
 24 OCIBindByName($update,":rid",&$rowid,-1,OCI_B_ROWID);
 25 OCIBindByName($update,":sal",&$sal,32);
 26 
 27 $sal = 10000;
 28 
 29 while (list($empno,$ename) = each($data)) {
 30 	OCIExecute($stmt);
 31 	OCIExecute($update);
 32 } 
 33 
 34 $rowid->free();
 35 
 36 OCIFreeStatement($update);
 37 OCIFreeStatement($stmt);
 38 
 39 $stmt = OCIParse($conn,"select * from emp where empno in (1111,2222,3333)");
 40 OCIExecute($stmt);
 41 while (OCIFetchInto($stmt,&$arr,OCI_ASSOC)) {
 42 	var_dump($arr);
 43 }
 44 OCIFreeStatement($stmt);
 45 
 46 /* delete our "junk" from the emp table.... */
 47 $stmt = OCIParse($conn,"delete from emp where empno in (1111,2222,3333)");
 48 OCIExecute($stmt);
 49 OCIFreeStatement($stmt);
 50 
 51 OCILogoff($conn);
 52 ?>