1
0
mirror of https://github.com/php/doc-zh.git synced 2026-04-24 08:38:08 +02:00
Files
2025-02-24 00:20:06 +08:00

153 lines
5.7 KiB
XML
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 3b2503bdcbbffc9bd1381078ee06c298d4f8a49a Maintainer: HonestQiao Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<refentry xml:id="function.pg-pconnect" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>pg_pconnect</refname>
<refpurpose>打开一个持久的 PostgreSQL 连接</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type class="union"><type>PgSql\Connection</type><type>false</type></type><methodname>pg_pconnect</methodname>
<methodparam><type>string</type><parameter>connection_string</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer>0</initializer></methodparam>
</methodsynopsis>
<para>
<function>pg_pconnect</function> 打开一个到 PostgreSQL 数据库的持久连接。返回其它 PostgreSQL 函数所需要的 <classname>PgSql\Connection</classname> 实例。
</para>
<para>
如果使用与已有连接相同的 <parameter>connection_string</parameter><function>pg_pconnect</function>
进行第二次调用,则将返回已有连接,除非将 <constant>PGSQL_CONNECT_FORCE_NEW</constant> 传递给 <parameter>flags</parameter>
</para>
<para>
要打开持久连接,&php.ini; 中的 <link linkend="ini.pgsql.allow-persistent">pgsql.allow_persistent</link> 参数必须为
<literal>"On"</literal>(也是默认值)。最大持久连接数由 &php.ini; 中的 <link linkend="ini.pgsql.max-persistent">pgsql.max_persistent</link>
参数定义(默认为 <literal>-1</literal> 表示没有限制)。所有连接的数量可由 &php.ini; 中的 <link linkend="ini.pgsql.max-links">pgsql.max_links</link> 参数设置。
</para>
<para>
<function>pg_close</function> 不能关闭由 <function>pg_pconnect</function> 打开的持久连接。
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>connection_string</parameter></term>
<listitem>
<para>
<parameter>connection_string</parameter> 可以为空以使用所有默认参数,也可以包含一个或多个由空格分隔的参数设置。每个参数设置的形式为
<literal>keyword = value</literal>。等号旁边的空格是可选的。要写入空值或包含空格的值,请用单引号将其括起来,例如,<literal>keyword =
'a value'</literal>。值中的单引号和反斜线必须用反斜线转义,即 <literal>\'</literal><literal>\\</literal>
</para>
<para>
当前可识别的参数关键字是:<parameter>host</parameter><parameter>hostaddr</parameter><parameter>port</parameter><parameter>dbname</parameter><parameter>user</parameter><parameter>password</parameter><parameter>connect_timeout</parameter><parameter>options</parameter><parameter>tty</parameter>(已忽略)、<parameter>sslmode</parameter><parameter>requiressl</parameter>(已弃用以支持
<parameter>sslmode</parameter>)和 <parameter>service</parameter>。存在哪些参数取决于 PostgreSQL 版本。
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>flags</parameter></term>
<listitem>
<para>
如果传递了 <constant>PGSQL_CONNECT_FORCE_NEW</constant>,则会创建新连接,即使 <parameter>connection_string</parameter> 与现有连接相同。
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
成功时返回 <classname>PgSql\Connection</classname> 实例,&return.falseforfailure;
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.1.0</entry>
<entry>
现在返回 <classname>PgSql\Connection</classname> 实例;之前返回 &resource;
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>使用 <function>pg_pconnect</function></title>
<programlisting role="php">
<![CDATA[
<?php
// 连接到名为 "mary" 的数据库
$dbconn = pg_pconnect("dbname=mary");
// 连接到主机为 "localhost",端口为 "5432" 名为 "mary" 的水库
$dbconn2 = pg_pconnect("host=localhost port=5432 dbname=mary");
// 使用用户名和密码连接到主机为 "sheep",名为 "mary" 的数据库
$dbconn3 = pg_pconnect("host=sheep port=5432 dbname=mary user=lamb password=foo");
// 使用用户名和密码连接到主机为 "sheep",名为 "test" 的数据库
$conn_string = "host=sheep port=5432 dbname=test user=lamb password=bar";
$dbconn4 = pg_pconnect($conn_string);
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>pg_connect</function></member>
<member>
<link linkend="features.persistent-connections">持久数据库连接</link>
</member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->