⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 function.pg-pconnect.html

📁 php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Open a persistent PostgreSQL connection</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.pg-parameter-status.html">pg_parameter_status</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.pg-ping.html">pg_ping</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-pconnect" class="refentry"> <div class="refnamediv">  <h1 class="refname">pg_pconnect</h1>  <p class="verinfo">(PHP 4, PHP 5)</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">  <h3 class="title">Description</h3>  <div class="methodsynopsis dc-description">   <span class="type">resource</span> <span class="methodname"><b><b>pg_pconnect</b></b></span>    ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$connection_string</tt></span>   [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$connect_type</tt></span>  ] )</div>  <p class="para rdfs-comment">   <b>pg_pconnect()</b> opens a connection to a   PostgreSQL database. It returns a connection resource that is   needed by other PostgreSQL functions.  </p>  <p class="para">   If a second call is made to <b>pg_pconnect()</b> with   the same <i><tt class="parameter">connection_string</tt></i> as an existing connection, the   existing connection will be returned unless you pass   <b><tt>PGSQL_CONNECT_FORCE_NEW</tt></b> as   <i><tt class="parameter">connect_type</tt></i>.  </p>  <p class="para">   To enable persistent connection, the <a href="pgsql.configuration.html#ini.pgsql.allow-persistent" class="link">pgsql.allow_persistent</a>   <var class="filename">php.ini</var> directive must be set to &quot;On&quot; (which is the default).   The maximum number of persistent connection can be defined with the <a href="pgsql.configuration.html#ini.pgsql.max-persistent" class="link">pgsql.max_persistent</a>   <var class="filename">php.ini</var> directive (defaults to -1 for no limit). The total number   of connections can be set with the <a href="pgsql.configuration.html#ini.pgsql.max-links" class="link">pgsql.max_links</a>    <var class="filename">php.ini</var> directive.  </p>  <p class="para">   <a href="function.pg-close.html" class="function">pg_close()</a> will not close persistent links   generated by <b>pg_pconnect()</b>.  </p> </div> <div class="refsect1 parameters">  <h3 class="title">Parameters</h3>  <p class="para">   <dl>    <dt>     <span class="term"><i><tt class="parameter">connection_string</tt></i></span>     <dd>      <p class="para">       The <i><tt class="parameter">connection_string</tt></i> 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 <i>keyword = value</i>. Spaces around        the equal sign are optional. To write an empty value or a value        containing spaces, surround it with single quotes, e.g., <i>keyword =        &#039;a value&#039;</i>. 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:       <i><tt class="parameter">host</tt></i>, <i><tt class="parameter">hostaddr</tt></i>, <i><tt class="parameter">port</tt></i>,       <i><tt class="parameter">dbname</tt></i>, <i><tt class="parameter">user</tt></i>,       <i><tt class="parameter">password</tt></i>, <i><tt class="parameter">connect_timeout</tt></i>,       <i><tt class="parameter">options</tt></i>, <i><tt class="parameter">tty</tt></i> (ignored), <i><tt class="parameter">sslmode</tt></i>,       <i><tt class="parameter">requiressl</tt></i> (deprecated in favor of <i><tt class="parameter">sslmode</tt></i>), and       <i><tt class="parameter">service</tt></i>.  Which of these arguments exist depends       on your PostgreSQL version.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">connect_type</tt></i></span>     <dd>      <p class="para">       If <b><tt>PGSQL_CONNECT_FORCE_NEW</tt></b> is passed, then a new connection       is created, even if the <i><tt class="parameter">connection_string</tt></i> is identical to       an existing connection.      </p>     </dd>    </dt>   </dl>  </p> </div> <div class="refsect1 returnvalues">  <h3 class="title">Return Values</h3>  <p class="para">   PostgreSQL connection resource on success, <b><tt>FALSE</tt></b> on failure.  </p> </div>  <div class="refsect1 examples">  <h3 class="title">Examples</h3>  <p class="para">   <div class="example">    <p><b>Example #1 Using <b>pg_pconnect()</b></b></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_pconnect</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_pconnect</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_pconnect</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_pconnect</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 /></span><span style="color: #0000BB">?&gt;</span></span></code></div>    </div>   </div>  </p> </div>  <div class="refsect1 seealso">  <h3 class="title">See Also</h3>  <p class="para">   <ul class="simplelist">    <li class="member"><a href="function.pg-connect.html" class="function" rel="rdfs-seeAlso">pg_connect()</a></li>    <li class="member">     <a href="features.persistent-connections.html" class="link">     Persistent Database Connections</a>    </li>   </ul>  </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.pg-parameter-status.html">pg_parameter_status</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.pg-ping.html">pg_ping</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>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -