<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.ibm-db2.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'function.db2-pconnect.php',
    1 => 'db2_pconnect',
    2 => 'Returns a persistent connection to a database',
  ),
  'up' => 
  array (
    0 => 'ref.ibm-db2.php',
    1 => 'Функції IBM DB2',
  ),
  'prev' => 
  array (
    0 => 'function.db2-pclose.php',
    1 => 'db2_pclose',
  ),
  'next' => 
  array (
    0 => 'function.db2-prepare.php',
    1 => 'db2_prepare',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/ibm_db2/functions/db2-pconnect.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<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">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>db2_pconnect</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$database</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$username</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$password</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$options</code><span class="initializer"> = []</span></span><br>): <span class="type"><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></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.php" class="xref">Persistent Database Connections</a>.
  </p>

  <p class="para">
   Calling <span class="function"><a href="function.db2-close.php" class="function">db2_close()</a></span> on a persistent connection always
   returns <strong><code><a href="reserved.constants.php#constant.true">true</a></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">Параметри</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">database</code></dt>
     <dd>
      <p class="para">
       For a cataloged connection to a database, <code class="parameter">database</code>
       represents the database alias in the DB2 client catalog.
      </p>
      <p class="para">
       For an uncataloged connection to a database,
       <code class="parameter">database</code> represents a complete connection
       string in the following format:
       <pre class="literallayout">DATABASE=<code class="parameter">database</code>;HOSTNAME=<code class="parameter">hostname</code>;PORT=<code class="parameter">port</code>;PROTOCOL=TCPIP;UID=<code class="parameter">username</code>;PWD=<code class="parameter">password</code>;</pre>
       <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
        <p class="para">
         When connecting to Db2 on IBM i, the underlying system calls
         <a href="https://www.ibm.com/docs/en/i/7.5?topic=functions-sqldriverconnect-connect-data-source" class="link external">&raquo;&nbsp;SQLDriverConnect</a>,
         which only accepts DSN, UID, and PWD for the
         <a href="https://www.ibm.com/docs/en/i/7.5?topic=functions-sqldriverconnect-connect-data-source#rzadpfndvcon__title__5" class="link external">&raquo;&nbsp;connection string</a>.
         Like so:
         <pre class="literallayout">DSN=<code class="parameter">database</code>;UID=<code class="parameter">username</code>;PWD=<code class="parameter">password</code>;</pre>
        </p>
       </p></blockquote>
       where the parameters represent the following values:
       <dl>
        
         <dt><code class="parameter">database</code></dt>
         <dd>
          <p class="para">
           The name of the database.
          </p>
         </dd>
        
        
         <dt><code class="parameter">hostname</code></dt>
         <dd>
          <p class="para">
           The hostname or IP address of the database server.
          </p>
         </dd>
        
        
         <dt><code class="parameter">port</code></dt>
         <dd>
          <p class="para">
           The TCP/IP port on which the database is listening for
           requests.
          </p>
         </dd>
        
        
         <dt><code class="parameter">username</code></dt>
         <dd>
          <p class="para">
           The username with which you are connecting to the
           database.
          </p>
         </dd>
        
        
         <dt><code class="parameter">password</code></dt>
         <dd>
          <p class="para">
           The password with which you are connecting to the database.
          </p>
         </dd>
        
       </dl>
      </p>
     </dd>
    
    
     <dt><code class="parameter">username</code></dt>
     <dd>
      <p class="para">
       The username with which you are connecting to the database.
      </p>
     </dd>
    
    
     <dt><code class="parameter">password</code></dt>
     <dd>
      <p class="para">
       The password with which you are connecting to the database.
      </p>
     </dd>
    
    
     <dt><code class="parameter">options</code></dt>
     <dd>
      <p class="para">
       An associative array of connection options that affect the behavior
       of the connection, where valid array keys include:
       <dl>
        
         <dt><code class="parameter">autocommit</code></dt>
         <dd>
          <p class="para">
           Passing the <strong><code><a href="ibm-db2.constants.php#constant.db2-autocommit-on">DB2_AUTOCOMMIT_ON</a></code></strong> value turns
           autocommit on for this connection handle.
          </p>
          <p class="para">
           Passing the <strong><code><a href="ibm-db2.constants.php#constant.db2-autocommit-off">DB2_AUTOCOMMIT_OFF</a></code></strong> value turns
           autocommit off for this connection handle.
          </p>
         </dd>
        
        
         <dt><code class="parameter">DB2_ATTR_CASE</code></dt>
         <dd>
          <p class="para">
           Passing the <strong><code><a href="ibm-db2.constants.php#constant.db2-case-natural">DB2_CASE_NATURAL</a></code></strong> value specifies
           that column names are returned in natural case.
          </p>
          <p class="para">
           Passing the <strong><code><a href="ibm-db2.constants.php#constant.db2-case-lower">DB2_CASE_LOWER</a></code></strong> value specifies
           that column names are returned in lower case.
          </p>
          <p class="para">
           Passing the <strong><code><a href="ibm-db2.constants.php#constant.db2-case-upper">DB2_CASE_UPPER</a></code></strong> value specifies
           that column names are returned in upper case.
          </p>
         </dd>
        
        
         <dt><code class="parameter">CURSOR</code></dt>
         <dd>
          <p class="para">
           Passing the <strong><code><a href="ibm-db2.constants.php#constant.db2-forward-only">DB2_FORWARD_ONLY</a></code></strong> 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 <strong><code><a href="ibm-db2.constants.php#constant.db2-scrollable">DB2_SCROLLABLE</a></code></strong> 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>
        
       </dl>
      </p>
      <p class="para">
       The following new option is available in ibm_db2 version 1.7.0
       and later.
       <dl>
        
         <dt><code class="parameter">trustedcontext</code></dt>
         <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.php" 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>
        
      </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">Підказка</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><code class="parameter">i5_lib</code></dt>
         <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><code class="parameter">i5_naming</code></dt>
         <dd>
          <p class="para">
           <code class="literal">DB2_I5_NAMING_ON</code> 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">
           <code class="literal">DB2_I5_NAMING_OFF</code> 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><code class="parameter">i5_commit</code></dt>
         <dd>
          <p class="para">
           The <code class="parameter">i5_commit</code> 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">Зауваження</strong>: 
            <p class="para">
             The php.ini setting <code class="parameter">ibm_db2.i5_allow_commit</code>==0
             or <code class="literal">DB2_I5_TXN_NO_COMMIT</code> is the default, but may be
             overridden with the <code class="parameter">i5_commit</code> option.
            </p>
           </p></blockquote>
          </p>
          <p class="para">
           <code class="literal">DB2_I5_TXN_NO_COMMIT</code> - Commitment control is not used.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_TXN_READ_UNCOMMITTED</code> - Dirty reads, nonrepeatable
           reads, and phantoms are possible.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_TXN_READ_COMMITTED</code> - Dirty reads are not possible.
           Nonrepeatable reads, and phantoms are possible.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_TXN_REPEATABLE_READ</code> - Dirty reads and nonrepeatable
           reads are not possible. Phantoms are possible.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_TXN_SERIALIZABLE</code> - Transactions are serializable.
           Dirty reads, non-repeatable reads, and phantoms are not possible
          </p>
         </dd>
        
        
         <dt><code class="parameter">i5_query_optimize</code></dt>
         <dd>
          <p class="para">
            <code class="literal">DB2_FIRST_IO</code> 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">
           <code class="literal">DB2_ALL_IO</code> 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><code class="parameter">i5_dbcs_alloc</code></dt>
         <dd>
          <p class="para">
           <code class="literal">DB2_I5_DBCS_ALLOC_ON</code> value turns on DB2 6X allocation scheme
           for DBCS translation column size growth.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_DBCS_ALLOC_OFF</code> value turns off DB2 6X allocation scheme
           for DBCS translation column size growth.
           <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
            <p class="para">
             The php.ini setting <code class="parameter">ibm_db2.i5_dbcs_alloc</code>==0 or
             <code class="literal">DB2_I5_DBCS_ALLOC_OFF</code> is the default, but may be overridden
             with the <code class="parameter">i5_dbcs_alloc</code> option.
            </p>
           </p></blockquote>
           </p>
         </dd>
        
        
         <dt><code class="parameter">i5_date_fmt</code></dt>
         <dd>
          <p class="para">
           <code class="literal">DB2_I5_FMT_ISO</code> - The International Organization for Standardization
           (ISO) date format yyyy-mm-dd is used. This is the default.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_FMT_USA</code> - The United States date format mm/dd/yyyy is used.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_FMT_EUR</code> - The European date format dd.mm.yyyy is used.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_FMT_JIS</code> - The Japanese Industrial Standard date format
           yyyy-mm-dd is used.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_FMT_MDY</code> - The date format mm/dd/yyyy is used.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_FMT_DMY</code> - The date format dd/mm/yyyy is used.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_FMT_YMD</code> - The date format yy/mm/dd is used.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_FMT_JUL</code> - The Julian date format yy/ddd is used.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_FMT_JOB</code> - The job default is used.
          </p>
         </dd>
        
        
         <dt><code class="parameter">i5_date_sep</code></dt>
         <dd>
          <p class="para">
           <code class="literal">DB2_I5_SEP_SLASH</code> - A slash ( / ) is used as the date separator.
           This is the default.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_SEP_DASH</code> - A dash ( - ) is used as the date separator.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_SEP_PERIOD</code> - A period ( . ) is used as the date
           separator.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_SEP_COMMA</code> - A comma ( , ) is used as the date separator.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_SEP_BLANK</code> - A blank is used as the date separator.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_SEP_JOB</code> - The job default is used
          </p>
         </dd>
        
        
         <dt><code class="parameter">i5_time_fmt</code></dt>
         <dd>
          <p class="para">
           <code class="literal">DB2_I5_FMT_ISO</code> - The International Organization for
           Standardization (ISO) time format hh.mm.ss is used. This is the default.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_FMT_USA</code> - The United States time format
           hh:mmxx is used, where xx is AM or PM.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_FMT_EUR</code> - The European time format hh.mm.ss
           is used.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_FMT_JIS</code> - The Japanese Industrial Standard
           time format hh:mm:ss is used.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_FMT_HMS</code> - The hh:mm:ss format is used.
          </p>
         </dd>
        
        
         <dt><code class="parameter">i5_time_sep</code></dt>
         <dd>
          <p class="para">
           <code class="literal">DB2_I5_SEP_COLON</code> - A colon ( : ) is used as the time
           separator. This is the default.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_SEP_PERIOD</code> - A period ( . ) is used as the time
           separator.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_SEP_COMMA</code> - A comma ( , ) is used as the time
           separator.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_SEP_BLANK</code> - A blank is used as the time separator.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_SEP_JOB</code> - The job default is used.
          </p>
         </dd>
        
        
         <dt><code class="parameter">i5_decimal_sep</code></dt>
         <dd>
          <p class="para">
           <code class="literal">DB2_I5_SEP_PERIOD</code> - A period ( . ) is used as
           the decimal separator. This is the default.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_SEP_COMMA</code> - A comma ( , ) is used as the
           decimal separator.
          </p>
          <p class="para">
           <code class="literal">DB2_I5_SEP_JOB</code> - The job default is used.
          </p>
         </dd>
        
       </dl>
      </p>
      <p class="para">
       The following new i5/OS option is available in ibm_db2 version 1.8.0
       and later.
       <dl>
        
         <dt><code class="parameter">i5_libl</code></dt>
         <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">Зауваження</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>
        
       </dl>
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.db2-pconnect-returnvalues">
  <h3 class="title">Значення, що повертаються</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
   <code class="parameter">database</code>, <code class="parameter">username</code>, and
   <code class="parameter">password</code> parameters. If the connection attempt fails,
   <span class="function"><strong>db2_pconnect()</strong></span> returns <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.db2-pconnect-changelog">
  <h3 class="title">Журнал змін</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Версія</th>
       <th>Опис</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>PECL 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>PECL ibm_db2 1.8.0</td>
       <td>
        The <code class="parameter">i5_libl</code> option is available for i5/OS
        users.
       </td>
      </tr>

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

      <tr>
       <td>PECL ibm_db2 1.5.1</td>
       <td>
        The <code class="parameter">i5_lib</code>, <code class="parameter">i5_naming</code>,
        <code class="parameter">i5_commit</code>,
        <code class="parameter">i5_query_optimize</code>,
        <code class="parameter">i5_dbcs_alloc</code>,
        <code class="parameter">i5_date_fmt</code>,
        <code class="parameter">i5_date_sep</code>,
        <code class="parameter">i5_time_fmt</code>, <code class="parameter">i5_time_sep</code>
        and <code class="parameter">i5_decimal_sep</code> 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">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #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 </span><span style="color: #007700">= </span><span style="color: #DD0000">'SAMPLE'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$user </span><span style="color: #007700">= </span><span style="color: #DD0000">'db2inst1'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$password </span><span style="color: #007700">= </span><span style="color: #DD0000">'ibmdb2'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$pconn </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_pconnect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">, </span><span style="color: #0000BB">$user</span><span style="color: #007700">, </span><span style="color: #0000BB">$password</span><span style="color: #007700">);<br /><br />if (</span><span style="color: #0000BB">$pconn</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"Persistent connection succeeded."</span><span style="color: #007700">;<br />}<br />else {<br />    echo </span><span style="color: #DD0000">"Persistent connection failed."</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">$pconn2 </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_pconnect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">, </span><span style="color: #0000BB">$user</span><span style="color: #007700">, </span><span style="color: #0000BB">$password</span><span style="color: #007700">);<br />if (</span><span style="color: #0000BB">$pconn</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"Second persistent connection succeeded."</span><span style="color: #007700">;<br />}<br />else {<br />    echo </span><span style="color: #DD0000">"Second persistent connection failed."</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Поданий вище приклад
виведе:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Persistent connection succeeded.
Second persistent connection succeeded.</pre>
</div>
    </div>
   </div>
   <div class="example" id="example-2">
    <p><strong>Приклад #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 </span><span style="color: #007700">= </span><span style="color: #DD0000">"SAMPLE"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$hostname </span><span style="color: #007700">= </span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$port </span><span style="color: #007700">= </span><span style="color: #0000BB">50000</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$authID </span><span style="color: #007700">= </span><span style="color: #DD0000">"db2inst1"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$auth_pass </span><span style="color: #007700">= </span><span style="color: #DD0000">"ibmdb2"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$tc_user </span><span style="color: #007700">= </span><span style="color: #DD0000">"tcuser"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$tc_pass </span><span style="color: #007700">= </span><span style="color: #DD0000">"tcpassword"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$dsn </span><span style="color: #007700">= </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 />  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 </span><span style="color: #007700">= array (</span><span style="color: #DD0000">"trustedcontext" </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">DB2_TRUSTED_CONTEXT_ENABLE</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$tc_conn </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_pconnect</span><span style="color: #007700">(</span><span style="color: #0000BB">$dsn</span><span style="color: #007700">, </span><span style="color: #DD0000">""</span><span style="color: #007700">, </span><span style="color: #DD0000">""</span><span style="color: #007700">, </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">) {<br />    echo </span><span style="color: #DD0000">"Explicit trusted connection succeeded.\n"</span><span style="color: #007700">;<br /><br />    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">, </span><span style="color: #DD0000">"trustedcontext"</span><span style="color: #007700">)) {<br />        </span><span style="color: #0000BB">$userBefore </span><span style="color: #007700">= </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">, </span><span style="color: #DD0000">"trusted_user"</span><span style="color: #007700">);<br /><br />        </span><span style="color: #FF8000">//Do some work as user 1.<br /><br />        //Switching to trusted user.<br />        </span><span style="color: #0000BB">$parameters </span><span style="color: #007700">= array(</span><span style="color: #DD0000">"trusted_user" </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">$tc_user</span><span style="color: #007700">,<br />          </span><span style="color: #DD0000">"trusted_password" </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">$tcuser_pass</span><span style="color: #007700">);<br />        </span><span style="color: #0000BB">$res </span><span style="color: #007700">= </span><span style="color: #0000BB">db2_set_option </span><span style="color: #007700">(</span><span style="color: #0000BB">$tc_conn</span><span style="color: #007700">, </span><span style="color: #0000BB">$parameters</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /><br />        </span><span style="color: #0000BB">$userAfter </span><span style="color: #007700">= </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">, </span><span style="color: #DD0000">"trusted_user"</span><span style="color: #007700">);<br />        </span><span style="color: #FF8000">//Do more work as trusted user.<br /><br />        </span><span style="color: #007700">if(</span><span style="color: #0000BB">$userBefore </span><span style="color: #007700">!= </span><span style="color: #0000BB">$userAfter</span><span style="color: #007700">) {<br />            echo </span><span style="color: #DD0000">"User has been switched." </span><span style="color: #007700">. </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />        }<br />    }<br /><br />    </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 {<br />    echo </span><span style="color: #DD0000">"Explicit trusted connection 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>Поданий вище приклад
виведе:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">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">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.db2-connect.php" class="function" rel="rdfs-seeAlso">db2_connect()</a> - Returns a connection to a database</span></li>
   </ul>
  </p>
 </div>



</div><?php manual_footer($setup); ?>