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

📄 function.pg-connect.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 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-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">  <h3 class="title">Description</h3>  <div class="methodsynopsis dc-description">   <span class="type">resource</span> <span class="methodname"><b><b>pg_connect</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_connect()</b> opens a connection to a   PostgreSQL database specified by the   <i><tt class="parameter">connection_string</tt></i>.  </p>  <p class="para">   If a second call is made to <b>pg_connect()</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">   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">  <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_connect()</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_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 /></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-pconnect.html" class="function" rel="rdfs-seeAlso">pg_pconnect()</a></li>    <li class="member"><a href="function.pg-close.html" class="function" rel="rdfs-seeAlso">pg_close()</a></li>    <li class="member"><a href="function.pg-host.html" class="function" rel="rdfs-seeAlso">pg_host()</a></li>    <li class="member"><a href="function.pg-port.html" class="function" rel="rdfs-seeAlso">pg_port()</a></li>    <li class="member"><a href="function.pg-tty.html" class="function" rel="rdfs-seeAlso">pg_tty()</a></li>    <li class="member"><a href="function.pg-options.html" class="function" rel="rdfs-seeAlso">pg_options()</a></li>    <li class="member"><a href="function.pg-dbname.html" class="function" rel="rdfs-seeAlso">pg_dbname()</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-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>

⌨️ 快捷键说明

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