OCIBindByName

OCIBindByName -- Enlaza una variable PHP a un Placeholder de Oracle

Descripción

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

OCIBindByName( ) enlaza la variable PHP variable a un placeholder de Oracle ph_name . Si esta será usada para entrada o salida se determinará en tiempo de ejecución , y sera resevado el espacio necesario de almacenamiento . El parámetro length establece el tamaño máximo del enlace . Si establece length a -1 OCIBindByName( ) usará el tamaño de la variable para establecer el tamaño máximo .

Si necesita enlazar tipos de datos abstractos ( LOB / ROWID / BFILE ) necesitará primero reservar la memoria con la función OCINewDescriptor( ) . length no se usa para tipos de datos abstractos y debería establecerse a -1 . La variable type le informa a Oracle , que tipo de descriptor queremos usar . Los valores posibles son :

Ejemplo 1 .

 
?php

 
/

 
*

 
OCIBindByPos

 
example

 
thies@digicol.de

 
(

 
980221

 
)

 
inserts

 
3

 
resords

 
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"

 
,

 
$empno,32)

 
;

 
OCIBindByName($stmt

 
,":ename"

 
,

 
$ename,32)

 
;

 
OCIBindByName($stmt

 
,":rid"

 
,

 
$rowid,-1,OCI_B_ROWID)

 
;

 
$update

 
=

 
OCIParse($conn

 
,"update

 
emp

 
set

 
sal

 
=

 
:sal

 
where

 
ROWID

 
=

 
:rid")

 
;

 
OCIBindByName($update

 
,":rid"

 
,

 
$rowid,-1,OCI_B_ROWID)

 
;

 
OCIBindByName($update

 
,":sal"

 
,

 
$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

 
,

 
$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)

 
;

 
?