pg_connect

(PHP 3, PHP 4 >= 4.0.0)

pg_connect -- Open a PostgreSQL connection

Description

int pg_connect (string host, string port, string dbname)

int pg_connect (string host, string port, string options, string dbname)

int pg_connect (string host, string port, string options, string tty, string dbname)

int pg_connect (string conn_string)

Returns a connection index on success, or FALSE if the connection could not be made. Opens a connection to a PostgreSQL database. The arguments should be within a quoted string.

Example 1. Using pg_connect arguments


<?php
$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=baaaa");
//connect to a database named "mary" on the host "sheep" with a username and password
?>
     
The arguments available include host, port, tty, options, dbname, user, and password.

If a second call is made to pg_connect() with the same arguments, no new connection will be established, but instead, the connection index of the already opened connection will be returned.

This function returns a connection index that is needed by other PostgreSQL functions. You can have multiple connections open at once.

The previous syntax of: $conn = pg_connect ("host", "port", "options", "tty", "dbname") has been deprecated.

See also pg_pconnect().