<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >oci_bind_by_name</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="Manual do PHP" HREF="index.html"><LINK REL="UP" TITLE="Funções do Oracle 8" HREF="ref.oci8.html"><LINK REL="PREVIOUS" TITLE="oci_bind_array_by_name" HREF="function.oci-bind-array-by-name.html"><LINK REL="NEXT" TITLE="oci_cancel" HREF="function.oci-cancel.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></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" >Manual do PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.oci-bind-array-by-name.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.oci-cancel.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.oci-bind-by-name" ></A >oci_bind_by_name</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN151202" ></A ><P > (PHP 5)</P >oci_bind_by_name -- Binds the PHP variable to the Oracle placeholder</DIV ><DIV CLASS="refsect1" ><A NAME="AEN151205" ></A ><H2 >Descrição</H2 >bool <B CLASS="methodname" >oci_bind_by_name</B > ( resource statement, string ph_name, mixed &variable [, int maxlength [, int type]] )<BR ></BR ><P > Binds the PHP variable <CODE CLASS="parameter" >variable</CODE > to the Oracle placeholder <CODE CLASS="parameter" >ph_name</CODE >. Whether it will be used for input or output will be determined at run-time and the necessary storage space will be allocated. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN151228" ></A ><H2 >Parâmetros</H2 ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >statement</CODE ></DT ><DD ><P > An OCI statement. </P ></DD ><DT ><CODE CLASS="parameter" >ph_name</CODE ></DT ><DD ><P > The placeholder. </P ></DD ><DT ><CODE CLASS="parameter" >variable</CODE ></DT ><DD ><P > The PHP variable. </P ></DD ><DT ><CODE CLASS="parameter" >maxlength</CODE ></DT ><DD ><P > Sets the maximum length for the bind. If you set it to -1, this function will use the current length of <CODE CLASS="parameter" >variable</CODE > to set the maximum length. </P ></DD ><DT ><CODE CLASS="parameter" >type</CODE ></DT ><DD ><P > If you need to bind an abstract datatype (LOB/ROWID/BFILE) you need to allocate it first using the <A HREF="function.oci-new-descriptor.html" ><B CLASS="function" >oci_new_descriptor()</B ></A > function. The <CODE CLASS="parameter" >length</CODE > is not used for abstract datatypes and should be set to -1. The <CODE CLASS="parameter" >type</CODE > parameter tells Oracle which descriptor is used. Possible values are: <P ></P ><UL ><LI ><P > <TT CLASS="constant" ><B >SQLT_FILE</B ></TT > - for BFILEs; </P ></LI ><LI ><P > <TT CLASS="constant" ><B >SQLT_CFILE</B ></TT > - for CFILEs; </P ></LI ><LI ><P > <TT CLASS="constant" ><B >SQLT_CLOB</B ></TT > - for CLOBs; </P ></LI ><LI ><P > <TT CLASS="constant" ><B >SQLT_BLOB</B ></TT > - for BLOBs; </P ></LI ><LI ><P > <TT CLASS="constant" ><B >SQLT_RDD</B ></TT > - for ROWIDs; </P ></LI ><LI ><P > <TT CLASS="constant" ><B >SQLT_NTY</B ></TT > - for named datatypes; </P ></LI ><LI ><P > <TT CLASS="constant" ><B >SQLT_INT</B ></TT > - for integers; </P ></LI ><LI ><P > <TT CLASS="constant" ><B >SQLT_CHR</B ></TT > - for VARCHARs; </P ></LI ><LI ><P > <TT CLASS="constant" ><B >SQLT_BIN</B ></TT > - for RAW columns; </P ></LI ><LI ><P > <TT CLASS="constant" ><B >SQLT_LNG</B ></TT > - for LONG columns; </P ></LI ><LI ><P > <TT CLASS="constant" ><B >SQLT_LBI</B ></TT > - for LONG RAW columns; </P ></LI ><LI ><P > <TT CLASS="constant" ><B >SQLT_RSET</B ></TT > - for cursors, that were created before with <A HREF="function.oci-new-cursor.html" ><B CLASS="function" >oci_new_cursor()</B ></A >. </P ></LI ></UL > </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN151299" ></A ><H2 >Valores de retornado</H2 ><P > Retorna <TT CLASS="constant" ><B >TRUE</B ></TT > em caso de sucesso ou <TT CLASS="constant" ><B >FALSE</B ></TT > em falhas. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN151304" ></A ><H2 >Exemplos</H2 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN151307" ></A ><P ><B >Exemplo 1. <B CLASS="function" >oci_bind_by_name()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#FF8000">/* oci_bind_by_name example thies at thieso dot net (980221)<br /> inserts 3 records into emp, and uses the ROWID for updating the<br /> records just after the insert.<br />*/<br /><br /></font><font color="#0000BB">$conn </font><font color="#007700">= </font><font color="#0000BB">oci_connect</font><font color="#007700">(</font><font color="#DD0000">"scott"</font><font color="#007700">, </font><font color="#DD0000">"tiger"</font><font color="#007700">);<br /><br /></font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">oci_parse</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#DD0000">"<br /> INSERT INTO<br /> emp (empno, ename)<br /> VALUES<br /> (:empno,:ename)<br /> RETURNING<br /> ROWID<br /> INTO<br /> :rid<br /> "</font><font color="#007700">);<br /><br /></font><font color="#0000BB">$data </font><font color="#007700">= array(<br /> </font><font color="#0000BB">1111 </font><font color="#007700">=> </font><font color="#DD0000">"Larry"</font><font color="#007700">,<br /> </font><font color="#0000BB">2222 </font><font color="#007700">=> </font><font color="#DD0000">"Bill"</font><font color="#007700">,<br /> </font><font color="#0000BB">3333 </font><font color="#007700">=> </font><font color="#DD0000">"Jim"<br /> </font><font color="#007700">);<br /><br /></font><font color="#0000BB">$rowid </font><font color="#007700">= </font><font color="#0000BB">oci_new_descriptor</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#0000BB">OCI_D_ROWID</font><font color="#007700">);<br /><br /></font><font color="#0000BB">oci_bind_by_name</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">, </font><font color="#DD0000">":empno"</font><font color="#007700">, </font><font color="#0000BB">$empno</font><font color="#007700">, </font><font color="#0000BB">32</font><font color="#007700">);<br /></font><font color="#0000BB">oci_bind_by_name</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">, </font><font color="#DD0000">":ename"</font><font color="#007700">, </font><font color="#0000BB">$ename</font><font color="#007700">, </font><font color="#0000BB">32</font><font color="#007700">);<br /></font><font color="#0000BB">oci_bind_by_name</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">, </font><font color="#DD0000">":rid"</font><font color="#007700">, </font><font color="#0000BB">$rowid</font><font color="#007700">, -</font><font color="#0000BB">1</font><font color="#007700">, </font><font color="#0000BB">OCI_B_ROWID</font><font color="#007700">);<br /><br /></font><font color="#0000BB">$update </font><font color="#007700">= </font><font color="#0000BB">oci_parse</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#DD0000">"<br /> UPDATE<br /> emp<br /> SET<br /> sal = :sal<br /> WHERE<br /> ROWID = :rid<br /> "</font><font color="#007700">);<br /></font><font color="#0000BB">oci_bind_by_name</font><font color="#007700">(</font><font color="#0000BB">$update</font><font color="#007700">, </font><font color="#DD0000">":rid"</font><font color="#007700">, </font><font color="#0000BB">$rowid</font><font color="#007700">, -</font><font color="#0000BB">1</font><font color="#007700">, </font><font color="#0000BB">OCI_B_ROWID</font><font color="#007700">);<br /></font><font color="#0000BB">oci_bind_by_name</font><font color="#007700">(</font><font color="#0000BB">$update</font><font color="#007700">, </font><font color="#DD0000">":sal"</font><font color="#007700">, </font><font color="#0000BB">$sal</font><font color="#007700">, </font><font color="#0000BB">32</font><font color="#007700">);<br /><br /></font><font color="#0000BB">$sal </font><font color="#007700">= </font><font color="#0000BB">10000</font><font color="#007700">;<br /><br />foreach (</font><font color="#0000BB">$data </font><font color="#007700">as </font><font color="#0000BB">$empno </font><font color="#007700">=> </font><font color="#0000BB">$ename</font><font color="#007700">) {<br /> </font><font color="#0000BB">oci_execute</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">);<br /> </font><font color="#0000BB">oci_execute</font><font color="#007700">(</font><font color="#0000BB">$update</font><font color="#007700">);<br />}<br /><br /></font><font color="#0000BB">$rowid</font><font color="#007700">-></font><font color="#0000BB">free</font><font color="#007700">();<br /><br /></font><font color="#0000BB">oci_free_statement</font><font color="#007700">(</font><font color="#0000BB">$update</font><font color="#007700">);<br /></font><font color="#0000BB">oci_free_statement</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">);<br /><br /></font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">oci_parse</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#DD0000">"<br /> SELECT<br /> *<br /> FROM<br /> emp<br /> WHERE<br /> empno<br /> IN<br /> (1111,2222,3333)<br /> "</font><font color="#007700">);<br /></font><font color="#0000BB">oci_execute</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">);<br /><br />while (</font><font color="#0000BB">$row </font><font color="#007700">= </font><font color="#0000BB">oci_fetch_assoc</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">)) {<br /> </font><font color="#0000BB">var_dump</font><font color="#007700">(</font><font color="#0000BB">$row</font><font color="#007700">);<br />}<br /><br /></font><font color="#0000BB">oci_free_statement</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* delete our "junk" from the emp table.... */<br /></font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">oci_parse</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#DD0000">"<br /> DELETE FROM<br /> emp<br /> WHERE<br /> empno<br /> IN<br /> (1111,2222,3333)<br /> "</font><font color="#007700">);<br /></font><font color="#0000BB">oci_execute</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">);<br /></font><font color="#0000BB">oci_free_statement</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">);<br /><br /></font><font color="#0000BB">oci_close</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > Remember, this function strips trailing whitespaces. See the following example: </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN151313" ></A ><P ><B >Exemplo 2. <B CLASS="function" >oci_bind_by_name()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /> $connection </font><font color="#007700">= </font><font color="#0000BB">oci_connect</font><font color="#007700">(</font><font color="#DD0000">'apelsin'</font><font color="#007700">,</font><font color="#DD0000">'kanistra'</font><font color="#007700">);<br /> </font><font color="#0000BB">$query </font><font color="#007700">= </font><font color="#DD0000">"INSERT INTO test_table VALUES(:id, :text)"</font><font color="#007700">;<br /><br /> </font><font color="#0000BB">$statement </font><font color="#007700">= </font><font color="#0000BB">oci_parse</font><font color="#007700">(</font><font color="#0000BB">$query</font><font color="#007700">);<br /> </font><font color="#0000BB">oci_bind_by_name</font><font color="#007700">(</font><font color="#0000BB">$statement</font><font color="#007700">, </font><font color="#DD0000">":id"</font><font color="#007700">, </font><font color="#0000BB">1</font><font color="#007700">);<br /> </font><font color="#0000BB">oci_bind_by_name</font><font color="#007700">(</font><font color="#0000BB">$statement</font><font color="#007700">, </font><font color="#DD0000">":text"</font><font color="#007700">, </font><font color="#DD0000">"trailing spaces follow "</font><font color="#007700">);<br /> </font><font color="#0000BB">oci_execute</font><font color="#007700">(</font><font color="#0000BB">$statement</font><font color="#007700">);<br /> </font><font color="#FF8000">/*<br /> This code will insert into DB string 'trailing spaces follow', without<br /> trailing spaces<br /> */<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN151318" ></A ><P ><B >Exemplo 3. <B CLASS="function" >oci_bind_by_name()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /> $connection </font><font color="#007700">= </font><font color="#0000BB">oci_connect</font><font color="#007700">(</font><font color="#DD0000">'apelsin'</font><font color="#007700">,</font><font color="#DD0000">'kanistra'</font><font color="#007700">);<br /> </font><font color="#0000BB">$query </font><font color="#007700">= </font><font color="#DD0000">"INSERT INTO test_table VALUES(:id, 'trailing spaces follow ')"</font><font color="#007700">;<br /><br /> </font><font color="#0000BB">$statement </font><font color="#007700">= </font><font color="#0000BB">oci_parse</font><font color="#007700">(</font><font color="#0000BB">$query</font><font color="#007700">);<br /> </font><font color="#0000BB">oci_bind_by_name</font><font color="#007700">(</font><font color="#0000BB">$statement</font><font color="#007700">, </font><font color="#DD0000">":id"</font><font color="#007700">, </font><font color="#0000BB">1</font><font color="#007700">);<br /> </font><font color="#0000BB">oci_execute</font><font color="#007700">(</font><font color="#0000BB">$statement</font><font color="#007700">);<br /> </font><font color="#FF8000">/*<br /> And this code will add 'trailing spaces follow ', preserving<br /> trailing whitespaces<br /> */<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN151322" ></A ><H2 >Valores de retornado</H2 ><P > Retorna <TT CLASS="constant" ><B >TRUE</B ></TT > em caso de sucesso ou <TT CLASS="constant" ><B >FALSE</B ></TT > em falhas. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN151327" ></A ><H2 >Notas</H2 ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Atenção</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P > Do not use <A HREF="ref.info.html#ini.magic-quotes-gpc" >magic_quotes_gpc</A > or <A HREF="function.addslashes.html" ><B CLASS="function" >addslashes()</B ></A > and <B CLASS="function" >oci_bind_by_name()</B > simultaneously as no quoting is needed and any magically applied quotes will be written into your database as <B CLASS="function" >oci_bind_by_name()</B > is not able to distinguish magically added quotings from those added intentionally. </P ></TD ></TR ></TABLE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Nota: </B > In PHP versions before 5.0.0 you must use <A HREF="function.ocibindbyname.html" ><B CLASS="function" >ocibindbyname()</B ></A > instead. This name still can be used, it was left as alias of <B CLASS="function" >oci_bind_by_name()</B > for downwards compatability. This, however, is deprecated and not recommended. </P ></BLOCKQUOTE ></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="function.oci-bind-array-by-name.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Principal</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.oci-cancel.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >oci_bind_array_by_name</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.oci8.html" ACCESSKEY="U" >Acima</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >oci_cancel</TD ></TR ></TABLE ></DIV ></BODY ></HTML >