Sophie

Sophie

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

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>Open a PostgreSQL connection</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.pg-close.html">pg_close</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.pg-connection-busy.html">pg_connection_busy</a></div>
 <div class="up"><a href="ref.pgsql.html">PostgreSQL Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.pg-connect" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">pg_connect</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">pg_connect</span> &mdash; <span class="dc-title">Open a PostgreSQL connection</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.pg-connect-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">resource</span> <span class="methodname"><strong>pg_connect</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$connection_string</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$connect_type</code></span>
  ] )</div>

  <p class="para rdfs-comment">
    <span class="function"><strong>pg_connect()</strong></span> opens a connection to a
   PostgreSQL database specified by the
   <em><code class="parameter">connection_string</code></em>.
  </p>
  <p class="para">
   If a second call is made to  <span class="function"><strong>pg_connect()</strong></span> with
   the same <em><code class="parameter">connection_string</code></em> as an existing connection, the
   existing connection will be returned unless you pass
   <strong><code>PGSQL_CONNECT_FORCE_NEW</code></strong> as
   <em><code class="parameter">connect_type</code></em>.
  </p>
  <p class="para">
   The old syntax with multiple parameters
   <strong class="command">$conn = pg_connect(&quot;host&quot;, &quot;port&quot;, &quot;options&quot;, &quot;tty&quot;, &quot;dbname&quot;)
   </strong> has been deprecated.
  </p>
 </div>


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

    <dt>

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

      <p class="para">
       The <em><code class="parameter">connection_string</code></em> 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 <em>keyword = value</em>. Spaces around 
       the equal sign are optional. To write an empty value or a value 
       containing spaces, surround it with single quotes, e.g., <em>keyword = 
       &#039;a value&#039;</em>. Single quotes and backslashes within the value must be 
       escaped with a backslash, i.e., \&#039; and \\.  
      </p>
      <p class="para">
       The currently recognized parameter keywords are:
       <em><code class="parameter">host</code></em>, <em><code class="parameter">hostaddr</code></em>, <em><code class="parameter">port</code></em>,
       <em><code class="parameter">dbname</code></em> (defaults to value of <em><code class="parameter">user</code></em>),
       <em><code class="parameter">user</code></em>,
       <em><code class="parameter">password</code></em>, <em><code class="parameter">connect_timeout</code></em>,
       <em><code class="parameter">options</code></em>, <em><code class="parameter">tty</code></em> (ignored), <em><code class="parameter">sslmode</code></em>,
       <em><code class="parameter">requiressl</code></em> (deprecated in favor of <em><code class="parameter">sslmode</code></em>), and
       <em><code class="parameter">service</code></em>.  Which of these arguments exist depends
       on your PostgreSQL version.
      </p>
      <p class="para">
       The <em><code class="parameter">options</code></em> parameter can be used to set command line parameters 
       to be invoked by the server.
      </p>
     </dd>

    </dt>

    <dt>

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

      <p class="para">
       If <strong><code>PGSQL_CONNECT_FORCE_NEW</code></strong> is passed, then a new connection
       is created, even if the <em><code class="parameter">connection_string</code></em> is identical to
       an existing connection.
      </p>
     </dd>

    </dt>

   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.pg-connect-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   PostgreSQL connection resource on success, <strong><code>FALSE</code></strong> on failure.
  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-function.pg-connect-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-2049">
    <p><strong>Example #1 Using  <span class="function"><strong>pg_connect()</strong></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$dbconn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"dbname=mary"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//connect&nbsp;to&nbsp;a&nbsp;database&nbsp;named&nbsp;"mary"<br /><br /></span><span style="color: #0000BB">$dbconn2&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"host=localhost&nbsp;port=5432&nbsp;dbname=mary"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//&nbsp;connect&nbsp;to&nbsp;a&nbsp;database&nbsp;named&nbsp;"mary"&nbsp;on&nbsp;"localhost"&nbsp;at&nbsp;port&nbsp;"5432"<br /><br /></span><span style="color: #0000BB">$dbconn3&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"host=sheep&nbsp;port=5432&nbsp;dbname=mary&nbsp;user=lamb&nbsp;password=foo"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//connect&nbsp;to&nbsp;a&nbsp;database&nbsp;named&nbsp;"mary"&nbsp;on&nbsp;the&nbsp;host&nbsp;"sheep"&nbsp;with&nbsp;a&nbsp;username&nbsp;and&nbsp;password<br /><br /></span><span style="color: #0000BB">$conn_string&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"host=sheep&nbsp;port=5432&nbsp;dbname=test&nbsp;user=lamb&nbsp;password=bar"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$dbconn4&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn_string</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//connect&nbsp;to&nbsp;a&nbsp;database&nbsp;named&nbsp;"test"&nbsp;on&nbsp;the&nbsp;host&nbsp;"sheep"&nbsp;with&nbsp;a&nbsp;username&nbsp;and&nbsp;password<br /><br /></span><span style="color: #0000BB">$dbconn5&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"host=localhost&nbsp;options='--client_encoding=UTF8'"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//connect&nbsp;to&nbsp;a&nbsp;database&nbsp;on&nbsp;"localhost"&nbsp;and&nbsp;set&nbsp;the&nbsp;command&nbsp;line&nbsp;parameter&nbsp;which&nbsp;tells&nbsp;the&nbsp;encoding&nbsp;is&nbsp;in&nbsp;UTF-8<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

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


 <div class="refsect1 seealso" id="refsect1-function.pg-connect-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"> <span class="function"><a href="function.pg-pconnect.html" class="function" rel="rdfs-seeAlso">pg_pconnect()</a> - Open a persistent PostgreSQL connection</span></li>
    <li class="member"> <span class="function"><a href="function.pg-close.html" class="function" rel="rdfs-seeAlso">pg_close()</a> - Closes a PostgreSQL connection</span></li>
    <li class="member"> <span class="function"><a href="function.pg-host.html" class="function" rel="rdfs-seeAlso">pg_host()</a> - Returns the host name associated with the connection</span></li>
    <li class="member"> <span class="function"><a href="function.pg-port.html" class="function" rel="rdfs-seeAlso">pg_port()</a> - Return the port number associated with the connection</span></li>
    <li class="member"> <span class="function"><a href="function.pg-tty.html" class="function" rel="rdfs-seeAlso">pg_tty()</a> - Return the TTY name associated with the connection</span></li>
    <li class="member"> <span class="function"><a href="function.pg-options.html" class="function" rel="rdfs-seeAlso">pg_options()</a> - Get the options associated with the connection</span></li>
    <li class="member"> <span class="function"><a href="function.pg-dbname.html" class="function" rel="rdfs-seeAlso">pg_dbname()</a> - Get the database name</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.pg-close.html">pg_close</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.pg-connection-busy.html">pg_connection_busy</a></div>
 <div class="up"><a href="ref.pgsql.html">PostgreSQL Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>