pg_pconnect
(PHP 4, PHP 5, PHP 7, PHP 8)
pg_pconnect — 打开一个持久的 PostgreSQL 连接
参数
connection_string
-
connection_string 可以为空以使用所有默认参数,也可以包含一个或多个由空格分隔的参数设置。每个参数设置的形式为
keyword = value。等号旁边的空格是可选的。要写入空值或包含空格的值,请用单引号将其括起来,例如,keyword =
'a value'。值中的单引号和反斜线必须用反斜线转义,即 \' 和 \\。
当前可识别的参数关键字是:host、hostaddr、port、dbname、user、password、connect_timeout、options、tty(已忽略)、sslmode、requiressl(已弃用以支持
sslmode)和 service。存在哪些参数取决于 PostgreSQL 版本。
flags
-
如果传递了 PGSQL_CONNECT_FORCE_NEW,则会创建新连接,即使 connection_string 与现有连接相同。
示例
示例 #1 使用 pg_pconnect()
<?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);
?>