(PHP 3 <= 3.0.18, PHP 4 >= 4.0.0)

pg_pconnect -- Open a persistent PostgreSQL connection


int pg_pconnect (string connection_string)

pg_pconnect() opens a connection to a PostgreSQL database. It returns a connection resource that is needed by other PostgreSQL functions.

It returns a connection resource on success, or FALSE if the connection could not be made. The arguments should be within a quoted string. The arguments available include host, port, tty, options, dbname, user, and password.

Example 1. Using pg_connect

$dbconn = pg_connect ("dbname=mary");
//connect to a database named "mary"
$dbconn2 = pg_connect ("host=localhost port=5432 dbname=mary");
// connect to a database named "mary" on "localhost" at port "5432"
$dbconn3 = pg_connect ("host=sheep port=5432 dbname=mary user=lamb password=foo");
//connect to a database named "mary" on the host "sheep" with a username and password
$conn_string = "host=sheep port=5432 dbname=test user=lamb password=bar";
$dbconn4 = pg_connect ($conn_string);
//connect to a database named "test" on the host "sheep" with a username and password

If a second call is made to pg_pconnect() with the same arguments, no new connection will be established, but instead, the connection resource of the already opened connection will be returned. You can have multiple connections to the same database if you use different connection patameters. (i.e. Use different username)

Multiple parameters syntax for pg_pconnect() $conn = pg_pconnect ("host", "port", "options", "tty", "dbname") has been deprecated.

To enable persistent connection, pgsql.allow_persistent php.ini directive must be set to "On". (Default is On) Max number of persistent connection can be defined by pgsql.max_persistent php.ini directive. (Default is -1 which is no limit) Total number of connection can be set by pgsql.max_links php.ini directive.

pg_close() will not close persistent links generated by pg_pconnect().

See also pg_connect().