Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > 05cd670d8a02b2b4a0ffb1756f2e8308 > files > 535

php-manual-zh-5.2.4-1mdv2008.1.noarch.rpm

<!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="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"
>PHP 手册</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.db2-server-info.html"
ACCESSKEY="P"
>上一页</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"
>下一页</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="AEN82866"
></A
><P
>    (PECL)</P
>db2_set_option&nbsp;--&nbsp;Set options for connection or statement resources</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN82869"
></A
><H2
>说明</H2
>bool <B
CLASS="methodname"
>db2_set_option</B
> ( resource resource, array options [, int type] )<BR
></BR
><P
>&#13;     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="AEN82884"
></A
><H2
>参数</H2
><P
>&#13;      <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><CODE
CLASS="parameter"
>resource</CODE
></DT
><DD
><P
>&#13;             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
>&#13;             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
>&#13;                     Passing <TT
CLASS="literal"
>DB2_AUTOCOMMIT_ON</TT
> turns
                     autocommit on for the specified connection resource.
                    </P
><P
>&#13;                     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
>&#13;                     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
>&#13;                     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
>&#13;                     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
>&#13;                     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
>&#13;                     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
>&#13;                     Passing <TT
CLASS="literal"
>DB2_CASE_LOWER</TT
> specifies that
                     column names of the result set are returned in lower case.
                    </P
><P
>&#13;                     Passing <TT
CLASS="literal"
>DB2_CASE_UPPER</TT
> specifies that
                     column names of the result set are returned in upper case.
                    </P
><P
>&#13;                     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
>&#13;                   Passing <TT
CLASS="literal"
>DB2_DEFERRED_PREPARE_ON</TT
> turns deferred 
                   prepare on for the specified statement resource.
                  </P
><P
>&#13;                   Passing <TT
CLASS="literal"
>DB2_DEFERRED_PREPARE_OFF</TT
> turns deferred 
                   prepare off for the specified statement resource.
                  </P
></DD
></DL
></DIV
>
            </P
><P
>&#13;             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
>&#13;                     <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
>&#13;                     <TT
CLASS="literal"
>DB2_I5_FETCH_OFF</TT
> - Cursors can be used 
                     for positioned updates and deletes.
                    </P
></DD
></DL
></DIV
>
            </P
><P
>&#13;             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
>&#13;               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
>&#13;               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
>&#13;                 <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
>&#13;                 <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
>&#13;                 <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
>&#13;                 <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
>&#13;             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
>&#13;                     Passing <TT
CLASS="literal"
>1</TT
> as the value specifies that
                     a connection resource has been passed into the function.
                    </P
><P
>&#13;                     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
>&#13;    </P
><P
>&#13;     The following table specifies which options are compatible with
     the available resource types:
      <DIV
CLASS="table"
><A
NAME="AEN83028"
></A
><P
><B
>表 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
>&nbsp;</TD
><TD
>&nbsp;</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="AEN83172"
></A
><H2
>返回值</H2
><P
>&#13;     如果成功则返回 <TT
CLASS="constant"
><B
>TRUE</B
></TT
>,失败则返回 <TT
CLASS="constant"
><B
>FALSE</B
></TT
>。
    </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN83177"
></A
><H2
>范例</H2
><P
>&#13;
      <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN83180"
></A
><P
><B
>例 1. Setting one parameter with a connection resource</B
></P
><P
>&#13;        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?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">=&gt; </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 />&nbsp;&nbsp;echo </font><font color="#DD0000">'Options Set Successfully'</font><font color="#007700">;&nbsp;&nbsp;&nbsp;&nbsp;<br />}<br />else<br />{<br />&nbsp;&nbsp;echo </font><font color="#DD0000">'Could Not Set Options'</font><font color="#007700">;<br />}<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>上例将输出:</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="AEN83186"
></A
><P
><B
>例 2. Setting multiple parameters with a connection resource</B
></P
><P
>&#13;        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?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">=&gt; </font><font color="#0000BB">DB2_AUTOCOMMIT_OFF</font><font color="#007700">, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'binmode' </font><font color="#007700">=&gt; </font><font color="#0000BB">DB2_PASSTHRU</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'db2_attr_case' </font><font color="#007700">=&gt; </font><font color="#0000BB">DB2_CASE_UPPER</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#DD0000">'cursor' </font><font color="#007700">=&gt; </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 />&nbsp;&nbsp;echo </font><font color="#DD0000">'Options Set Successfully'</font><font color="#007700">;<br />}<br />else<br />{<br />&nbsp;&nbsp;echo </font><font color="#DD0000">'Could Not Set Options'</font><font color="#007700">;<br />}<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>上例将输出:</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="AEN83192"
></A
><P
><B
>例 3. Setting multiple parameters with an invalid key</B
></P
><P
>&#13;        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?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">=&gt; </font><font color="#0000BB">DB2_AUTOCOMMIT_OFF</font><font color="#007700">, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'MY_INVALID_KEY' </font><font color="#007700">=&gt; </font><font color="#0000BB">DB2_PASSTHRU</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'db2_attr_case' </font><font color="#007700">=&gt; </font><font color="#0000BB">DB2_CASE_UPPER</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'cursor' </font><font color="#007700">=&gt; </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 />&nbsp;&nbsp;echo </font><font color="#DD0000">'Options Set Successfully'</font><font color="#007700">;&nbsp;&nbsp;&nbsp;&nbsp;<br />}<br />else<br />{<br />&nbsp;&nbsp;echo </font><font color="#DD0000">'Could Not Set Options'</font><font color="#007700">;<br />}<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>上例将输出:</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="AEN83198"
></A
><P
><B
>例 4. Setting multiple parameters with an invalid value</B
></P
><P
>&#13;        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?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">=&gt; </font><font color="#0000BB">DB2_AUTOCOMMIT_OFF</font><font color="#007700">, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'binmode' </font><font color="#007700">=&gt; </font><font color="#DD0000">'INVALID_VALUE'</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'db2_attr_case' </font><font color="#007700">=&gt; </font><font color="#0000BB">DB2_CASE_UPPER</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#DD0000">'cursor' </font><font color="#007700">=&gt; </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 />&nbsp;&nbsp;echo </font><font color="#DD0000">'Options Set Successfully'</font><font color="#007700">;&nbsp;&nbsp;&nbsp;&nbsp;<br />}<br />else<br />{<br />&nbsp;&nbsp;echo </font><font color="#DD0000">'Could Not Set Options'</font><font color="#007700">;<br />}<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>上例将输出:</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="AEN83204"
></A
><P
><B
>例 5. Setting multiple parameters with a connection resource and the wrong type</B
></P
><P
>&#13;        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?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">=&gt; </font><font color="#0000BB">DB2_AUTOCOMMIT_OFF</font><font color="#007700">, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'binmode' </font><font color="#007700">=&gt; </font><font color="#0000BB">DB2_PASSTHRU</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'db2_attr_case' </font><font color="#007700">=&gt; </font><font color="#0000BB">DB2_CASE_UPPER</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#DD0000">'cursor' </font><font color="#007700">=&gt; </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 />&nbsp;&nbsp;echo </font><font color="#DD0000">'Options Set Successfully'</font><font color="#007700">;&nbsp;&nbsp;&nbsp;&nbsp;<br />}<br />else<br />{<br />&nbsp;&nbsp;echo </font><font color="#DD0000">'Could Not Set Options'</font><font color="#007700">;<br />}<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>上例将输出:</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="AEN83210"
></A
><P
><B
>例 6. Setting multiple parameters with the wrong resource</B
></P
><P
>&#13;        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?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">=&gt; </font><font color="#0000BB">DB2_AUTOCOMMIT_OFF</font><font color="#007700">, <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'binmode' </font><font color="#007700">=&gt; </font><font color="#0000BB">DB2_PASSTHRU</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'db2_attr_case' </font><font color="#007700">=&gt; </font><font color="#0000BB">DB2_CASE_UPPER</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'cursor' </font><font color="#007700">=&gt; </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">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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 />&nbsp;&nbsp;echo </font><font color="#DD0000">'Options Set Successfully'</font><font color="#007700">;&nbsp;&nbsp;&nbsp;&nbsp;<br />}<br />else<br />{<br />&nbsp;&nbsp;echo </font><font color="#DD0000">'Could Not Set Options'</font><font color="#007700">;<br />}<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>上例将输出:</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="AEN83216"
></A
><P
><B
>例 7. Putting it all together</B
></P
><P
>&#13;        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?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">=&gt; </font><font color="#0000BB">DB2_CASE_LOWER</font><font color="#007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#DD0000">'cursor' </font><font color="#007700">=&gt; </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">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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">'&lt;br /&gt;&lt;br /&gt;'</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">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>上例将输出:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>Array
(
    [empno] =&#62; 000140
    [firstnme] =&#62; HEATHER
    [midinit] =&#62; A
    [lastname] =&#62; NICHOLLS
    [workdept] =&#62; C01
    [phoneno] =&#62; 1793
    [hiredate] =&#62; 1976-12-15
    [job] =&#62; ANALYST
    [edlevel] =&#62; 18
    [sex] =&#62; F
    [birthdate] =&#62; 1946-01-19
    [salary] =&#62; 28420.00
    [bonus] =&#62; 600.00
    [comm] =&#62; 2274.00
)

Array
(
    [empno] =&#62; 000130
    [firstnme] =&#62; DELORES
    [midinit] =&#62; M
    [lastname] =&#62; QUINTANA
    [workdept] =&#62; C01
    [phoneno] =&#62; 4578
    [hiredate] =&#62; 1971-07-28
    [job] =&#62; ANALYST
    [edlevel] =&#62; 16
    [sex] =&#62; F
    [birthdate] =&#62; 1925-09-15
    [salary] =&#62; 23800.00
    [bonus] =&#62; 500.00
    [comm] =&#62; 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="AEN83222"
></A
><P
><B
>例 8. i5/OS cursors are read-only</B
></P
><P
>&#13;        </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />&nbsp;&nbsp;$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">=&gt;</font><font color="#DD0000">"nobody"</font><font color="#007700">));<br />&nbsp;&nbsp;</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 />&nbsp;&nbsp;</font><font color="#0000BB">$name </font><font color="#007700">= </font><font color="#DD0000">"first2"</font><font color="#007700">;<br />&nbsp;&nbsp;</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 />&nbsp;&nbsp;</font><font color="#0000BB">$options </font><font color="#007700">= array(</font><font color="#DD0000">"i5_fetch_only"</font><font color="#007700">=&gt;</font><font color="#0000BB">DB2_I5_FETCH_ON</font><font color="#007700">);<br />&nbsp;&nbsp;</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 />&nbsp;&nbsp;if (</font><font color="#0000BB">db2_execute</font><font color="#007700">(</font><font color="#0000BB">$stmt</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;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 />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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 />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;}<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>上例将输出:</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="AEN83228"
></A
><H2
>参见</H2
><P
>&#13;      <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"
>上一页</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>起始页</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.db2-special-columns.html"
ACCESSKEY="N"
>下一页</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"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>db2_special_columns</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>