<HTML ><HEAD ><TITLE >OCIBindByName</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="Oracle 8 functions" HREF="ref.oci8.html"><LINK REL="PREVIOUS" TITLE="Oracle 8 functions" HREF="ref.oci8.html"><LINK REL="NEXT" TITLE="OCICancel" HREF="function.ocicancel.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="ref.oci8.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.ocicancel.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.ocibindbyname" ></A >OCIBindByName</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN66686" ></A ><P > (PHP 3>= 3.0.4, PHP 4 )</P >OCIBindByName -- Bind a PHP variable to an Oracle Placeholder </DIV ><DIV CLASS="refsect1" ><A NAME="AEN66689" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >OCIBindByName</B > ( int stmt, string ph_name, mixed & variable, int length [, int type])<BR ></BR ><P > <B CLASS="function" >OCIBindByName()</B > binds the PHP variable <TT CLASS="parameter" ><I >variable</I ></TT > to the Oracle placeholder <TT CLASS="parameter" ><I >ph_name</I ></TT >. Whether it will be used for input or output will be determined run-time, and the necessary storage space will be allocated. The <TT CLASS="parameter" ><I >length</I ></TT > parameter sets the maximum length for the bind. If you set <TT CLASS="parameter" ><I >length</I ></TT > to -1 <B CLASS="function" >OCIBindByName()</B > will use the current length of <TT CLASS="parameter" ><I >variable</I ></TT > to set the maximum length. </P ><P > If you need to bind an abstract Datatype (LOB/ROWID/BFILE) you need to allocate it first using <A HREF="function.ocinewdescriptor.html" ><B CLASS="function" >OCINewDescriptor()</B ></A > function. The <TT CLASS="parameter" ><I >length</I ></TT > is not used for abstract Datatypes and should be set to -1. The <TT CLASS="parameter" ><I >type</I ></TT > variable tells oracle, what kind of descriptor we want to use. Possible values are: 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). </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN66721" ></A ><P ><B >Example 1. OCIDefineByName</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" ><?php /* OCIBindByPos example thies@thieso.net (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",&$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); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Warning</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P > It is a bad idea to use magic quotes and <B CLASS="function" >OciBindByName()</B > simultaneously as no quoting is needed on quoted variables and any quotes magically applied will be written into your database as <B CLASS="function" >OciBindByName()</B > is not able to distinguish magically added quotings from those added by intention. </P ></TD ></TR ></TABLE ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="ref.oci8.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.ocicancel.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Oracle 8 functions</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.oci8.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >OCICancel</TD ></TR ></TABLE ></DIV ></BODY ></HTML >