Sophie

Sophie

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

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>Returns a persistent connection to a database</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.db2-pclose.html">db2_pclose</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.db2-prepare.html">db2_prepare</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-pconnect" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">db2_pconnect</h1>
  <p class="verinfo">(PECL ibm_db2 &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">db2_pconnect</span> &mdash; <span class="dc-title">
   Returns a persistent connection to a database
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.db2-pconnect-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">resource</span> <span class="methodname"><strong>db2_pconnect</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$database</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$username</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$password</code></span>
   [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$options</code></span>
  ] )</div>



  <p class="para rdfs-comment">
   Returns a persistent connection to an IBM DB2 Universal Database, IBM
   Cloudscape, or Apache Derby database. 
  </p>

  <p class="para">
   For more information on persistent
   connections, refer to <a href="features.persistent-connections.html" class="xref">Persistent Database Connections</a>.
  </p>

  <p class="para">
   Calling  <span class="function"><a href="function.db2-close.html" class="function">db2_close()</a></span> on a persistent connection always
   returns <strong><code>TRUE</code></strong>, but the underlying DB2 client connection remains open and
   waiting to serve the next matching  <span class="function"><strong>db2_pconnect()</strong></span>
   request.
  </p>

  <p class="para">
   Users running version 1.9.0 or later of ibm_db2 should be aware that the
   extension will perform a transaction rollback on persistent connections at
   the end of a request, thus ending the transaction.  This prevents the
   transaction block from carrying over to the next request which uses that
   connection if script execution ends before the transaction block does.
  </p>

 </div>

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

    <dt>

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

      <p class="para">
       The database alias in the DB2 client catalog.
      </p>
     </dd>

    </dt>

    <dt>

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

      <p class="para">
       The username with which you are connecting to the database.
      </p>
     </dd>

    </dt>

    <dt>

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

      <p class="para">
       The password with which you are connecting to the database.
      </p>
     </dd>

    </dt>

    <dt>

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

      <p class="para">
       An associative array of connection options that affect the behavior
       of the connection, where valid array keys include:
       <dl>

        <dt>

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

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

        </dt>

        <dt>

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

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

        </dt>

        <dt>

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

          <p class="para">
           Passing the <em>DB2_FORWARD_ONLY</em> value specifies a
           forward-only cursor for a statement resource. This is the default
           cursor type and is supported on all database servers.
          </p>
          <p class="para">
           Passing the <em>DB2_SCROLLABLE</em> value specifies a
           scrollable cursor for a statement resource. This mode enables
           random access to rows in a result set, but currently is supported
           only by IBM DB2 Universal Database.
          </p>
         </dd>

        </dt>

       </dl>

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

        <dt>

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

          <p class="para">
           Passing the DB2_TRUSTED_CONTEXT_ENABLE value turns trusted context 
           on for this connection handle. This parameter cannot be set using 
            <span class="function"><a href="function.db2-set-option.html" class="function">db2_set_option()</a></span>.
          </p>
          <p class="para">
           This key works only if the database is cataloged (even if the 
           database is local), or if you specify the full DSN when you create  
           the connection.
          </p>
          <p class="para">
           To catalog the database, use following commands:
          </p>
          <p class="para">
           <pre class="literallayout">db2 catalog tcpip node loopback remote &lt;SERVERNAME&gt; server &lt;SERVICENAME&gt;
db2 catalog database &lt;LOCALDBNAME&gt; as &lt;REMOTEDBNAME&gt; at node loopback
db2 &quot;update dbm cfg using svcename &lt;SERVICENAME&gt;&quot;
db2set DB2COMM=TCPIP</pre>
          </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.
       <div class="tip"><strong class="tip">Tip</strong>
        <p class="para">Conflicting connection attributes used in conjunction with persistent 
         connections can produce indeterminate results on i5/OS. Site policies should 
         be establish for all applications using each persistent connection user 
         profile. The default DB2_AUTOCOMMIT_ON is suggested when using persistent connections.
        </p>
       </div>
       <dl>

        <dt>

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

          <p class="para">
           A character value that indicates the default library that will be 
           used for resolving unqualified file references. This is not valid 
           if the connection is using system naming mode.
          </p>
         </dd>

        </dt>

        <dt>

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

          <p class="para">
           <em>DB2_I5_NAMING_ON</em> value turns on DB2 UDB CLI iSeries 
           system naming mode. Files are qualified using the slash (/) delimiter. 
           Unqualified files are resolved using the library list for the job.
          </p>
          <p class="para">
           <em>DB2_I5_NAMING_OFF</em> value turns off DB2 UDB CLI default 
           naming mode, which is SQL naming. Files are qualified using the period (.) 
           delimiter. Unqualified files are resolved using either the default library 
           or the current user ID.
          </p>
         </dd>

        </dt>

        <dt>

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

          <p class="para">
           The <em><code class="parameter">i5_commit</code></em> attribute should be set before the 
            <span class="function"><strong>db2_pconnect()</strong></span>. If the value is changed after the 
           connection has been established, and the connection is to a remote data 
           source, the change does not take effect until the next successful 
            <span class="function"><strong>db2_pconnect()</strong></span> for the connection handle.
           <blockquote class="note"><p><strong class="note">Note</strong>: 
            <p class="para">
             The php.ini setting <em><code class="parameter">ibm_db2.i5_allow_commit</code></em>==0 
             or <em>DB2_I5_TXN_NO_COMMIT</em> is the default, but may be 
             overridden with the <em><code class="parameter">i5_commit</code></em> option.
            </p>
           </p></blockquote>           
          </p>
          <p class="para">
           <em>DB2_I5_TXN_NO_COMMIT</em> - Commitment control is not used.
          </p>
          <p class="para">
           <em>DB2_I5_TXN_READ_UNCOMMITTED</em> - Dirty reads, nonrepeatable 
           reads, and phantoms are possible.
          </p>
          <p class="para">
           <em>DB2_I5_TXN_READ_COMMITTED</em> - Dirty reads are not possible. 
           Nonrepeatable reads, and phantoms are possible.
          </p>
          <p class="para">
           <em>DB2_I5_TXN_REPEATABLE_READ</em> - Dirty reads and nonrepeatable 
           reads are not possible. Phantoms are possible.
          </p>
          <p class="para">
           <em>DB2_I5_TXN_SERIALIZABLE</em> - Transactions are serializable. 
           Dirty reads, non-repeatable reads, and phantoms are not possible
          </p>
         </dd>

        </dt>

        <dt>

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

          <p class="para">
            <em>DB2_FIRST_IO</em> All queries are optimized with the goal of 
            returning the first page of output as fast as possible. This goal works well 
            when the output is controlled by a user who is most likely to cancel the query 
            after viewing the first page of output data. Queries coded with an 
            OPTIMIZE FOR nnn ROWS clause honor the goal specified by the clause.
          </p>
          <p class="para">
           <em>DB2_ALL_IO</em> All queries are optimized with the goal of running 
           the entire query to completion in the shortest amount of elapsed time. This is a 
           good option when the output of a query is being written to a file or report, or 
           the interface is queuing the output data. Queries coded with an OPTIMIZE FOR nnn 
           ROWS clause honor the goal specified by the clause. This is the default.
          </p>
         </dd>

        </dt>

        <dt>

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

          <p class="para">
           <em>DB2_I5_DBCS_ALLOC_ON</em> value turns on DB2 6X allocation scheme 
           for DBCS translation column size growth.
          </p>
          <p class="para">
           <em>DB2_I5_DBCS_ALLOC_OFF</em> value turns off DB2 6X allocation scheme 
           for DBCS translation column size growth. 
           <blockquote class="note"><p><strong class="note">Note</strong>: 
            <p class="para">
             The php.ini setting <em><code class="parameter">ibm_db2.i5_dbcs_alloc</code></em>==0 or 
             <em>DB2_I5_DBCS_ALLOC_OFF</em> is the default, but may be overridden 
             with the <em><code class="parameter">i5_dbcs_alloc</code></em> option.
            </p>
           </p></blockquote>
           </p>
         </dd>

        </dt>

        <dt>

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

          <p class="para">
           <em>DB2_I5_FMT_ISO</em> - The International Organization for Standardization 
           (ISO) date format yyyy-mm-dd is used. This is the default.
          </p>
          <p class="para">
           <em>DB2_I5_FMT_USA</em> - The United States date format mm/dd/yyyy is used.
          </p>
          <p class="para">
           <em>DB2_I5_FMT_EUR</em> - The European date format dd.mm.yyyy is used.
          </p>
          <p class="para">
           <em>DB2_I5_FMT_JIS</em> - The Japanese Industrial Standard date format 
           yyyy-mm-dd is used. 
          </p>
          <p class="para">
           <em>DB2_I5_FMT_MDY</em> - The date format mm/dd/yyyy is used. 
          </p>
          <p class="para">
           <em>DB2_I5_FMT_DMY</em> - The date format dd/mm/yyyy is used.
          </p>
          <p class="para">
           <em>DB2_I5_FMT_YMD</em> - The date format yy/mm/dd is used.
          </p>
          <p class="para">
           <em>DB2_I5_FMT_JUL</em> - The Julian date format yy/ddd is used.
          </p>
          <p class="para">
           <em>DB2_I5_FMT_JOB</em> - The job default is used.
          </p>
         </dd>

        </dt>

        <dt>

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

          <p class="para">
           <em>DB2_I5_SEP_SLASH</em> - A slash ( / ) is used as the date separator. 
           This is the default.
          </p>
          <p class="para">
           <em>DB2_I5_SEP_DASH</em> - A dash ( - ) is used as the date separator.
          </p>
          <p class="para">
           <em>DB2_I5_SEP_PERIOD</em> - A period ( . ) is used as the date 
           separator.
          </p>
          <p class="para">
           <em>DB2_I5_SEP_COMMA</em> - A comma ( , ) is used as the date separator.
          </p>
          <p class="para">
           <em>DB2_I5_SEP_BLANK</em> - A blank is used as the date separator.
          </p>
          <p class="para">
           <em>DB2_I5_SEP_JOB</em> - The job default is used
          </p>
         </dd>

        </dt>
     
        <dt>

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

          <p class="para">
           <em>DB2_I5_FMT_ISO</em> - The International Organization for 
           Standardization (ISO) time format hh.mm.ss is used. This is the default.
          </p>
          <p class="para">
           <em>DB2_I5_FMT_USA</em> - The United States time format 
           hh:mmxx is used, where xx is AM or PM.
          </p>
          <p class="para">
           <em>DB2_I5_FMT_EUR</em> - The European time format hh.mm.ss 
           is used.
          </p>
          <p class="para">
           <em>DB2_I5_FMT_JIS</em> - The Japanese Industrial Standard 
           time format hh:mm:ss is used.
          </p>
          <p class="para">
           <em>DB2_I5_FMT_HMS</em> - The hh:mm:ss format is used.
          </p>
         </dd>

        </dt>

        <dt>

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

          <p class="para">
           <em>DB2_I5_SEP_COLON</em> - A colon ( : ) is used as the time 
           separator. This is the default.
          </p>
          <p class="para">
           <em>DB2_I5_SEP_PERIOD</em> - A period ( . ) is used as the time 
           separator.
          </p>
          <p class="para">
           <em>DB2_I5_SEP_COMMA</em> - A comma ( , ) is used as the time 
           separator.
          </p>
          <p class="para">
           <em>DB2_I5_SEP_BLANK</em> - A blank is used as the time separator.
          </p>
          <p class="para">
           <em>DB2_I5_SEP_JOB</em> - The job default is used.
          </p>
         </dd>

        </dt>

        <dt>

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

          <p class="para">
           <em>DB2_I5_SEP_PERIOD</em> - A period ( . ) is used as 
           the decimal separator. This is the default.
          </p>
          <p class="para">
           <em>DB2_I5_SEP_COMMA</em> - A comma ( , ) is used as the 
           decimal separator.
          </p>
          <p class="para">
           <em>DB2_I5_SEP_JOB</em> - The job default is used.
          </p>
         </dd>

        </dt>
        
       </dl>

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

        <dt>

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

          <p class="para">
           A character value that indicates the library list that will be used for 
           resolving unqualified file references. Specify the library list 
           elements separated by blanks &#039;i5_libl&#039;=&gt;&quot;MYLIB YOURLIB ANYLIB&quot;. 
           <blockquote class="note"><p><strong class="note">Note</strong>: 
            <p class="para">
             i5_libl calls qsys2/qcmdexc(&#039;cmd&#039;,cmdlen), which is only available 
             in i5/OS V5R4 and later.
            </p>
           </p></blockquote>
          </p>
         </dd>

        </dt>
         
       </dl>

      </p>      
     </dd>

    </dt>

   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.db2-pconnect-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns a connection handle resource if the connection attempt is
   successful.  <span class="function"><strong>db2_pconnect()</strong></span> tries to reuse an existing
   connection resource that exactly matches the
   <em><code class="parameter">database</code></em>, <em><code class="parameter">username</code></em>, and
   <em><code class="parameter">password</code></em> parameters. If the connection attempt fails,
    <span class="function"><strong>db2_pconnect()</strong></span> returns <strong><code>FALSE</code></strong>.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.db2-pconnect-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>ibm_db2 1.9.0</td>
       <td>
        Active transactions within a persistent connection will be rolled back
        at the end of each request.
       </td>
      </tr>

      <tr>
       <td>ibm_db2 1.8.0</td>
       <td>
        The <em><code class="parameter">i5_libl</code></em> option is available for i5/OS
        users.
       </td>
      </tr>

      <tr>
       <td>ibm_db2 1.7.0</td>
       <td>
        The <em><code class="parameter">trustedcontext</code></em> option is available.
       </td>
      </tr>

      <tr>
       <td>ibm_db2 1.5.1</td>
       <td>
        The <em><code class="parameter">i5_lib</code></em>, <em><code class="parameter">i5_naming</code></em>,
        <em><code class="parameter">i5_commit</code></em>,
        <em><code class="parameter">i5_query_optimize</code></em>,
        <em><code class="parameter">i5_dbcs_alloc</code></em>,
        <em><code class="parameter">i5_date_fmt</code></em>,
        <em><code class="parameter">i5_date_sep</code></em>,
        <em><code class="parameter">i5_time_fmt</code></em>, <em><code class="parameter">i5_time_sep</code></em>
        and <em><code class="parameter">i5_decimal_sep</code></em> options are available for
        i5/OS users.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.db2-pconnect-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1178">
    <p><strong>Example #1 A  <span class="function"><strong>db2_pconnect()</strong></span> example</strong></p>
    <div class="example-contents"><p>
     In the following example, the first call to
      <span class="function"><strong>db2_pconnect()</strong></span> returns a new persistent connection
     resource. The second call to  <span class="function"><strong>db2_pconnect()</strong></span> returns
     a persistent connection resource that simply reuses the first persistent
     connection resource.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$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">$user&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: #0000BB">$pconn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_pconnect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$user</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$password</span><span style="color: #007700">);<br /><br />if&nbsp;(</span><span style="color: #0000BB">$pconn</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Persistent&nbsp;connection&nbsp;succeeded."</span><span style="color: #007700">;<br />}<br />else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Persistent&nbsp;connection&nbsp;failed."</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">$pconn2&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_pconnect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$user</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$password</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">$pconn</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Second&nbsp;persistent&nbsp;connection&nbsp;succeeded."</span><span style="color: #007700">;<br />}<br />else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Second&nbsp;persistent&nbsp;connection&nbsp;failed."</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>
Persistent connection succeeded.
Second persistent connection succeeded.
</pre></div>
    </div>
   </div>
   <div class="example" id="example-1179">
    <p><strong>Example #2 Using trusted context</strong></p>
    <div class="example-contents"><p>
     The following example shows how to enable trusted context, switch 
     users, and get the current user ID.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$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">$authID&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"db2inst1"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$auth_pass&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"ibmdb2"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$tc_user&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"tcuser"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$tc_pass&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"tcpassword"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$dsn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"DATABASE=</span><span style="color: #0000BB">$database</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">;<br />&nbsp;&nbsp;PROTOCOL=TCPIP;UID=</span><span style="color: #0000BB">$authID</span><span style="color: #DD0000">;PWD=</span><span style="color: #0000BB">$auth_pass</span><span style="color: #DD0000">;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;array&nbsp;(</span><span style="color: #DD0000">"trustedcontext"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">DB2_TRUSTED_CONTEXT_ENABLE</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$tc_conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_pconnect</span><span style="color: #007700">(</span><span style="color: #0000BB">$dsn</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;</span><span style="color: #0000BB">$options</span><span style="color: #007700">);<br />if(</span><span style="color: #0000BB">$tc_conn</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Explicit&nbsp;trusted&nbsp;connection&nbsp;succeeded.\n"</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span style="color: #0000BB">db2_get_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$tc_conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"trustedcontext"</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$userBefore&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_get_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$tc_conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"trusted_user"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//Do&nbsp;some&nbsp;work&nbsp;as&nbsp;user&nbsp;1.<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Switching&nbsp;to&nbsp;trusted&nbsp;user.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$parameters&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"trusted_user"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$tc_user</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"trusted_password"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$tcuser_pass</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$res&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_set_option&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">$tc_conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$parameters</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$userAfter&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_get_option</span><span style="color: #007700">(</span><span style="color: #0000BB">$tc_conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"trusted_user"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//Do&nbsp;more&nbsp;work&nbsp;as&nbsp;trusted&nbsp;user.<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">if(</span><span style="color: #0000BB">$userBefore&nbsp;</span><span style="color: #007700">!=&nbsp;</span><span style="color: #0000BB">$userAfter</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"User&nbsp;has&nbsp;been&nbsp;switched."&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">db2_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$tc_conn</span><span style="color: #007700">);<br />}<br />else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Explicit&nbsp;trusted&nbsp;connection&nbsp;failed.\n"</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>
Explicit trusted connection succeeded.
User has been switched.
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.db2-pconnect-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>
   </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-pclose.html">db2_pclose</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.db2-prepare.html">db2_prepare</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>