-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathpg-pconnect.xml
More file actions
executable file
·152 lines (143 loc) · 5.72 KB
/
pg-pconnect.xml
File metadata and controls
executable file
·152 lines (143 loc) · 5.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?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
-->