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


<?php
/* OCIDefineByPos の例 thies@digicol.de (980219) */

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

$stmt = OCIParse($conn,"select empno, ename from emp");

/* the define MUST be done BEFORE ociexecute! */

OCIDefineByName($stmt,"EMPNO",&$empno);
OCIDefineByName($stmt,"ENAME",&$ename);

OCIExecute($stmt);

while (OCIFetch($stmt)) {
    echo "empno:".$empno."\n";
    echo "ename:".$ename."\n";
}

OCIFreeStatement($stmt);
OCILogoff($conn);
?>