OCIDefineByName

OCIDefineByName -- SELECT 実行中、定義用の PHP 変数を使用する

説明

int OCIDefineByName(int stmt, string Column-Name, mixed &variable, int [type]);

OCIDefineByName() は、SQL カラムを ユーザー定義の PHP 変数に取得します。 Oracle は、全ての大文字のカラム名を使用しますが、 select の中で小文字も書くことが可能であることに注意して下さい。 OCIDefineByName() は、 the Column-Name が大文字であることを仮定します。 select 文にない変数を定義する場合は、エラーは発生しないでしょう!

抽象 Datatype (LOB/ROWID/BFILE) を定義する必要がある場合、 まず OCINewDescriptor() 関数を用いてその 領域を確保する必要があります。 OCIBindByName() 関数も参照下さい。

例 1. OCIDefineByName

  1 
  2 <?php
  3 /* OCIDefineByPos の例 thies@digicol.de (980219) */
  4 
  5 $conn = OCILogon("scott","tiger");
  6 
  7 $stmt = OCIParse($conn,"select empno, ename from emp");
  8 
  9 /* the define MUST be done BEFORE ociexecute! */
 10 
 11 OCIDefineByName($stmt,"EMPNO",&$empno);
 12 OCIDefineByName($stmt,"ENAME",&$ename);
 13 
 14 OCIExecute($stmt);
 15 
 16 while (OCIFetch($stmt)) {
 17     echo "empno:".$empno."\n";
 18     echo "ename:".$ename."\n";
 19 }
 20 
 21 OCIFreeStatement($stmt);
 22 OCILogoff($conn);
 23 ?>