Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 2546

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Set options for connection or statement resources</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.db2-server-info.html">db2_server_info</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.db2-special-columns.html">db2_special_columns</a></div>
 <div class="up"><a href="ref.ibm-db2.html">IBM DB2 Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.db2-set-option" class="refentry">
  <div class="refnamediv">
    <h1 class="refname">db2_set_option</h1>
    <p class="verinfo">(PECL ibm_db2 &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">db2_set_option</span> &mdash; <span class="dc-title">Set options for connection or statement resources</span></p>

  </div>
  <div class="refsect1 description" id="refsect1-function.db2-set-option-description">
    <h3 class="title">Description</h3>
    <div class="methodsynopsis dc-description">
      <span class="type">bool</span> <span class="methodname"><strong>db2_set_option</strong></span>
       ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$resource</code></span>      
      , <span class="methodparam"><span class="type">array</span> <code class="parameter">$options</code></span>
      , <span class="methodparam"><span class="type">int</span> <code class="parameter">$type</code></span>
     )</div>

    <p class="para rdfs-comment">
     Sets options for a statement resource or a connection resource. You
     cannot set options for result set resources. 
    </p>
  </div>

  <div class="refsect1 parameters" id="refsect1-function.db2-set-option-parameters">
    <h3 class="title">Parameters</h3>
    <p class="para">
      <dl>

        <dt>

          <span class="term"><em><code class="parameter">resource</code></em></span>
          <dd>

            <p class="para">
             A valid statement resource as returned from
              <span class="function"><a href="function.db2-prepare.html" class="function">db2_prepare()</a></span> or a valid connection resource as
             returned from  <span class="function"><a href="function.db2-connect.html" class="function">db2_connect()</a></span> or
              <span class="function"><a href="function.db2-pconnect.html" class="function">db2_pconnect()</a></span>.
            </p>
          </dd>

        </dt>

        <dt>

          <span class="term"><em><code class="parameter">options</code></em></span>
          <dd>

            <p class="para">
             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.
              <dl>

                <dt>

                  <span class="term"><em><code class="parameter">autocommit</code></em></span>
                  <dd>

                    <p class="para">
                     Passing <em>DB2_AUTOCOMMIT_ON</em> turns
                     autocommit on for the specified connection resource.
                    </p>
                    <p class="para">
                     Passing <em>DB2_AUTOCOMMIT_OFF</em> turns
                     autocommit off for the specified connection resource.
                    </p>
                  </dd>

                </dt>

                <dt>

                  <span class="term"><em><code class="parameter">cursor</code></em></span>
                  <dd>

                    <p class="para">
                     Passing <em>DB2_FORWARD_ONLY</em> specifies a
                     forward-only cursor for a statement resource. This is the
                     default cursor type, and is supported by all database
                     servers.
                    </p>
                    <p class="para">
                     Passing <em>DB2_SCROLLABLE</em> 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>

                <dt>

                  <span class="term"><em><code class="parameter">binmode</code></em></span>
                  <dd>

                    <p class="para">
                     Passing <em>DB2_BINARY</em> specifies that
                     binary data will be returned as is. This is the default
                     mode. This is the equivalent of setting
                     <em>ibm_db2.binmode=1</em> in <var class="filename">php.ini</var>.
                    </p>
                    <p class="para">
                     Passing <em>DB2_CONVERT</em> specifies that
                     binary data will be converted to hexadecimal encoding,
                     and will be returned as such. This is the equivalent of
                     setting <em>ibm_db2.binmode=2</em> in <var class="filename">php.ini</var>.
                    </p>
                    <p class="para">
                     Passing <em>DB2_PASSTHRU</em> specifies that
                     binary data will be converted to <strong><code>NULL</code></strong>. This is the
                     equivalent of setting <em>ibm_db2.binmode=3</em>
                     in <var class="filename">php.ini</var>.
                    </p>
                  </dd>

                </dt>

                <dt>

                  <span class="term"><em><code class="parameter">db2_attr_case</code></em></span>
                  <dd>

                    <p class="para">
                     Passing <em>DB2_CASE_LOWER</em> specifies that
                     column names of the result set are returned in lower case.
                    </p>
                    <p class="para">
                     Passing <em>DB2_CASE_UPPER</em> specifies that
                     column names of the result set are returned in upper case.
                    </p>
                    <p class="para">
                     Passing <em>DB2_CASE_NATURAL</em> specifies that
                     column names of the result set are returned in natural
                     case.
                    </p>
                  </dd>

                </dt>

                <dt>

                 <span class="term"><em><code class="parameter">deferred_prepare</code></em></span>
                 <dd>

                  <p class="para">
                   Passing <em>DB2_DEFERRED_PREPARE_ON</em> turns deferred 
                   prepare on for the specified statement resource.
                  </p>
                  <p class="para">
                   Passing <em>DB2_DEFERRED_PREPARE_OFF</em> turns deferred 
                   prepare off for the specified statement resource.
                  </p>
                 </dd>

                </dt>
                
              </dl>

            </p>
            <p class="para">
             The following new i5/OS options are available in ibm_db2 version 1.5.1 
             and later. These options apply only when running PHP and ibm_db2 natively on i5 systems.
              <dl>

                <dt>

                  <span class="term"><em><code class="parameter">i5_fetch_only</code></em></span>
                  <dd>

                    <p class="para">
                     <em>DB2_I5_FETCH_ON</em> - Cursors are read-only 
                     and cannot be used for positioned updates or deletes. This 
                     is the default unless <em>SQL_ATTR_FOR_FETCH_ONLY</em> 
                     environment has been set to <em>SQL_FALSE</em>.
                    </p>
                    <p class="para">
                     <em>DB2_I5_FETCH_OFF</em> - Cursors can be used 
                     for positioned updates and deletes.
                    </p>
                  </dd>

                </dt>

               </dl>

            </p>
            <p class="para">
             The following new option is available in ibm_db2 version 1.8.0 and later.
              <dl>

                <dt>

                  <span class="term"><em><code class="parameter">rowcount</code></em></span>
                  <dd>

                    <p class="para">
                     <em>DB2_ROWCOUNT_PREFETCH_ON</em> - Client can request 
                     the full row count prior to fetching, which means that 
                      <span class="function"><a href="function.db2-num-rows.html" class="function">db2_num_rows()</a></span> returns the number of rows selected 
                     even when a <em>ROLLFORWARD_ONLY</em> cursor is used.
                    </p>
                    <p class="para">
                     <em>DB2_ROWCOUNT_PREFETCH_OFF</em> - Client cannot request
                     the full row count prior to fetching.
                    </p>
                  </dd>

                </dt>

              </dl>

            </p>            
            <p class="para">
             The following new options are available in ibm_db2 version 1.7.0 and later.
              <dl>

                <dt>

                  <span class="term"><em><code class="parameter">trusted_user</code></em></span>
                  <dd>

                    <p class="para">
                     To switch the user to a trusted user, pass the User ID (String) 
                     of the trusted user as the value of this key. This option can 
                     be set on a connection resource only. To use this option, trusted
                     context must be enabled on the connection resource.
                    </p>
                  </dd>

                </dt>

                <dt>

                  <span class="term"><em><code class="parameter">trusted_password</code></em></span>
                  <dd>

                    <p class="para">
                     The password (String) that corresponds to the user specified
                     by the trusted_user key.
                    </p>
                  </dd>

                </dt>
                
               </dl>

            </p>            
            <p class="para">
             The following new options are available in ibm_db2 version 1.6.0 and later. 
             These options provide useful tracking information that can be accessed during 
             execution with  <span class="function"><a href="function.db2-get-option.html" class="function">db2_get_option()</a></span>.
             <blockquote class="note"><p><strong class="note">Note</strong>: 
              <p class="para">
               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 class="para">
               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>
             </p></blockquote>
             <dl>

              <dt>

               <span class="term"><em><code class="parameter">userid</code></em></span>
               <dd>

                <p class="para">
                 <em>SQL_ATTR_INFO_USERID</em> - 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.
                 <blockquote class="note"><p><strong class="note">Note</strong>: 
                  <p class="para">
                   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>
                 </p></blockquote>
                </p>
               </dd>

              </dt>

              <dt>

               <span class="term"><em><code class="parameter">acctstr</code></em></span>
               <dd>

                <p class="para">
                 <em>SQL_ATTR_INFO_ACCTSTR</em> - 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.
                 <blockquote class="note"><p><strong class="note">Note</strong>: 
                  <p class="para">
                   DB2 for z/OS and OS/390 servers support up to a length of 200 characters.
                  </p>
                 </p></blockquote>
                </p>
               </dd>

              </dt>

              <dt>

               <span class="term"><em><code class="parameter">applname</code></em></span>
               <dd>

                <p class="para">
                 <em>SQL_ATTR_INFO_APPLNAME</em> - 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.
                 <blockquote class="note"><p><strong class="note">Note</strong>: 
                  <p class="para">
                   DB2 for z/OS and OS/390 servers support up to a length of 32 characters.
                  </p>
                 </p></blockquote>
                </p>
               </dd>

              </dt>

              <dt>

               <span class="term"><em><code class="parameter">wrkstnname</code></em></span>
               <dd>

                <p class="para">
                 <em>SQL_ATTR_INFO_WRKSTNNAME</em> - 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.
                 <blockquote class="note"><p><strong class="note">Note</strong>: 
                  <p class="para">
                   DB2 for z/OS and OS/390 servers support up to a length of 18 characters.
                  </p>
                 </p></blockquote>
                </p>
               </dd>

              </dt>

             </dl>

            </p>
          </dd>

        </dt>

        <dt>

          <span class="term"><em><code class="parameter">type</code></em></span>
          <dd>

            <p class="para">
             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 class="para">
             Passing <em>1</em> as the value specifies that
             a connection resource has been passed into the function.
            </p>
            <p class="para">
             Passing any integer not equal to <em>1</em> as
             the value specifies that a statement resource has been
             passed into the function.
            </p>
          </dd>

        </dt>

      </dl>

    </p>
    <p class="para">
    </p>
    <p class="para">
     The following table specifies which options are compatible with
     the available resource types:
      <table class="doctable table">
        <caption><strong>Resource-Parameter Matrix</strong></caption>
        
          <col style="text-align: center;" />
          <col style="text-align: center;" />
          <col style="text-align: center;" />
          <col style="text-align: center;" />
          <col style="text-align: center;" />
          
          <thead>
            <tr>
              <th>Key</th>
              <th>Value</th>
              <th colspan="3">Resource Type</th>
            </tr>

          </thead>


          <tbody class="tbody">
            <tr>
              <td class="empty">&nbsp;</td><td class="empty">&nbsp;</td><td>Connection</td>
              <td>Statement</td>
              <td>Result Set</td>
            </tr>

            <tr>
              <td>autocommit</td>
              <td><em>DB2_AUTOCOMMIT_ON</em></td>
              <td>X</td>
              <td>-</td>
              <td>-</td>
            </tr>

            <tr>
              <td>autocommit</td>
              <td><em>DB2_AUTOCOMMIT_OFF</em></td>
              <td>X</td>
              <td>-</td>
              <td>-</td>
            </tr>

            <tr>
              <td>cursor</td>
              <td><em>DB2_SCROLLABLE</em></td>
              <td>-</td>
              <td>X</td>
              <td>-</td>
            </tr>

            <tr>
              <td>cursor</td>
              <td><em>DB2_FORWARD_ONLY</em></td>
              <td>-</td>
              <td>X</td>
              <td>-</td>
            </tr>

            <tr>
              <td>binmode</td>
              <td><em>DB2_BINARY</em></td>
              <td>X</td>
              <td>X</td>
              <td>-</td>
            </tr>

            <tr>
              <td>binmode</td>
              <td><em>DB2_CONVERT</em></td>
              <td>X</td>
              <td>X</td>
              <td>-</td>
            </tr>

            <tr>
              <td>binmode</td>
              <td><em>DB2_PASSTHRU</em></td>
              <td>X</td>
              <td>X</td>
              <td>-</td>
            </tr>

            <tr>
              <td>db2_attr_case</td>
              <td><em>DB2_CASE_LOWER</em></td>
              <td>X</td>
              <td>X</td>
              <td>-</td>
            </tr>

            <tr>
              <td>db2_attr_case</td>
              <td><em>DB2_CASE_UPPER</em></td>
              <td>X</td>
              <td>X</td>
              <td>-</td>
            </tr>

            <tr>
              <td>db2_attr_case</td>
              <td><em>DB2_CASE_NATURAL</em></td>
              <td>X</td>
              <td>X</td>
              <td>-</td>
            </tr>

            <tr>
              <td>deferred_prepare</td>
              <td><em>DB2_DEFERRED_PREPARE_ON</em></td>
              <td>-</td>
              <td>X</td>
              <td>-</td>
            </tr>

            <tr>
              <td>deferred_prepare</td>
              <td><em>DB2_DEFERRED_PREPARE_OFF</em></td>
              <td>-</td>
              <td>X</td>
              <td>-</td>
            </tr>

            <tr>
              <td>i5_fetch_only</td>
              <td><em>DB2_I5_FETCH_ON</em></td>
              <td>-</td>
              <td>X</td>
              <td>-</td>
            </tr>

            <tr>
              <td>i5_fetch_only</td>
              <td><em>DB2_I5_FETCH_OFF</em></td>
              <td>-</td>
              <td>X</td>
              <td>-</td>
            </tr>

            <tr>
              <td>rowcount</td>
              <td><em>DB2_ROWCOUNT_PREFETCH_ON</em></td>
              <td>-</td>
              <td>X</td>
              <td>-</td>
            </tr>

            <tr>
              <td>rowcount</td>
              <td><em>DB2_ROWCOUNT_PREFETCH_OFF</em></td>
              <td>-</td>
              <td>X</td>
              <td>-</td>
            </tr>

            <tr>
              <td>trusted_user</td>
              <td><em>&lt;USER NAME&gt; (String)</em></td>
              <td>X</td>
              <td>-</td>
              <td>-</td>
            </tr>

            <tr>
              <td>trusted_password</td>
              <td><em>&lt;PASSWORD&gt; (String)</em></td>
              <td>X</td>
              <td>-</td>
              <td>-</td>
            </tr>

            <tr>
              <td>userid</td>
              <td><em>SQL_ATTR_INFO_USERID</em></td>
              <td>X</td>
              <td>X</td>
              <td>-</td>
            </tr>

            <tr>
              <td>acctstr</td>
              <td><em>SQL_ATTR_INFO_ACCTSTR</em></td>
              <td>X</td>
              <td>X</td>
              <td>-</td>
            </tr>

            <tr>
              <td>applname</td>
              <td><em>SQL_ATTR_INFO_APPLNAME</em></td>
              <td>X</td>
              <td>X</td>
              <td>-</td>
            </tr>

            <tr>
              <td>wrkstnname</td>
              <td><em>SQL_ATTR_INFO_WRKSTNNAME</em></td>
              <td>X</td>
              <td>X</td>
              <td>-</td>
            </tr>

          </tbody>
        
      </table>

    </p>
  </div>

  
  <div class="refsect1 returnvalues" id="refsect1-function.db2-set-option-returnvalues">
    <h3 class="title">Return Values</h3>
    <p class="para">
     Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure.
    </p>
  </div>

  
  
  
  <div class="refsect1 examples" id="refsect1-function.db2-set-option-examples">
    <h3 class="title">Examples</h3>
    <p class="para">

      <div class="example" id="example-1184">
        <p><strong>Example #1 Setting one parameter with a connection resource</strong></p>
        <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Database&nbsp;Connection&nbsp;Parameters&nbsp;*/<br /></span><span style="color: #0000BB">$database&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'SAMPLE'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$hostname&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'localhost'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$port&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">50000</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$protocol&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'TCPIP'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$username&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'db2inst1'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$password&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'ibmdb2'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/*&nbsp;Connection&nbsp;String&nbsp;*/<br /></span><span style="color: #0000BB">$conn_string&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"DRIVER={IBM&nbsp;DB2&nbsp;ODBC&nbsp;DRIVER};DATABASE=</span><span style="color: #0000BB">$database</span><span style="color: #DD0000">;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$conn_string&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #DD0000">"HOSTNAME=</span><span style="color: #0000BB">$hostname</span><span style="color: #DD0000">;PORT=</span><span style="color: #0000BB">$port</span><span style="color: #DD0000">;PROTOCOL=</span><span style="color: #0000BB">$protocol</span><span style="color: #DD0000">;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$conn_string&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #DD0000">"UID=</span><span style="color: #0000BB">$username</span><span style="color: #DD0000">;PWD=</span><span style="color: #0000BB">$password</span><span style="color: #DD0000">;"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/*&nbsp;Obtain&nbsp;Connection&nbsp;Resource&nbsp;*/<br /></span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn_string</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Create&nbsp;the&nbsp;associative&nbsp;options&nbsp;array&nbsp;with&nbsp;valid&nbsp;key-value&nbsp;pairs&nbsp;*/<br /></span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'autocommit'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_AUTOCOMMIT_ON</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Call&nbsp;the&nbsp;function&nbsp;using&nbsp;the&nbsp;correct&nbsp;resource,&nbsp;options&nbsp;array,&nbsp;and&nbsp;type&nbsp;values&nbsp;*/<br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_set_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$options</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Check&nbsp;if&nbsp;all&nbsp;options&nbsp;could&nbsp;be&nbsp;set&nbsp;correctly&nbsp;*/<br /></span><span style="color: #007700">if(</span><span style="color: #0000BB">$result</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Options&nbsp;Set&nbsp;Successfully'</span><span style="color: #007700">;<br />}<br />else<br />{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Could&nbsp;Not&nbsp;Set&nbsp;Options'</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
        </div>

        <div class="example-contents"><p>The above example will output:</p></div>
        <div class="example-contents screen"><div class="cdata"><pre>Options Set Successfully</pre></div></div>
      </div>

      <div class="example" id="example-1185">
        <p><strong>Example #2 Setting multiple parameters with a connection resource</strong></p>
        <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Database&nbsp;Connection&nbsp;Parameters&nbsp;*/<br /></span><span style="color: #0000BB">$database&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'SAMPLE'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$hostname&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'localhost'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$port&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">50000</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$protocol&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'TCPIP'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$username&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'db2inst1'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$password&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'ibmdb2'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/*&nbsp;Connection&nbsp;String&nbsp;*/<br /></span><span style="color: #0000BB">$conn_string&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"DRIVER={IBM&nbsp;DB2&nbsp;ODBC&nbsp;DRIVER};DATABASE=</span><span style="color: #0000BB">$database</span><span style="color: #DD0000">;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$conn_string&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #DD0000">"HOSTNAME=</span><span style="color: #0000BB">$hostname</span><span style="color: #DD0000">;PORT=</span><span style="color: #0000BB">$port</span><span style="color: #DD0000">;PROTOCOL=</span><span style="color: #0000BB">$protocol</span><span style="color: #DD0000">;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$conn_string&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #DD0000">"UID=</span><span style="color: #0000BB">$username</span><span style="color: #DD0000">;PWD=</span><span style="color: #0000BB">$password</span><span style="color: #DD0000">;"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/*&nbsp;Obtain&nbsp;Connection&nbsp;Resource&nbsp;*/<br /></span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn_string</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Create&nbsp;the&nbsp;associative&nbsp;options&nbsp;array&nbsp;with&nbsp;valid&nbsp;key-value&nbsp;pairs&nbsp;*/<br /></span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'autocommit'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_AUTOCOMMIT_OFF</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'binmode'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_PASSTHRU</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'db2_attr_case'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_CASE_UPPER</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'cursor'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_SCROLLABLE</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Call&nbsp;the&nbsp;function&nbsp;using&nbsp;the&nbsp;correct&nbsp;resource,&nbsp;options&nbsp;array,&nbsp;and&nbsp;type&nbsp;values&nbsp;*/<br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_set_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$options</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Check&nbsp;if&nbsp;all&nbsp;options&nbsp;could&nbsp;be&nbsp;set&nbsp;correctly&nbsp;*/<br /></span><span style="color: #007700">if(</span><span style="color: #0000BB">$result</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Options&nbsp;Set&nbsp;Successfully'</span><span style="color: #007700">;<br />}<br />else<br />{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Could&nbsp;Not&nbsp;Set&nbsp;Options'</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
        </div>

        <div class="example-contents"><p>The above example will output:</p></div>
        <div class="example-contents screen"><div class="cdata"><pre>Options Set Successfully</pre></div></div>
      </div>

      
      <div class="example" id="example-1186">
        <p><strong>Example #3 Setting multiple parameters with an invalid key</strong></p>
        <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Database&nbsp;Connection&nbsp;Parameters&nbsp;*/<br /></span><span style="color: #0000BB">$database&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'SAMPLE'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$hostname&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'localhost'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$port&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">50000</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$protocol&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'TCPIP'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$username&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'db2inst1'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$password&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'ibmdb2'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/*&nbsp;Connection&nbsp;String&nbsp;*/<br /></span><span style="color: #0000BB">$conn_string&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"DRIVER={IBM&nbsp;DB2&nbsp;ODBC&nbsp;DRIVER};DATABASE=</span><span style="color: #0000BB">$database</span><span style="color: #DD0000">;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$conn_string&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #DD0000">"HOSTNAME=</span><span style="color: #0000BB">$hostname</span><span style="color: #DD0000">;PORT=</span><span style="color: #0000BB">$port</span><span style="color: #DD0000">;PROTOCOL=</span><span style="color: #0000BB">$protocol</span><span style="color: #DD0000">;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$conn_string&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #DD0000">"UID=</span><span style="color: #0000BB">$username</span><span style="color: #DD0000">;PWD=</span><span style="color: #0000BB">$password</span><span style="color: #DD0000">;"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/*&nbsp;Obtain&nbsp;Connection&nbsp;Resource&nbsp;*/<br /></span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn_string</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Create&nbsp;the&nbsp;associative&nbsp;options&nbsp;array&nbsp;with&nbsp;valid&nbsp;key-value&nbsp;pairs&nbsp;*/<br /></span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'autocommit'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_AUTOCOMMIT_OFF</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'MY_INVALID_KEY'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_PASSTHRU</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'db2_attr_case'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_CASE_UPPER</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'cursor'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_SCROLLABLE</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Call&nbsp;the&nbsp;function&nbsp;using&nbsp;the&nbsp;correct&nbsp;resource,&nbsp;options&nbsp;array,&nbsp;and&nbsp;type&nbsp;values&nbsp;*/<br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_set_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$options</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Check&nbsp;if&nbsp;all&nbsp;options&nbsp;could&nbsp;be&nbsp;set&nbsp;correctly&nbsp;*/<br /></span><span style="color: #007700">if(</span><span style="color: #0000BB">$result</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Options&nbsp;Set&nbsp;Successfully'</span><span style="color: #007700">;<br />}<br />else<br />{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Could&nbsp;Not&nbsp;Set&nbsp;Options'</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
        </div>

        <div class="example-contents"><p>The above example will output:</p></div>
        <div class="example-contents screen"><div class="cdata"><pre>Could Not Set Options</pre></div></div>
      </div>

      
      <div class="example" id="example-1187">
        <p><strong>Example #4 Setting multiple parameters with an invalid value</strong></p>
        <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Database&nbsp;Connection&nbsp;Parameters&nbsp;*/<br /></span><span style="color: #0000BB">$database&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'SAMPLE'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$hostname&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'localhost'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$port&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">50000</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$protocol&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'TCPIP'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$username&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'db2inst1'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$password&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'ibmdb2'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/*&nbsp;Connection&nbsp;String&nbsp;*/<br /></span><span style="color: #0000BB">$conn_string&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"DRIVER={IBM&nbsp;DB2&nbsp;ODBC&nbsp;DRIVER};DATABASE=</span><span style="color: #0000BB">$database</span><span style="color: #DD0000">;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$conn_string&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #DD0000">"HOSTNAME=</span><span style="color: #0000BB">$hostname</span><span style="color: #DD0000">;PORT=</span><span style="color: #0000BB">$port</span><span style="color: #DD0000">;PROTOCOL=</span><span style="color: #0000BB">$protocol</span><span style="color: #DD0000">;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$conn_string&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #DD0000">"UID=</span><span style="color: #0000BB">$username</span><span style="color: #DD0000">;PWD=</span><span style="color: #0000BB">$password</span><span style="color: #DD0000">;"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/*&nbsp;Obtain&nbsp;Connection&nbsp;Resource&nbsp;*/<br /></span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn_string</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Create&nbsp;the&nbsp;associative&nbsp;options&nbsp;array&nbsp;with&nbsp;valid&nbsp;key-value&nbsp;pairs&nbsp;*/<br /></span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'autocommit'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_AUTOCOMMIT_OFF</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'binmode'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'INVALID_VALUE'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'db2_attr_case'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_CASE_UPPER</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'cursor'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_SCROLLABLE</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Call&nbsp;the&nbsp;function&nbsp;using&nbsp;the&nbsp;correct&nbsp;resource,&nbsp;options&nbsp;array,&nbsp;and&nbsp;type&nbsp;values&nbsp;*/<br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_set_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$options</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Check&nbsp;if&nbsp;all&nbsp;options&nbsp;could&nbsp;be&nbsp;set&nbsp;correctly&nbsp;*/<br /></span><span style="color: #007700">if(</span><span style="color: #0000BB">$result</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Options&nbsp;Set&nbsp;Successfully'</span><span style="color: #007700">;<br />}<br />else<br />{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Could&nbsp;Not&nbsp;Set&nbsp;Options'</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
        </div>

        <div class="example-contents"><p>The above example will output:</p></div>
        <div class="example-contents screen"><div class="cdata"><pre>Could Not Set Options</pre></div></div>
      </div>

      <div class="example" id="example-1188">
        <p><strong>Example #5 Setting multiple parameters with a connection resource and the wrong type</strong></p>
        <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Database&nbsp;Connection&nbsp;Parameters&nbsp;*/<br /></span><span style="color: #0000BB">$database&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'SAMPLE'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$hostname&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'localhost'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$port&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">50000</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$protocol&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'TCPIP'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$username&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'db2inst1'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$password&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'ibmdb2'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/*&nbsp;Connection&nbsp;String&nbsp;*/<br /></span><span style="color: #0000BB">$conn_string&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"DRIVER={IBM&nbsp;DB2&nbsp;ODBC&nbsp;DRIVER};DATABASE=</span><span style="color: #0000BB">$database</span><span style="color: #DD0000">;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$conn_string&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #DD0000">"HOSTNAME=</span><span style="color: #0000BB">$hostname</span><span style="color: #DD0000">;PORT=</span><span style="color: #0000BB">$port</span><span style="color: #DD0000">;PROTOCOL=</span><span style="color: #0000BB">$protocol</span><span style="color: #DD0000">;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$conn_string&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #DD0000">"UID=</span><span style="color: #0000BB">$username</span><span style="color: #DD0000">;PWD=</span><span style="color: #0000BB">$password</span><span style="color: #DD0000">;"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/*&nbsp;Obtain&nbsp;Connection&nbsp;Resource&nbsp;*/<br /></span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn_string</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Create&nbsp;the&nbsp;associative&nbsp;options&nbsp;array&nbsp;with&nbsp;valid&nbsp;key-value&nbsp;pairs&nbsp;*/<br /></span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'autocommit'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_AUTOCOMMIT_OFF</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'binmode'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_PASSTHRU</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'db2_attr_case'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_CASE_UPPER</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'cursor'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_SCROLLABLE</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Call&nbsp;the&nbsp;function&nbsp;using&nbsp;the&nbsp;correct&nbsp;resource,&nbsp;options&nbsp;array,&nbsp;and&nbsp;the&nbsp;wrong&nbsp;type&nbsp;value&nbsp;*/<br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_set_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$options</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Check&nbsp;if&nbsp;all&nbsp;options&nbsp;could&nbsp;be&nbsp;set&nbsp;correctly&nbsp;*/<br /></span><span style="color: #007700">if(</span><span style="color: #0000BB">$result</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Options&nbsp;Set&nbsp;Successfully'</span><span style="color: #007700">;<br />}<br />else<br />{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Could&nbsp;Not&nbsp;Set&nbsp;Options'</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
        </div>

        <div class="example-contents"><p>The above example will output:</p></div>
        <div class="example-contents screen"><div class="cdata"><pre>Could Not Set Options</pre></div></div>
      </div>

      <div class="example" id="example-1189">
        <p><strong>Example #6 Setting multiple parameters with the wrong resource</strong></p>
        <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Database&nbsp;Connection&nbsp;Parameters&nbsp;*/<br /></span><span style="color: #0000BB">$database&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'SAMPLE'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$hostname&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'localhost'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$port&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">50000</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$protocol&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'TCPIP'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$username&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'db2inst1'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$password&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'ibmdb2'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/*&nbsp;Connection&nbsp;String&nbsp;*/<br /></span><span style="color: #0000BB">$conn_string&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"DRIVER={IBM&nbsp;DB2&nbsp;ODBC&nbsp;DRIVER};DATABASE=</span><span style="color: #0000BB">$database</span><span style="color: #DD0000">;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$conn_string&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #DD0000">"HOSTNAME=</span><span style="color: #0000BB">$hostname</span><span style="color: #DD0000">;PORT=</span><span style="color: #0000BB">$port</span><span style="color: #DD0000">;PROTOCOL=</span><span style="color: #0000BB">$protocol</span><span style="color: #DD0000">;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$conn_string&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #DD0000">"UID=</span><span style="color: #0000BB">$username</span><span style="color: #DD0000">;PWD=</span><span style="color: #0000BB">$password</span><span style="color: #DD0000">;"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/*&nbsp;Obtain&nbsp;Connection&nbsp;Resource&nbsp;*/<br /></span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn_string</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Create&nbsp;the&nbsp;associative&nbsp;options&nbsp;array&nbsp;with&nbsp;valid&nbsp;key-value&nbsp;pairs&nbsp;*/<br /></span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'autocommit'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_AUTOCOMMIT_OFF</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'binmode'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_PASSTHRU</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'db2_attr_case'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_CASE_UPPER</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'cursor'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_SCROLLABLE</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'SELECT&nbsp;*&nbsp;FROM&nbsp;EMPLOYEE'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Call&nbsp;the&nbsp;function&nbsp;using&nbsp;the&nbsp;wrong&nbsp;resource,&nbsp;and&nbsp;the&nbsp;correct&nbsp;options&nbsp;array,&nbsp;and&nbsp;type&nbsp;values&nbsp;*/<br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_set_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$options</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Check&nbsp;if&nbsp;all&nbsp;options&nbsp;could&nbsp;be&nbsp;set&nbsp;correctly&nbsp;*/<br /></span><span style="color: #007700">if(</span><span style="color: #0000BB">$result</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Options&nbsp;Set&nbsp;Successfully'</span><span style="color: #007700">;<br />}<br />else<br />{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Could&nbsp;Not&nbsp;Set&nbsp;Options'</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
        </div>

        <div class="example-contents"><p>The above example will output:</p></div>
        <div class="example-contents screen"><div class="cdata"><pre>Could Not Set Options</pre></div></div>
      </div>

      <div class="example" id="example-1190">
        <p><strong>Example #7 Putting it all together</strong></p>
        <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Database&nbsp;Connection&nbsp;Parameters&nbsp;*/<br /></span><span style="color: #0000BB">$database&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'SAMPLE'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$hostname&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'localhost'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$port&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">50000</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$protocol&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'TCPIP'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$username&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'db2inst1'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$password&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'ibmdb2'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/*&nbsp;Connection&nbsp;String&nbsp;*/<br /></span><span style="color: #0000BB">$conn_string&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"DRIVER={IBM&nbsp;DB2&nbsp;ODBC&nbsp;DRIVER};DATABASE=</span><span style="color: #0000BB">$database</span><span style="color: #DD0000">;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$conn_string&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #DD0000">"HOSTNAME=</span><span style="color: #0000BB">$hostname</span><span style="color: #DD0000">;PORT=</span><span style="color: #0000BB">$port</span><span style="color: #DD0000">;PROTOCOL=</span><span style="color: #0000BB">$protocol</span><span style="color: #DD0000">;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$conn_string&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #DD0000">"UID=</span><span style="color: #0000BB">$username</span><span style="color: #DD0000">;PWD=</span><span style="color: #0000BB">$password</span><span style="color: #DD0000">;"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/*&nbsp;Obtain&nbsp;Connection&nbsp;Resource&nbsp;*/<br /></span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn_string</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Create&nbsp;the&nbsp;associative&nbsp;options&nbsp;array&nbsp;with&nbsp;valid&nbsp;key-value&nbsp;pairs&nbsp;*/<br /></span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'db2_attr_case'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_CASE_LOWER</span><span style="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;</span><span style="color: #DD0000">'cursor'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_SCROLLABLE</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'SELECT&nbsp;*&nbsp;FROM&nbsp;EMPLOYEE&nbsp;WHERE&nbsp;EMPNO&nbsp;=&nbsp;?&nbsp;OR&nbsp;EMPNO&nbsp;=&nbsp;?'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Call&nbsp;the&nbsp;function&nbsp;using&nbsp;the&nbsp;correct&nbsp;resource,&nbsp;options&nbsp;array,&nbsp;and&nbsp;type&nbsp;values&nbsp;*/<br /></span><span style="color: #0000BB">$option_result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_set_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$options</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">'000130'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'000140'</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">/*&nbsp;Get&nbsp;Row&nbsp;2&nbsp;before&nbsp;Row&nbsp;1&nbsp;since&nbsp;Scrollable&nbsp;Cursor&nbsp;*/<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">db2_fetch_assoc</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">));<br />print&nbsp;</span><span style="color: #DD0000">'&lt;br&nbsp;/&gt;&lt;br&nbsp;/&gt;'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">db2_fetch_assoc</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
        </div>

        <div class="example-contents"><p>The above example will output:</p></div>
        <div class="example-contents screen"><div class="cdata"><pre>Array
(
    [empno] =&gt; 000140
    [firstnme] =&gt; HEATHER
    [midinit] =&gt; A
    [lastname] =&gt; NICHOLLS
    [workdept] =&gt; C01
    [phoneno] =&gt; 1793
    [hiredate] =&gt; 1976-12-15
    [job] =&gt; ANALYST
    [edlevel] =&gt; 18
    [sex] =&gt; F
    [birthdate] =&gt; 1946-01-19
    [salary] =&gt; 28420.00
    [bonus] =&gt; 600.00
    [comm] =&gt; 2274.00
)

Array
(
    [empno] =&gt; 000130
    [firstnme] =&gt; DELORES
    [midinit] =&gt; M
    [lastname] =&gt; QUINTANA
    [workdept] =&gt; C01
    [phoneno] =&gt; 4578
    [hiredate] =&gt; 1971-07-28
    [job] =&gt; ANALYST
    [edlevel] =&gt; 16
    [sex] =&gt; F
    [birthdate] =&gt; 1925-09-15
    [salary] =&gt; 23800.00
    [bonus] =&gt; 500.00
    [comm] =&gt; 1904.00
)</pre></div></div>
      </div>
      <div class="example" id="example-1191">
        <p><strong>Example #8 i5/OS cursors are read-only</strong></p>
        <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">"i5_lib"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"nobody"</span><span style="color: #007700">));<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'select&nbsp;*&nbsp;from&nbsp;names&nbsp;where&nbsp;first&nbsp;=&nbsp;?'</span><span style="color: #007700">);<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$name&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"first2"</span><span style="color: #007700">;<br />&nbsp;&nbsp;</span><span style="color: #0000BB">db2_bind_param</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"name"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">DB2_PARAM_IN</span><span style="color: #007700">);<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"i5_fetch_only"</span><span style="color: #007700">=&gt;</span><span style="color: #0000BB">DB2_I5_FETCH_ON</span><span style="color: #007700">);<br />&nbsp;&nbsp;</span><span style="color: #0000BB">db2_set_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">,</span><span style="color: #0000BB">$options</span><span style="color: #007700">,</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br />&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">db2_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(</span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_fetch_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #007700">{</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]}</span><span style="color: #DD0000">&nbsp;</span><span style="color: #007700">{</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]}</span><span style="color: #DD0000">"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
        </div>

        <div class="example-contents"><p>The above example will output:</p></div>
        <div class="example-contents screen">
<div class="cdata"><pre>
first2 last2
</pre></div>
        </div>
      </div>
    </p>
  </div>

  <div class="refsect1 seealso" id="refsect1-function.db2-set-option-seealso">
    <h3 class="title">See Also</h3>
    <p class="para">
      <ul class="simplelist">
        <li class="member"> <span class="function"><a href="function.db2-connect.html" class="function" rel="rdfs-seeAlso">db2_connect()</a> - Returns a connection to a database</span></li>
        <li class="member"> <span class="function"><a href="function.db2-pconnect.html" class="function" rel="rdfs-seeAlso">db2_pconnect()</a> - Returns a persistent connection to a database</span></li>
        <li class="member"> <span class="function"><a href="function.db2-exec.html" class="function" rel="rdfs-seeAlso">db2_exec()</a> - Executes an SQL statement directly</span></li>
        <li class="member"> <span class="function"><a href="function.db2-prepare.html" class="function" rel="rdfs-seeAlso">db2_prepare()</a> - Prepares an SQL statement to be executed</span></li>
        <li class="member"> <span class="function"><a href="function.db2-cursor-type.html" class="function" rel="rdfs-seeAlso">db2_cursor_type()</a> - Returns the cursor type used by a statement resource</span></li>
      </ul>
    </p>
  </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.db2-server-info.html">db2_server_info</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.db2-special-columns.html">db2_special_columns</a></div>
 <div class="up"><a href="ref.ibm-db2.html">IBM DB2 Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>