<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.pgsql.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.pg-pconnect.php',
    1 => 'pg_pconnect',
    2 => 'Open a persistent PostgreSQL connection',
  ),
  'up' => 
  array (
    0 => 'ref.pgsql.php',
    1 => 'PostgreSQL Functions',
  ),
  'prev' => 
  array (
    0 => 'function.pg-parameter-status.php',
    1 => 'pg_parameter_status',
  ),
  'next' => 
  array (
    0 => 'function.pg-ping.php',
    1 => 'pg_ping',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/pgsql/functions/pg-pconnect.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.pg-pconnect" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">pg_pconnect</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">pg_pconnect</span> &mdash; <span class="dc-title">Open a persistent PostgreSQL connection</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.pg-pconnect-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>pg_pconnect</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$connection_string</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$flags</code><span class="initializer"> = 0</span></span>): <span class="type"><span class="type"><a href="class.pgsql-connection.php" class="type PgSql\Connection">PgSql\Connection</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>pg_pconnect()</strong></span> opens a connection to a
   PostgreSQL database. It returns a <span class="classname"><a href="class.pgsql-connection.php" class="classname">PgSql\Connection</a></span> instance that is
   needed by other PostgreSQL functions.
  </p>
  <p class="para">
   If a second call is made to <span class="function"><strong>pg_pconnect()</strong></span> with
   the same <code class="parameter">connection_string</code> as an existing connection, the
   existing connection will be returned unless you pass
   <strong><code><a href="pgsql.constants.php#constant.pgsql-connect-force-new">PGSQL_CONNECT_FORCE_NEW</a></code></strong> as
   <code class="parameter">flags</code>.
  </p>
  <p class="para">
   To enable persistent connections, the
   <a href="pgsql.configuration.php#ini.pgsql.allow-persistent" class="link">pgsql.allow_persistent</a>
   <var class="filename">php.ini</var> directive must be set to <code class="literal">&quot;On&quot;</code> (which is the default).
   The maximum number of persistent connections can be defined with the
   <a href="pgsql.configuration.php#ini.pgsql.max-persistent" class="link">pgsql.max_persistent</a>
   <var class="filename">php.ini</var> directive (defaults to <code class="literal">-1</code> for no limit).
   The total number of connections can be set with the
   <a href="pgsql.configuration.php#ini.pgsql.max-links" class="link">pgsql.max_links</a>
   <var class="filename">php.ini</var> directive.
  </p>
  <p class="para">
   <span class="function"><a href="function.pg-close.php" class="function">pg_close()</a></span> will not close persistent links
   generated by <span class="function"><strong>pg_pconnect()</strong></span>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.pg-pconnect-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">connection_string</code></dt>
     <dd>
      <p class="para">
       The <code class="parameter">connection_string</code> can be empty to use all default parameters, or it 
       can contain one or more parameter settings separated by whitespace. 
       Each parameter setting is in the form <code class="literal">keyword = value</code>. Spaces around 
       the equal sign are optional. To write an empty value or a value 
       containing spaces, surround it with single quotes, e.g., <code class="literal">keyword = 
       &#039;a value&#039;</code>. Single quotes and backslashes within the value must be 
       escaped with a backslash, i.e., <code class="literal">\&#039;</code> and <code class="literal">\\</code>.
      </p>
      <p class="para">
       The currently recognized parameter keywords are:
       <code class="parameter">host</code>, <code class="parameter">hostaddr</code>, <code class="parameter">port</code>,
       <code class="parameter">dbname</code>, <code class="parameter">user</code>,
       <code class="parameter">password</code>, <code class="parameter">connect_timeout</code>,
       <code class="parameter">options</code>, <code class="parameter">tty</code> (ignored), <code class="parameter">sslmode</code>,
       <code class="parameter">requiressl</code> (deprecated in favor of <code class="parameter">sslmode</code>), and
       <code class="parameter">service</code>.
       Which of these arguments exist depends on the PostgreSQL version.
      </p>
     </dd>
    
    
     <dt><code class="parameter">flags</code></dt>
     <dd>
      <p class="para">
       If <strong><code><a href="pgsql.constants.php#constant.pgsql-connect-force-new">PGSQL_CONNECT_FORCE_NEW</a></code></strong> is passed, then a new connection
       is created, even if the <code class="parameter">connection_string</code> is identical to
       an existing connection.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.pg-pconnect-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns a <span class="classname"><a href="class.pgsql-connection.php" class="classname">PgSql\Connection</a></span> instance on success,  or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on failure.
  </p>
 </div>


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

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.1.0</td>
      <td>
       Returns a <span class="classname"><a href="class.pgsql-connection.php" class="classname">PgSql\Connection</a></span> instance now;
       previously, a <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> was returned.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>

 
 <div class="refsect1 examples" id="refsect1-function.pg-pconnect-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 Using <span class="function"><strong>pg_pconnect()</strong></span></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">// Connect to a database named "mary"<br /></span><span style="color: #0000BB">$dbconn </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_pconnect</span><span style="color: #007700">(</span><span style="color: #DD0000">"dbname=mary"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Connect to a database named "mary" on "localhost" at port "5432"<br /></span><span style="color: #0000BB">$dbconn2 </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_pconnect</span><span style="color: #007700">(</span><span style="color: #DD0000">"host=localhost port=5432 dbname=mary"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Connect to a database named "mary" on the host "sheep" with a username and password<br /></span><span style="color: #0000BB">$dbconn3 </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_pconnect</span><span style="color: #007700">(</span><span style="color: #DD0000">"host=sheep port=5432 dbname=mary user=lamb password=foo"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Connect to a database named "test" on the host "sheep" with a username and password<br /></span><span style="color: #0000BB">$conn_string </span><span style="color: #007700">= </span><span style="color: #DD0000">"host=sheep port=5432 dbname=test user=lamb password=bar"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$dbconn4 </span><span style="color: #007700">= </span><span style="color: #0000BB">pg_pconnect</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn_string</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.pg-pconnect-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.pg-connect.php" class="function" rel="rdfs-seeAlso">pg_connect()</a> - Open a PostgreSQL connection</span></li>
    <li>
     <a href="features.persistent-connections.php" class="link">
     Persistent Database Connections</a>
    </li>
   </ul>
  </p>
 </div>

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