Forum und email

OCIDefineByName

(PHP 4, PHP 5, PECL oci8:1.0-1.2.4)

OCIDefineByName — 한 SELECT 구문사용시 정의단계(define-step)를 위한 PHP 변수를 할당한다.

Description

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

OCIDefineByName()함수는 페치(fetch)한 컬럼을 사용자정의 PHP변수 에 할당한다. 물론, 오라클 유저는 select 구문에서 소문자 컬럼명을 쓸수 있지만, OCIDefineByName()함수의 Column-Name 인수는 반드시 대문자로 적어야 한다. select 구문에서 존재하지도 않는 변수를 선언해도, 에러는 발생하지않을것이다!

추상 데이터타입(LOB/ROWID/BFILE)을 다룰 때는 OCINewDescriptor()함수를 사용하여 그 컬럼에 대한 변수영역을 미리 할당해야 한다. OCIBindByName()를 보시오.

Example#1 OCIDefineByName

<?php
/* OCIDefineByPos example [email protected] (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);
?>