<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.oci8.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.oci-pconnect.php',
    1 => 'oci_pconnect',
    2 => 'Connect to an Oracle database using a persistent connection',
  ),
  'up' => 
  array (
    0 => 'ref.oci8.php',
    1 => 'OCI8 Functions',
  ),
  'prev' => 
  array (
    0 => 'function.oci-password-change.php',
    1 => 'oci_password_change',
  ),
  'next' => 
  array (
    0 => 'function.oci-register-taf-callback.php',
    1 => 'oci_register_taf_callback',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/oci8/functions/oci-pconnect.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.oci-pconnect" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">oci_pconnect</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8, PECL OCI8 &gt;= 1.1.0)</p><p class="refpurpose"><span class="refname">oci_pconnect</span> &mdash; <span class="dc-title">Connect to an Oracle database using a persistent connection</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.oci-pconnect-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>oci_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">$username</code></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">$password</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">$connection_string</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></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">$encoding</code><span class="initializer"> = &quot;&quot;</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$session_mode</code><span class="initializer"> = <strong><code><a href="oci8.constants.php#constant.oci-default">OCI_DEFAULT</a></code></strong></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">
   Creates a persistent connection to an Oracle server and logs on. 
  </p>
  <p class="para">
   Persistent connections are cached and re-used between requests, resulting in
   reduced overhead on each page load; a typical PHP application will have a
   single persistent connection open against an Oracle server per Apache child
   process (or PHP FPM process). See the <a href="oci8.connection.php" class="link">OCI8
   Connection Handling and Connection Pooling</a> section for more
   information.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.oci-pconnect-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">username</code></dt>
     <dd>
      <p class="para">
       The Oracle user name.
      </p>
     </dd>
    
    
     <dt><code class="parameter">password</code></dt>
     <dd>
      <p class="para">
       The password for <code class="parameter">username</code>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">connection_string</code></dt>
     <dd>
      <p class="para">Contains
the <code class="literal">Oracle instance</code> to connect to. It can be
an <a href="https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-E5358DEA-D619-4B7B-A799-3D2F802500F1" class="link external">&raquo;&nbsp;Easy Connect
string</a>, or a Connect Name from
the <var class="filename">tnsnames.ora</var> file, or the name of a local
Oracle instance.
</p>
<p class="para">If not specified or <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>, PHP uses
environment variables such as <strong><code>TWO_TASK</code></strong> (on Linux)
or <strong><code>LOCAL</code></strong> (on Windows)
and <strong><code>ORACLE_SID</code></strong> to determine the
<code class="literal">Oracle instance</code> to connect to.
</p>
<p class="para">
To use the Easy Connect naming method, PHP must be linked with Oracle
10<em>g</em> or greater Client libraries. The Easy Connect string for Oracle
10<em>g</em> is of the form:
<em>[//]host_name[:port][/service_name]</em>. From Oracle
11<em>g</em>, the syntax is:
<em>[//]host_name[:port][/service_name][:server_type][/instance_name]</em>.
Further options were introduced with Oracle 19c, including timeout and keep-alive
settings.  Refer to Oracle documentation.  Service names can be found by running
the Oracle utility <code class="literal">lsnrctl status</code> on the database server
machine.
</p>
<p class="para">
The <var class="filename">tnsnames.ora</var> file can be in the Oracle Net search path,
which
includes <var class="filename">/your/path/to/instantclient/network/admin</var>, <var class="filename">$ORACLE_HOME/network/admin</var>
and <var class="filename">/etc</var>.  Alternatively set <code class="literal">TNS_ADMIN</code>
so that <var class="filename">$TNS_ADMIN/tnsnames.ora</var> is read.  Make sure the web
daemon has read access to the file.
</p>
     </dd>
    
    
     <dt><code class="parameter">encoding</code></dt>
     <dd>
      <p class="para">Determines
the character set used by the Oracle Client libraries.  The character
set does not need to match the character set used by the database.  If
it doesn&#039;t match, Oracle will do its best to convert data to and from
the database character set.  Depending on the character sets this may
not give usable results.  Conversion also adds some time overhead.
</p>
<p class="para">If not specified, the
Oracle Client libraries determine a character set from
the <strong><code>NLS_LANG</code></strong> environment variable.
</p>
<p class="para">Passing this parameter can
reduce the time taken to connect.
</p>
     </dd>
    
    
     <dt><code class="parameter">session_mode</code></dt>
     <dd>
      <p class="para">This
parameter is available since version PHP 5 (PECL OCI8 1.1) and accepts the
following values: <strong><code><a href="oci8.constants.php#constant.oci-default">OCI_DEFAULT</a></code></strong>,
<strong><code><a href="oci8.constants.php#constant.oci-sysoper">OCI_SYSOPER</a></code></strong> and <strong><code><a href="oci8.constants.php#constant.oci-sysdba">OCI_SYSDBA</a></code></strong>.
If either <strong><code><a href="oci8.constants.php#constant.oci-sysoper">OCI_SYSOPER</a></code></strong> or
<strong><code><a href="oci8.constants.php#constant.oci-sysdba">OCI_SYSDBA</a></code></strong> were specified, this function will try
to establish privileged connection using external credentials.
Privileged connections are disabled by default. To enable them you
need to set <a href="oci8.configuration.php#ini.oci8.privileged-connect" class="link">oci8.privileged_connect</a>
to <code class="literal">On</code>.
</p>
<p class="para">
PHP 5.3 (PECL OCI8 1.3.4) introduced the
<strong><code><a href="oci8.constants.php#constant.oci-cred-ext">OCI_CRED_EXT</a></code></strong> mode value. This tells Oracle to use
External or OS authentication, which must be configured in the
database.  The <strong><code><a href="oci8.constants.php#constant.oci-cred-ext">OCI_CRED_EXT</a></code></strong> flag can only be used
with username of &quot;/&quot; and a empty password.
<a href="oci8.configuration.php#ini.oci8.privileged-connect" class="link">oci8.privileged_connect</a>
may be <code class="literal">On</code> or <code class="literal">Off</code>.
</p>
<p class="para">
<strong><code><a href="oci8.constants.php#constant.oci-cred-ext">OCI_CRED_EXT</a></code></strong> may be combined with the
<strong><code><a href="oci8.constants.php#constant.oci-sysoper">OCI_SYSOPER</a></code></strong> or
<strong><code><a href="oci8.constants.php#constant.oci-sysdba">OCI_SYSDBA</a></code></strong> modes.
</p>
<p class="para">
<strong><code><a href="oci8.constants.php#constant.oci-cred-ext">OCI_CRED_EXT</a></code></strong> is not supported on Windows for
security reasons.
</p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.oci-pconnect-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns a connection identifier or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on error.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.oci-pconnect-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 Basic <span class="function"><strong>oci_pconnect()</strong></span> Example using Easy Connect syntax</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">// Connects to the XE service (i.e. database) on the "localhost" machine<br /></span><span style="color: #0000BB">$conn </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_pconnect</span><span style="color: #007700">(</span><span style="color: #DD0000">'hr'</span><span style="color: #007700">, </span><span style="color: #DD0000">'welcome'</span><span style="color: #007700">, </span><span style="color: #DD0000">'localhost/XE'</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">$conn</span><span style="color: #007700">) {<br />    </span><span style="color: #0000BB">$e </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_error</span><span style="color: #007700">();<br />    </span><span style="color: #0000BB">trigger_error</span><span style="color: #007700">(</span><span style="color: #0000BB">htmlentities</span><span style="color: #007700">(</span><span style="color: #0000BB">$e</span><span style="color: #007700">[</span><span style="color: #DD0000">'message'</span><span style="color: #007700">], </span><span style="color: #0000BB">ENT_QUOTES</span><span style="color: #007700">), </span><span style="color: #0000BB">E_USER_ERROR</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">$stid </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_parse</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">, </span><span style="color: #DD0000">'SELECT * FROM employees'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">oci_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #DD0000">"&lt;table border='1'&gt;\n"</span><span style="color: #007700">;<br />while (</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">oci_fetch_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$stid</span><span style="color: #007700">, </span><span style="color: #0000BB">OCI_ASSOC</span><span style="color: #007700">+</span><span style="color: #0000BB">OCI_RETURN_NULLS</span><span style="color: #007700">)) {<br />    echo </span><span style="color: #DD0000">"&lt;tr&gt;\n"</span><span style="color: #007700">;<br />    foreach (</span><span style="color: #0000BB">$row </span><span style="color: #007700">as </span><span style="color: #0000BB">$item</span><span style="color: #007700">) {<br />        echo </span><span style="color: #DD0000">"    &lt;td&gt;" </span><span style="color: #007700">. (</span><span style="color: #0000BB">$item </span><span style="color: #007700">!== </span><span style="color: #0000BB">null </span><span style="color: #007700">? </span><span style="color: #0000BB">htmlentities</span><span style="color: #007700">(</span><span style="color: #0000BB">$item</span><span style="color: #007700">, </span><span style="color: #0000BB">ENT_QUOTES</span><span style="color: #007700">) : </span><span style="color: #DD0000">"&amp;nbsp;"</span><span style="color: #007700">) . </span><span style="color: #DD0000">"&lt;/td&gt;\n"</span><span style="color: #007700">;<br />    }<br />    echo </span><span style="color: #DD0000">"&lt;/tr&gt;\n"</span><span style="color: #007700">;<br />}<br />echo </span><span style="color: #DD0000">"&lt;/table&gt;\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
    See <span class="function"><a href="function.oci-connect.php" class="function">oci_connect()</a></span> for further examples of parameter usage.
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.oci-pconnect-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
    The lifetime and
    maximum number of persistent Oracle connections per PHP process can be tuned by setting
    the following configuration values: <a href="oci8.configuration.php#ini.oci8.persistent-timeout" class="link">oci8.persistent_timeout</a>,
    <a href="oci8.configuration.php#ini.oci8.ping-interval" class="link">oci8.ping_interval</a> and
    <a href="oci8.configuration.php#ini.oci8.max-persistent" class="link">oci8.max_persistent</a>.
   </span>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.oci-pconnect-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.oci-connect.php" class="function" rel="rdfs-seeAlso">oci_connect()</a> - Connect to an Oracle database</span></li>
    <li><span class="function"><a href="function.oci-new-connect.php" class="function" rel="rdfs-seeAlso">oci_new_connect()</a> - Connect to the Oracle server using a unique connection</span></li>
   </ul>
  </p>
 </div>


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