Forum und email

OCIBindByName

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

OCIBindByName — 오라클 위치보유자(Placeholder)를 PHP 변수에 연계(bind)시킨다.

Description

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

OCIBindByName()함수는 PHP 변수 variable 에 오라클 위치보유자(Oracle placeholder)인 ph_name 변수에 연계시킨다. 용도가 입력인지 출력인지는 실시간으로 결정될것이고, 충분한 저장 공간이 할당될 필요가 있다. length 인수 는 연계를 위한 최대 용량을 세팅한다. length 인수를 -1로 세팅하면 OCIBindByName()함수는 연계를 위한 최대 용량을 variable 의 현재 용량으로 사용할것이다.

추상형 데이터타입(LOB/ROWID/BFILE)을 연계 할 필요가 있다면 우선은 OCINewDescriptor()함수를 사용해서 변수를 할당해야 한다. length 인수는 추상형 데이터타입 을 위해 사용되지 않는다. 이때 이 값은 -1이 되어야 한다. type 변수는 오라클에서 현재 어떤 종류의 descriptor가 사용되는지 알려준다. 가능한 값은 다음과 같다: 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

<?php
/* OCIBindByPos example [email protected] (980221)
  inserts 3 records into emp, and uses the ROWID for updating the 
  records just after the insert.
*/

$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",&amp;$empno,32);
OCIBindByName($stmt,":ename",&amp;$ename,32);
OCIBindByName($stmt,":rid",&amp;$rowid,-1,OCI_B_ROWID);

$update = OCIParse($conn,"update emp set sal = :sal where ROWID = :rid");
OCIBindByName($update,":rid",&amp;$rowid,-1,OCI_B_ROWID);
OCIBindByName($update,":sal",&amp;$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,&amp;$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);
?>
Warning

It is a bad idea to use magic quotes and OciBindByName() simultaneously as no quoting is needed on quoted variables and any quotes magically applied will be written into your database as OciBindByName() is not able to distinguish magically added quotings from those added by intention.