<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >db2_set_option</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="IBM DB2, Cloudscape and Apache Derby Functions" HREF="ref.ibm-db2.html"><LINK REL="PREVIOUS" TITLE="db2_server_info" HREF="function.db2-server-info.html"><LINK REL="NEXT" TITLE="db2_special_columns" HREF="function.db2-special-columns.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.db2-server-info.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.db2-special-columns.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.db2-set-option" ></A >db2_set_option</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN78645" ></A ><P > (PECL)</P >db2_set_option -- Set options for connection or statement resources</DIV ><DIV CLASS="refsect1" ><A NAME="AEN78648" ></A ><H2 >Descrição</H2 >bool <B CLASS="methodname" >db2_set_option</B > ( resource resource, array options [, int type] )<BR ></BR ><P > Sets options for a statement resource or a connection resource. You cannot set options for result set resources. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN78663" ></A ><H2 >Parâmetros</H2 ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >resource</CODE ></DT ><DD ><P > A valid statement resource as returned from <A HREF="function.db2-prepare.html" ><B CLASS="function" >db2_prepare()</B ></A > or a valid connection resource as returned from <A HREF="function.db2-connect.html" ><B CLASS="function" >db2_connect()</B ></A > or <A HREF="function.db2-pconnect.html" ><B CLASS="function" >db2_pconnect()</B ></A >. </P ></DD ><DT ><CODE CLASS="parameter" >options</CODE ></DT ><DD ><P > An associative array containing valid statement or connection options. This parameter can be used to change autocommit values, cursor types (scrollable or forward), and to specify the case of the column names (lower, upper, or natural) that will appear in a result set. <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >autocommit</CODE ></DT ><DD ><P > Passing <TT CLASS="literal" >DB2_AUTOCOMMIT_ON</TT > turns autocommit on for the specified connection resource. </P ><P > Passing <TT CLASS="literal" >DB2_AUTOCOMMIT_OFF</TT > turns autocommit off for the specified connection resource. </P ></DD ><DT ><CODE CLASS="parameter" >cursor</CODE ></DT ><DD ><P > Passing <TT CLASS="literal" >DB2_FORWARD_ONLY</TT > specifies a forward-only cursor for a statement resource. This is the default cursor type, and is supported by all database servers. </P ><P > Passing <TT CLASS="literal" >DB2_SCROLLABLE</TT > specifies a scrollable cursor for a statement resource. Scrollable cursors enable result set rows to be accessed in non-sequential order, but are only supported by IBM DB2 Universal Database databases. </P ></DD ><DT ><CODE CLASS="parameter" >binmode</CODE ></DT ><DD ><P > Passing <TT CLASS="literal" >DB2_BINARY</TT > specifies that binary data will be returned as is. This is the default mode. This is the equivalent of setting <TT CLASS="literal" >ibm_db2.binmode=1</TT > in <TT CLASS="filename" >php.ini</TT >. </P ><P > Passing <TT CLASS="literal" >DB2_CONVERT</TT > specifies that binary data will be converted to hexadecimal encoding, and will be returned as such. This is the equivalent of setting <TT CLASS="literal" >ibm_db2.binmode=2</TT > in <TT CLASS="filename" >php.ini</TT >. </P ><P > Passing <TT CLASS="literal" >DB2_PASSTHRU</TT > specifies that binary data will be converted to <TT CLASS="constant" ><B >NULL</B ></TT >. This is the equivalent of setting <TT CLASS="literal" >ibm_db2.binmode=3</TT > in <TT CLASS="filename" >php.ini</TT >. </P ></DD ><DT ><CODE CLASS="parameter" >db2_attr_case</CODE ></DT ><DD ><P > Passing <TT CLASS="literal" >DB2_CASE_LOWER</TT > specifies that column names of the result set are returned in lower case. </P ><P > Passing <TT CLASS="literal" >DB2_CASE_UPPER</TT > specifies that column names of the result set are returned in upper case. </P ><P > Passing <TT CLASS="literal" >DB2_CASE_NATURAL</TT > specifies that column names of the result set are returned in natural case. </P ></DD ><DT ><CODE CLASS="parameter" >deferred_prepare</CODE ></DT ><DD ><P > Passing <TT CLASS="literal" >DB2_DEFERRED_PREPARE_ON</TT > turns deferred prepare on for the specified statement resource. </P ><P > Passing <TT CLASS="literal" >DB2_DEFERRED_PREPARE_OFF</TT > turns deferred prepare off for the specified statement resource. </P ></DD ></DL ></DIV > </P ><P > The following new i5/OS options are available as of ibm_db2 version 1.5.1. <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > Prior versions of ibm_db2 do not support these new i5 options. </P ></BLOCKQUOTE ></DIV > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >i5_fetch_only</CODE ></DT ><DD ><P > <TT CLASS="literal" >DB2_I5_FETCH_ON</TT > - Cursors are read-only and cannot be used for positioned updates or deletes. This is the default unless <TT CLASS="literal" >SQL_ATTR_FOR_FETCH_ONLY</TT > environment has been set to <TT CLASS="literal" >SQL_FALSE</TT >. </P ><P > <TT CLASS="literal" >DB2_I5_FETCH_OFF</TT > - Cursors can be used for positioned updates and deletes. </P ></DD ></DL ></DIV > </P ><P > The following new options are available as of ibm_db2 version 1.6.0. They provide useful tracking information that can be accessed during execution with <A HREF="function.db2-get-option.html" ><B CLASS="function" >db2_get_option()</B ></A >. <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > Prior versions of ibm_db2 do not support these new options. </P ><P > When the value in each option is being set, some servers might not handle the entire length provided and might truncate the value. </P ><P > To ensure that the data specified in each option is converted correctly when transmitted to a host system, use only the characters A through Z, 0 through 9, and the underscore (_) or period (.). </P ></BLOCKQUOTE ></DIV > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >userid</CODE ></DT ><DD ><P > <TT CLASS="literal" >SQL_ATTR_INFO_USERID</TT > - A pointer to a null-terminated character string used to identify the client user ID sent to the host database server when using DB2 Connect. <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > DB2 for z/OS and OS/390 servers support up to a length of 16 characters. This user-id is not to be confused with the authentication user-id, it is for identification purposes only and is not used for any authorization. </P ></BLOCKQUOTE ></DIV > </P ></DD ><DT ><CODE CLASS="parameter" >acctstr</CODE ></DT ><DD ><P > <TT CLASS="literal" >SQL_ATTR_INFO_ACCTSTR</TT > - A pointer to a null-terminated character string used to identify the client accounting string sent to the host database server when using DB2 Connect. <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > DB2 for z/OS and OS/390 servers support up to a length of 200 characters. </P ></BLOCKQUOTE ></DIV > </P ></DD ><DT ><CODE CLASS="parameter" >applname</CODE ></DT ><DD ><P > <TT CLASS="literal" >SQL_ATTR_INFO_APPLNAME</TT > - A pointer to a null-terminated character string used to identify the client application name sent to the host database server when using DB2 Connect. <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > DB2 for z/OS and OS/390 servers support up to a length of 32 characters. </P ></BLOCKQUOTE ></DIV > </P ></DD ><DT ><CODE CLASS="parameter" >wrkstnname</CODE ></DT ><DD ><P > <TT CLASS="literal" >SQL_ATTR_INFO_WRKSTNNAME</TT > - A pointer to a null-terminated character string used to identify the client workstation name sent to the host database server when using DB2 Connect. <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > DB2 for z/OS and OS/390 servers support up to a length of 18 characters. </P ></BLOCKQUOTE ></DIV > </P ></DD ></DL ></DIV > </P ></DD ><DT ><CODE CLASS="parameter" >type</CODE ></DT ><DD ><P > An integer value that specifies the type of resource that was passed into the function. The type of resource and this value must correspond. <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" ></CODE ></DT ><DD ><P > Passing <TT CLASS="literal" >1</TT > as the value specifies that a connection resource has been passed into the function. </P ><P > Passing any integer not equal to <TT CLASS="literal" >1</TT > as the value specifies that a statement resource has been passed into the function. </P ></DD ></DL ></DIV > </P ></DD ></DL ></DIV > </P ><P > </P ><P > The following table specifies which options are compatible with the available resource types: <DIV CLASS="table" ><A NAME="AEN78807" ></A ><P ><B >Tabela 1. Resource-Parameter Matrix</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL WIDTH="1*" ALIGN="center" TITLE="col1"><COL WIDTH="1*" ALIGN="center" TITLE="col2"><COL WIDTH="1*" ALIGN="center" TITLE="col3"><COL WIDTH="1*" ALIGN="center" TITLE="col4"><COL WIDTH="1*" ALIGN="center" TITLE="col5"><THEAD ><TR ><TH ROWSPAN="2" >Key</TH ><TH ROWSPAN="2" >Value</TH ><TH COLSPAN="3" >Resource Type</TH ></TR ></THEAD ><TBODY ><TR ><TD > </TD ><TD > </TD ><TD >Connection</TD ><TD >Statement</TD ><TD >Result Set</TD ></TR ><TR ><TD >autocommit</TD ><TD ><TT CLASS="literal" >DB2_AUTOCOMMIT_ON</TT ></TD ><TD >X</TD ><TD >-</TD ><TD >-</TD ></TR ><TR ><TD >autocommit</TD ><TD ><TT CLASS="literal" >DB2_AUTOCOMMIT_OFF</TT ></TD ><TD >X</TD ><TD >-</TD ><TD >-</TD ></TR ><TR ><TD >cursor</TD ><TD ><TT CLASS="literal" >DB2_SCROLLABLE</TT ></TD ><TD >-</TD ><TD >X</TD ><TD >-</TD ></TR ><TR ><TD >cursor</TD ><TD ><TT CLASS="literal" >DB2_FORWARD_ONLY</TT ></TD ><TD >-</TD ><TD >X</TD ><TD >-</TD ></TR ><TR ><TD >binmode</TD ><TD ><TT CLASS="literal" >DB2_BINARY</TT ></TD ><TD >X</TD ><TD >X</TD ><TD >-</TD ></TR ><TR ><TD >binmode</TD ><TD ><TT CLASS="literal" >DB2_CONVERT</TT ></TD ><TD >X</TD ><TD >X</TD ><TD >-</TD ></TR ><TR ><TD >binmode</TD ><TD ><TT CLASS="literal" >DB2_PASSTHRU</TT ></TD ><TD >X</TD ><TD >X</TD ><TD >-</TD ></TR ><TR ><TD >db2_attr_case</TD ><TD ><TT CLASS="literal" >DB2_CASE_LOWER</TT ></TD ><TD >X</TD ><TD >X</TD ><TD >-</TD ></TR ><TR ><TD >db2_attr_case</TD ><TD ><TT CLASS="literal" >DB2_CASE_UPPER</TT ></TD ><TD >X</TD ><TD >X</TD ><TD >-</TD ></TR ><TR ><TD >db2_attr_case</TD ><TD ><TT CLASS="literal" >DB2_CASE_NATURAL</TT ></TD ><TD >X</TD ><TD >X</TD ><TD >-</TD ></TR ><TR ><TD >deferred_prepare</TD ><TD ><TT CLASS="literal" >DB2_DEFERRED_PREPARE_ON</TT ></TD ><TD >-</TD ><TD >X</TD ><TD >-</TD ></TR ><TR ><TD >deferred_prepare</TD ><TD ><TT CLASS="literal" >DB2_DEFERRED_PREPARE_OFF</TT ></TD ><TD >-</TD ><TD >X</TD ><TD >-</TD ></TR ><TR ><TD >i5_fetch_only</TD ><TD ><TT CLASS="literal" >DB2_I5_FETCH_ON</TT ></TD ><TD >-</TD ><TD >X</TD ><TD >-</TD ></TR ><TR ><TD >i5_fetch_only</TD ><TD ><TT CLASS="literal" >DB2_I5_FETCH_OFF</TT ></TD ><TD >-</TD ><TD >X</TD ><TD >-</TD ></TR ><TR ><TD >userid</TD ><TD ><TT CLASS="literal" >SQL_ATTR_INFO_USERID</TT ></TD ><TD >X</TD ><TD >X</TD ><TD >-</TD ></TR ><TR ><TD >acctstr</TD ><TD ><TT CLASS="literal" >SQL_ATTR_INFO_ACCTSTR</TT ></TD ><TD >X</TD ><TD >X</TD ><TD >-</TD ></TR ><TR ><TD >applname</TD ><TD ><TT CLASS="literal" >SQL_ATTR_INFO_APPLNAME</TT ></TD ><TD >X</TD ><TD >X</TD ><TD >-</TD ></TR ><TR ><TD >wrkstnname</TD ><TD ><TT CLASS="literal" >SQL_ATTR_INFO_WRKSTNNAME</TT ></TD ><TD >X</TD ><TD >X</TD ><TD >-</TD ></TR ></TBODY ></TABLE ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN78951" ></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="AEN78956" ></A ><H2 >Exemplos</H2 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN78959" ></A ><P ><B >Exemplo 1. Setting one parameter with a connection resource</B ></P ><P > </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#FF8000">/* Database Connection Parameters */<br /></font><font color="#0000BB">$database </font><font color="#007700">= </font><font color="#DD0000">'SAMPLE'</font><font color="#007700">;<br /></font><font color="#0000BB">$hostname </font><font color="#007700">= </font><font color="#DD0000">'localhost'</font><font color="#007700">;<br /></font><font color="#0000BB">$port </font><font color="#007700">= </font><font color="#0000BB">50000</font><font color="#007700">;<br /></font><font color="#0000BB">$protocol </font><font color="#007700">= </font><font color="#DD0000">'TCPIP'</font><font color="#007700">;<br /></font><font color="#0000BB">$username </font><font color="#007700">= </font><font color="#DD0000">'db2inst1'</font><font color="#007700">;<br /></font><font color="#0000BB">$password </font><font color="#007700">= </font><font color="#DD0000">'ibmdb2'</font><font color="#007700">;<br /><br /></font><font color="#FF8000">/* Connection String */<br /></font><font color="#0000BB">$conn_string </font><font color="#007700">= </font><font color="#DD0000">"DRIVER=</font><font color="#007700">{</font><font color="#DD0000">IBM DB2 ODBC DRIVER</font><font color="#007700">}</font><font color="#DD0000">;DATABASE=$database;"</font><font color="#007700">;<br /></font><font color="#0000BB">$conn_string </font><font color="#007700">.= </font><font color="#DD0000">"HOSTNAME=$hostname;PORT=$port;PROTOCOL=$protocol;"</font><font color="#007700">;<br /></font><font color="#0000BB">$conn_string </font><font color="#007700">.= </font><font color="#DD0000">"UID=$username;PWD=$password;"</font><font color="#007700">;<br /><br /></font><font color="#FF8000">/* Obtain Connection Resource */<br /></font><font color="#0000BB">$conn </font><font color="#007700">= </font><font color="#0000BB">db2_connect</font><font color="#007700">(</font><font color="#0000BB">$conn_string</font><font color="#007700">, </font><font color="#DD0000">''</font><font color="#007700">, </font><font color="#DD0000">''</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Create the associative options array with valid key-value pairs */<br /></font><font color="#0000BB">$options </font><font color="#007700">= array(</font><font color="#DD0000">'autocommit' </font><font color="#007700">=> </font><font color="#0000BB">DB2_AUTOCOMMIT_ON</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Call the function using the correct resource, options array, and type values */<br /></font><font color="#0000BB">$result </font><font color="#007700">= </font><font color="#0000BB">db2_set_option</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#0000BB">$options</font><font color="#007700">, </font><font color="#0000BB">1</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Check if all options could be set correctly */<br /></font><font color="#007700">if(</font><font color="#0000BB">$result</font><font color="#007700">)<br />{<br /> echo </font><font color="#DD0000">'Options Set Successfully'</font><font color="#007700">; <br />}<br />else<br />{<br /> echo </font><font color="#DD0000">'Could Not Set Options'</font><font color="#007700">;<br />}<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P >O exemplo acima irá imprimir:</P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Options Set Successfully</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN78965" ></A ><P ><B >Exemplo 2. Setting multiple parameters with a connection resource</B ></P ><P > </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#FF8000">/* Database Connection Parameters */<br /></font><font color="#0000BB">$database </font><font color="#007700">= </font><font color="#DD0000">'SAMPLE'</font><font color="#007700">;<br /></font><font color="#0000BB">$hostname </font><font color="#007700">= </font><font color="#DD0000">'localhost'</font><font color="#007700">;<br /></font><font color="#0000BB">$port </font><font color="#007700">= </font><font color="#0000BB">50000</font><font color="#007700">;<br /></font><font color="#0000BB">$protocol </font><font color="#007700">= </font><font color="#DD0000">'TCPIP'</font><font color="#007700">;<br /></font><font color="#0000BB">$username </font><font color="#007700">= </font><font color="#DD0000">'db2inst1'</font><font color="#007700">;<br /></font><font color="#0000BB">$password </font><font color="#007700">= </font><font color="#DD0000">'ibmdb2'</font><font color="#007700">;<br /><br /></font><font color="#FF8000">/* Connection String */<br /></font><font color="#0000BB">$conn_string </font><font color="#007700">= </font><font color="#DD0000">"DRIVER=</font><font color="#007700">{</font><font color="#DD0000">IBM DB2 ODBC DRIVER</font><font color="#007700">}</font><font color="#DD0000">;DATABASE=$database;"</font><font color="#007700">;<br /></font><font color="#0000BB">$conn_string </font><font color="#007700">.= </font><font color="#DD0000">"HOSTNAME=$hostname;PORT=$port;PROTOCOL=$protocol;"</font><font color="#007700">;<br /></font><font color="#0000BB">$conn_string </font><font color="#007700">.= </font><font color="#DD0000">"UID=$username;PWD=$password;"</font><font color="#007700">;<br /><br /></font><font color="#FF8000">/* Obtain Connection Resource */<br /></font><font color="#0000BB">$conn </font><font color="#007700">= </font><font color="#0000BB">db2_connect</font><font color="#007700">(</font><font color="#0000BB">$conn_string</font><font color="#007700">, </font><font color="#DD0000">''</font><font color="#007700">, </font><font color="#DD0000">''</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Create the associative options array with valid key-value pairs */<br /></font><font color="#0000BB">$options </font><font color="#007700">= array(</font><font color="#DD0000">'autocommit' </font><font color="#007700">=> </font><font color="#0000BB">DB2_AUTOCOMMIT_OFF</font><font color="#007700">, <br /> </font><font color="#DD0000">'binmode' </font><font color="#007700">=> </font><font color="#0000BB">DB2_PASSTHRU</font><font color="#007700">,<br /> </font><font color="#DD0000">'db2_attr_case' </font><font color="#007700">=> </font><font color="#0000BB">DB2_CASE_UPPER</font><font color="#007700">,<br /> </font><font color="#DD0000">'cursor' </font><font color="#007700">=> </font><font color="#0000BB">DB2_SCROLLABLE</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Call the function using the correct resource, options array, and type values */<br /></font><font color="#0000BB">$result </font><font color="#007700">= </font><font color="#0000BB">db2_set_option</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#0000BB">$options</font><font color="#007700">, </font><font color="#0000BB">1</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Check if all options could be set correctly */<br /></font><font color="#007700">if(</font><font color="#0000BB">$result</font><font color="#007700">)<br />{<br /> echo </font><font color="#DD0000">'Options Set Successfully'</font><font color="#007700">;<br />}<br />else<br />{<br /> echo </font><font color="#DD0000">'Could Not Set Options'</font><font color="#007700">;<br />}<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P >O exemplo acima irá imprimir:</P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Options Set Successfully</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN78971" ></A ><P ><B >Exemplo 3. Setting multiple parameters with an invalid key</B ></P ><P > </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#FF8000">/* Database Connection Parameters */<br /></font><font color="#0000BB">$database </font><font color="#007700">= </font><font color="#DD0000">'SAMPLE'</font><font color="#007700">;<br /></font><font color="#0000BB">$hostname </font><font color="#007700">= </font><font color="#DD0000">'localhost'</font><font color="#007700">;<br /></font><font color="#0000BB">$port </font><font color="#007700">= </font><font color="#0000BB">50000</font><font color="#007700">;<br /></font><font color="#0000BB">$protocol </font><font color="#007700">= </font><font color="#DD0000">'TCPIP'</font><font color="#007700">;<br /></font><font color="#0000BB">$username </font><font color="#007700">= </font><font color="#DD0000">'db2inst1'</font><font color="#007700">;<br /></font><font color="#0000BB">$password </font><font color="#007700">= </font><font color="#DD0000">'ibmdb2'</font><font color="#007700">;<br /><br /></font><font color="#FF8000">/* Connection String */<br /></font><font color="#0000BB">$conn_string </font><font color="#007700">= </font><font color="#DD0000">"DRIVER=</font><font color="#007700">{</font><font color="#DD0000">IBM DB2 ODBC DRIVER</font><font color="#007700">}</font><font color="#DD0000">;DATABASE=$database;"</font><font color="#007700">;<br /></font><font color="#0000BB">$conn_string </font><font color="#007700">.= </font><font color="#DD0000">"HOSTNAME=$hostname;PORT=$port;PROTOCOL=$protocol;"</font><font color="#007700">;<br /></font><font color="#0000BB">$conn_string </font><font color="#007700">.= </font><font color="#DD0000">"UID=$username;PWD=$password;"</font><font color="#007700">;<br /><br /></font><font color="#FF8000">/* Obtain Connection Resource */<br /></font><font color="#0000BB">$conn </font><font color="#007700">= </font><font color="#0000BB">db2_connect</font><font color="#007700">(</font><font color="#0000BB">$conn_string</font><font color="#007700">, </font><font color="#DD0000">''</font><font color="#007700">, </font><font color="#DD0000">''</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Create the associative options array with valid key-value pairs */<br /></font><font color="#0000BB">$options </font><font color="#007700">= array(</font><font color="#DD0000">'autocommit' </font><font color="#007700">=> </font><font color="#0000BB">DB2_AUTOCOMMIT_OFF</font><font color="#007700">, <br /> </font><font color="#DD0000">'MY_INVALID_KEY' </font><font color="#007700">=> </font><font color="#0000BB">DB2_PASSTHRU</font><font color="#007700">,<br /> </font><font color="#DD0000">'db2_attr_case' </font><font color="#007700">=> </font><font color="#0000BB">DB2_CASE_UPPER</font><font color="#007700">,<br /> </font><font color="#DD0000">'cursor' </font><font color="#007700">=> </font><font color="#0000BB">DB2_SCROLLABLE</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Call the function using the correct resource, options array, and type values */<br /></font><font color="#0000BB">$result </font><font color="#007700">= </font><font color="#0000BB">db2_set_option</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#0000BB">$options</font><font color="#007700">, </font><font color="#0000BB">1</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Check if all options could be set correctly */<br /></font><font color="#007700">if(</font><font color="#0000BB">$result</font><font color="#007700">)<br />{<br /> echo </font><font color="#DD0000">'Options Set Successfully'</font><font color="#007700">; <br />}<br />else<br />{<br /> echo </font><font color="#DD0000">'Could Not Set Options'</font><font color="#007700">;<br />}<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P >O exemplo acima irá imprimir:</P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Could Not Set Options</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN78977" ></A ><P ><B >Exemplo 4. Setting multiple parameters with an invalid value</B ></P ><P > </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#FF8000">/* Database Connection Parameters */<br /></font><font color="#0000BB">$database </font><font color="#007700">= </font><font color="#DD0000">'SAMPLE'</font><font color="#007700">;<br /></font><font color="#0000BB">$hostname </font><font color="#007700">= </font><font color="#DD0000">'localhost'</font><font color="#007700">;<br /></font><font color="#0000BB">$port </font><font color="#007700">= </font><font color="#0000BB">50000</font><font color="#007700">;<br /></font><font color="#0000BB">$protocol </font><font color="#007700">= </font><font color="#DD0000">'TCPIP'</font><font color="#007700">;<br /></font><font color="#0000BB">$username </font><font color="#007700">= </font><font color="#DD0000">'db2inst1'</font><font color="#007700">;<br /></font><font color="#0000BB">$password </font><font color="#007700">= </font><font color="#DD0000">'ibmdb2'</font><font color="#007700">;<br /><br /></font><font color="#FF8000">/* Connection String */<br /></font><font color="#0000BB">$conn_string </font><font color="#007700">= </font><font color="#DD0000">"DRIVER=</font><font color="#007700">{</font><font color="#DD0000">IBM DB2 ODBC DRIVER</font><font color="#007700">}</font><font color="#DD0000">;DATABASE=$database;"</font><font color="#007700">;<br /></font><font color="#0000BB">$conn_string </font><font color="#007700">.= </font><font color="#DD0000">"HOSTNAME=$hostname;PORT=$port;PROTOCOL=$protocol;"</font><font color="#007700">;<br /></font><font color="#0000BB">$conn_string </font><font color="#007700">.= </font><font color="#DD0000">"UID=$username;PWD=$password;"</font><font color="#007700">;<br /><br /></font><font color="#FF8000">/* Obtain Connection Resource */<br /></font><font color="#0000BB">$conn </font><font color="#007700">= </font><font color="#0000BB">db2_connect</font><font color="#007700">(</font><font color="#0000BB">$conn_string</font><font color="#007700">, </font><font color="#DD0000">''</font><font color="#007700">, </font><font color="#DD0000">''</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Create the associative options array with valid key-value pairs */<br /></font><font color="#0000BB">$options </font><font color="#007700">= array(</font><font color="#DD0000">'autocommit' </font><font color="#007700">=> </font><font color="#0000BB">DB2_AUTOCOMMIT_OFF</font><font color="#007700">, <br /> </font><font color="#DD0000">'binmode' </font><font color="#007700">=> </font><font color="#DD0000">'INVALID_VALUE'</font><font color="#007700">,<br /> </font><font color="#DD0000">'db2_attr_case' </font><font color="#007700">=> </font><font color="#0000BB">DB2_CASE_UPPER</font><font color="#007700">,<br /> </font><font color="#DD0000">'cursor' </font><font color="#007700">=> </font><font color="#0000BB">DB2_SCROLLABLE</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Call the function using the correct resource, options array, and type values */<br /></font><font color="#0000BB">$result </font><font color="#007700">= </font><font color="#0000BB">db2_set_option</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#0000BB">$options</font><font color="#007700">, </font><font color="#0000BB">1</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Check if all options could be set correctly */<br /></font><font color="#007700">if(</font><font color="#0000BB">$result</font><font color="#007700">)<br />{<br /> echo </font><font color="#DD0000">'Options Set Successfully'</font><font color="#007700">; <br />}<br />else<br />{<br /> echo </font><font color="#DD0000">'Could Not Set Options'</font><font color="#007700">;<br />}<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P >O exemplo acima irá imprimir:</P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Could Not Set Options</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN78983" ></A ><P ><B >Exemplo 5. Setting multiple parameters with a connection resource and the wrong type</B ></P ><P > </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#FF8000">/* Database Connection Parameters */<br /></font><font color="#0000BB">$database </font><font color="#007700">= </font><font color="#DD0000">'SAMPLE'</font><font color="#007700">;<br /></font><font color="#0000BB">$hostname </font><font color="#007700">= </font><font color="#DD0000">'localhost'</font><font color="#007700">;<br /></font><font color="#0000BB">$port </font><font color="#007700">= </font><font color="#0000BB">50000</font><font color="#007700">;<br /></font><font color="#0000BB">$protocol </font><font color="#007700">= </font><font color="#DD0000">'TCPIP'</font><font color="#007700">;<br /></font><font color="#0000BB">$username </font><font color="#007700">= </font><font color="#DD0000">'db2inst1'</font><font color="#007700">;<br /></font><font color="#0000BB">$password </font><font color="#007700">= </font><font color="#DD0000">'ibmdb2'</font><font color="#007700">;<br /><br /></font><font color="#FF8000">/* Connection String */<br /></font><font color="#0000BB">$conn_string </font><font color="#007700">= </font><font color="#DD0000">"DRIVER=</font><font color="#007700">{</font><font color="#DD0000">IBM DB2 ODBC DRIVER</font><font color="#007700">}</font><font color="#DD0000">;DATABASE=$database;"</font><font color="#007700">;<br /></font><font color="#0000BB">$conn_string </font><font color="#007700">.= </font><font color="#DD0000">"HOSTNAME=$hostname;PORT=$port;PROTOCOL=$protocol;"</font><font color="#007700">;<br /></font><font color="#0000BB">$conn_string </font><font color="#007700">.= </font><font color="#DD0000">"UID=$username;PWD=$password;"</font><font color="#007700">;<br /><br /></font><font color="#FF8000">/* Obtain Connection Resource */<br /></font><font color="#0000BB">$conn </font><font color="#007700">= </font><font color="#0000BB">db2_connect</font><font color="#007700">(</font><font color="#0000BB">$conn_string</font><font color="#007700">, </font><font color="#DD0000">''</font><font color="#007700">, </font><font color="#DD0000">''</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Create the associative options array with valid key-value pairs */<br /></font><font color="#0000BB">$options </font><font color="#007700">= array(</font><font color="#DD0000">'autocommit' </font><font color="#007700">=> </font><font color="#0000BB">DB2_AUTOCOMMIT_OFF</font><font color="#007700">, <br /> </font><font color="#DD0000">'binmode' </font><font color="#007700">=> </font><font color="#0000BB">DB2_PASSTHRU</font><font color="#007700">,<br /> </font><font color="#DD0000">'db2_attr_case' </font><font color="#007700">=> </font><font color="#0000BB">DB2_CASE_UPPER</font><font color="#007700">,<br /> </font><font color="#DD0000">'cursor' </font><font color="#007700">=> </font><font color="#0000BB">DB2_SCROLLABLE</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Call the function using the correct resource, options array, and the wrong type value */<br /></font><font color="#0000BB">$result </font><font color="#007700">= </font><font color="#0000BB">db2_set_option</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#0000BB">$options</font><font color="#007700">, </font><font color="#0000BB">2</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Check if all options could be set correctly */<br /></font><font color="#007700">if(</font><font color="#0000BB">$result</font><font color="#007700">)<br />{<br /> echo </font><font color="#DD0000">'Options Set Successfully'</font><font color="#007700">; <br />}<br />else<br />{<br /> echo </font><font color="#DD0000">'Could Not Set Options'</font><font color="#007700">;<br />}<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P >O exemplo acima irá imprimir:</P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Could Not Set Options</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN78989" ></A ><P ><B >Exemplo 6. Setting multiple parameters with the wrong resource</B ></P ><P > </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#FF8000">/* Database Connection Parameters */<br /></font><font color="#0000BB">$database </font><font color="#007700">= </font><font color="#DD0000">'SAMPLE'</font><font color="#007700">;<br /></font><font color="#0000BB">$hostname </font><font color="#007700">= </font><font color="#DD0000">'localhost'</font><font color="#007700">;<br /></font><font color="#0000BB">$port </font><font color="#007700">= </font><font color="#0000BB">50000</font><font color="#007700">;<br /></font><font color="#0000BB">$protocol </font><font color="#007700">= </font><font color="#DD0000">'TCPIP'</font><font color="#007700">;<br /></font><font color="#0000BB">$username </font><font color="#007700">= </font><font color="#DD0000">'db2inst1'</font><font color="#007700">;<br /></font><font color="#0000BB">$password </font><font color="#007700">= </font><font color="#DD0000">'ibmdb2'</font><font color="#007700">;<br /><br /></font><font color="#FF8000">/* Connection String */<br /></font><font color="#0000BB">$conn_string </font><font color="#007700">= </font><font color="#DD0000">"DRIVER=</font><font color="#007700">{</font><font color="#DD0000">IBM DB2 ODBC DRIVER</font><font color="#007700">}</font><font color="#DD0000">;DATABASE=$database;"</font><font color="#007700">;<br /></font><font color="#0000BB">$conn_string </font><font color="#007700">.= </font><font color="#DD0000">"HOSTNAME=$hostname;PORT=$port;PROTOCOL=$protocol;"</font><font color="#007700">;<br /></font><font color="#0000BB">$conn_string </font><font color="#007700">.= </font><font color="#DD0000">"UID=$username;PWD=$password;"</font><font color="#007700">;<br /><br /></font><font color="#FF8000">/* Obtain Connection Resource */<br /></font><font color="#0000BB">$conn </font><font color="#007700">= </font><font color="#0000BB">db2_connect</font><font color="#007700">(</font><font color="#0000BB">$conn_string</font><font color="#007700">, </font><font color="#DD0000">''</font><font color="#007700">, </font><font color="#DD0000">''</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Create the associative options array with valid key-value pairs */<br /></font><font color="#0000BB">$options </font><font color="#007700">= array(</font><font color="#DD0000">'autocommit' </font><font color="#007700">=> </font><font color="#0000BB">DB2_AUTOCOMMIT_OFF</font><font color="#007700">, <br /> </font><font color="#DD0000">'binmode' </font><font color="#007700">=> </font><font color="#0000BB">DB2_PASSTHRU</font><font color="#007700">,<br /> </font><font color="#DD0000">'db2_attr_case' </font><font color="#007700">=> </font><font color="#0000BB">DB2_CASE_UPPER</font><font color="#007700">,<br /> </font><font color="#DD0000">'cursor' </font><font color="#007700">=> </font><font color="#0000BB">DB2_SCROLLABLE</font><font color="#007700">);<br /><br /></font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">db2_prepare</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#DD0000">'SELECT * FROM EMPLOYEE'</font><font color="#007700">); <br /><br /></font><font color="#FF8000">/* Call the function using the wrong resource, and the correct options array, and type values */<br /></font><font color="#0000BB">$result </font><font color="#007700">= </font><font color="#0000BB">db2_set_option</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">, </font><font color="#0000BB">$options</font><font color="#007700">, </font><font color="#0000BB">1</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Check if all options could be set correctly */<br /></font><font color="#007700">if(</font><font color="#0000BB">$result</font><font color="#007700">)<br />{<br /> echo </font><font color="#DD0000">'Options Set Successfully'</font><font color="#007700">; <br />}<br />else<br />{<br /> echo </font><font color="#DD0000">'Could Not Set Options'</font><font color="#007700">;<br />}<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P >O exemplo acima irá imprimir:</P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Could Not Set Options</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN78995" ></A ><P ><B >Exemplo 7. Putting it all together</B ></P ><P > </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#FF8000">/* Database Connection Parameters */<br /></font><font color="#0000BB">$database </font><font color="#007700">= </font><font color="#DD0000">'SAMPLE'</font><font color="#007700">;<br /></font><font color="#0000BB">$hostname </font><font color="#007700">= </font><font color="#DD0000">'localhost'</font><font color="#007700">;<br /></font><font color="#0000BB">$port </font><font color="#007700">= </font><font color="#0000BB">50000</font><font color="#007700">;<br /></font><font color="#0000BB">$protocol </font><font color="#007700">= </font><font color="#DD0000">'TCPIP'</font><font color="#007700">;<br /></font><font color="#0000BB">$username </font><font color="#007700">= </font><font color="#DD0000">'db2inst1'</font><font color="#007700">;<br /></font><font color="#0000BB">$password </font><font color="#007700">= </font><font color="#DD0000">'ibmdb2'</font><font color="#007700">;<br /><br /></font><font color="#FF8000">/* Connection String */<br /></font><font color="#0000BB">$conn_string </font><font color="#007700">= </font><font color="#DD0000">"DRIVER=</font><font color="#007700">{</font><font color="#DD0000">IBM DB2 ODBC DRIVER</font><font color="#007700">}</font><font color="#DD0000">;DATABASE=$database;"</font><font color="#007700">;<br /></font><font color="#0000BB">$conn_string </font><font color="#007700">.= </font><font color="#DD0000">"HOSTNAME=$hostname;PORT=$port;PROTOCOL=$protocol;"</font><font color="#007700">;<br /></font><font color="#0000BB">$conn_string </font><font color="#007700">.= </font><font color="#DD0000">"UID=$username;PWD=$password;"</font><font color="#007700">;<br /><br /></font><font color="#FF8000">/* Obtain Connection Resource */<br /></font><font color="#0000BB">$conn </font><font color="#007700">= </font><font color="#0000BB">db2_connect</font><font color="#007700">(</font><font color="#0000BB">$conn_string</font><font color="#007700">, </font><font color="#DD0000">''</font><font color="#007700">, </font><font color="#DD0000">''</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Create the associative options array with valid key-value pairs */<br /></font><font color="#0000BB">$options </font><font color="#007700">= array(</font><font color="#DD0000">'db2_attr_case' </font><font color="#007700">=> </font><font color="#0000BB">DB2_CASE_LOWER</font><font color="#007700">,<br /> </font><font color="#DD0000">'cursor' </font><font color="#007700">=> </font><font color="#0000BB">DB2_SCROLLABLE</font><font color="#007700">);<br /><br /></font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">db2_prepare</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#DD0000">'SELECT * FROM EMPLOYEE WHERE EMPNO = ? OR EMPNO = ?'</font><font color="#007700">);<br /><br /></font><font color="#FF8000">/* Call the function using the correct resource, options array, and type values */<br /></font><font color="#0000BB">$option_result </font><font color="#007700">= </font><font color="#0000BB">db2_set_option</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">, </font><font color="#0000BB">$options</font><font color="#007700">, </font><font color="#0000BB">2</font><font color="#007700">); <br /></font><font color="#0000BB">$result </font><font color="#007700">= </font><font color="#0000BB">db2_execute</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">, array(</font><font color="#DD0000">'000130'</font><font color="#007700">, </font><font color="#DD0000">'000140'</font><font color="#007700">));<br /><br /></font><font color="#FF8000">/* Get Row 2 before Row 1 since Scrollable Cursor */<br /></font><font color="#0000BB">print_r</font><font color="#007700">(</font><font color="#0000BB">db2_fetch_assoc</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">, </font><font color="#0000BB">2</font><font color="#007700">));<br />print </font><font color="#DD0000">'<br /><br />'</font><font color="#007700">;<br /></font><font color="#0000BB">print_r</font><font color="#007700">(</font><font color="#0000BB">db2_fetch_assoc</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">, </font><font color="#0000BB">1</font><font color="#007700">));<br /><br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P >O exemplo acima irá imprimir:</P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Array ( [empno] => 000140 [firstnme] => HEATHER [midinit] => A [lastname] => NICHOLLS [workdept] => C01 [phoneno] => 1793 [hiredate] => 1976-12-15 [job] => ANALYST [edlevel] => 18 [sex] => F [birthdate] => 1946-01-19 [salary] => 28420.00 [bonus] => 600.00 [comm] => 2274.00 ) Array ( [empno] => 000130 [firstnme] => DELORES [midinit] => M [lastname] => QUINTANA [workdept] => C01 [phoneno] => 4578 [hiredate] => 1971-07-28 [job] => ANALYST [edlevel] => 16 [sex] => F [birthdate] => 1925-09-15 [salary] => 23800.00 [bonus] => 500.00 [comm] => 1904.00 )</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN79001" ></A ><P ><B >Exemplo 8. i5/OS cursors are read-only</B ></P ><P > </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /> $conn </font><font color="#007700">= </font><font color="#0000BB">db2_connect</font><font color="#007700">(</font><font color="#DD0000">""</font><font color="#007700">, </font><font color="#DD0000">""</font><font color="#007700">, </font><font color="#DD0000">""</font><font color="#007700">, array(</font><font color="#DD0000">"i5_lib"</font><font color="#007700">=></font><font color="#DD0000">"nobody"</font><font color="#007700">));<br /> </font><font color="#0000BB">$stmt </font><font color="#007700">= </font><font color="#0000BB">db2_prepare</font><font color="#007700">(</font><font color="#0000BB">$conn</font><font color="#007700">, </font><font color="#DD0000">'select * from names where first = ?'</font><font color="#007700">);<br /> </font><font color="#0000BB">$name </font><font color="#007700">= </font><font color="#DD0000">"first2"</font><font color="#007700">;<br /> </font><font color="#0000BB">db2_bind_param</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">, </font><font color="#0000BB">1</font><font color="#007700">, </font><font color="#DD0000">"name"</font><font color="#007700">, </font><font color="#0000BB">DB2_PARAM_IN</font><font color="#007700">);<br /> </font><font color="#0000BB">$options </font><font color="#007700">= array(</font><font color="#DD0000">"i5_fetch_only"</font><font color="#007700">=></font><font color="#0000BB">DB2_I5_FETCH_ON</font><font color="#007700">);<br /> </font><font color="#0000BB">db2_set_option</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">,</font><font color="#0000BB">$options</font><font color="#007700">,</font><font color="#0000BB">0</font><font color="#007700">);<br /> if (</font><font color="#0000BB">db2_execute</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">)) {<br /> while (</font><font color="#0000BB">$row </font><font color="#007700">= </font><font color="#0000BB">db2_fetch_array</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">)) {<br /> echo </font><font color="#DD0000">"</font><font color="#007700">{</font><font color="#DD0000">$row</font><font color="#007700">[</font><font color="#DD0000">0</font><font color="#007700">]}</font><font color="#DD0000"> </font><font color="#007700">{</font><font color="#DD0000">$row</font><font color="#007700">[</font><font color="#DD0000">1</font><font color="#007700">]}</font><font color="#DD0000">"</font><font color="#007700">;<br /> }<br /> }<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P >O exemplo acima irá imprimir:</P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >first2 last2</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN79007" ></A ><H2 >Veja também</H2 ><P > <P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD ><A HREF="function.db2-connect.html" ><B CLASS="function" >db2_connect()</B ></A ></TD ></TR ><TR ><TD ><A HREF="function.db2-pconnect.html" ><B CLASS="function" >db2_pconnect()</B ></A ></TD ></TR ><TR ><TD ><A HREF="function.db2-exec.html" ><B CLASS="function" >db2_exec()</B ></A ></TD ></TR ><TR ><TD ><A HREF="function.db2-prepare.html" ><B CLASS="function" >db2_prepare()</B ></A ></TD ></TR ><TR ><TD ><A HREF="function.db2-cursor-type.html" ><B CLASS="function" >db2_cursor_type()</B ></A ></TD ></TR ></TBODY ></TABLE ><P ></P > </P ></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.db2-server-info.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.db2-special-columns.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >db2_server_info</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.ibm-db2.html" ACCESSKEY="U" >Acima</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >db2_special_columns</TD ></TR ></TABLE ></DIV ></BODY ></HTML >