Table 3. Postmaster and PHP
Postmaster PHP Status
postmaster & pg_connect("dbname=MyDbName");
OK
postmaster -i & pg_connect("dbname=MyDbName");
OK
postmaster & pg_connect("host=localhost dbname=MyDbName");
Unable to connect to PostgreSQL server: connectDB() failed:
Is the postmaster running and accepting TCP/IP (with -i)
connection at 'localhost' on port '5432'? in /path/to/file.php
on line 20.
postmaster -i & pg_connect("host=localhost dbname=MyDbName");
OK
A connection to PostgreSQL server can be established with
the following value pairs set in the command string: $conn
= pg_connect("host=myHost port=myPort tty=myTTY options=myOptions
dbname=myDB user=myUser password=myPassword ");
The previous syntax of: $conn = pg_connect ("host",
"port", "options", "tty",
"dbname") has been deprecated.
Environmental variables affect PostgreSQL server/client
behavior. For example, PostgreSQL module will lookup PGHOST
environment variable when the hostname is omitted in the
connection string. Supported environment variables are different
from version to version. Refer to PostgreSQL Programmer's
Manual (libpq - Environment Variables) for details.
Make sure you set environment variables for appropriate
user. Use $_ENV or getenv() to check which environment variables
are available to the current process.
Example 1. Setting default parameters
PGHOST=pgsql.example.com
PGPORT=7890
PGDATABASE=web-system
PGUSER=web-user
PGPASSWORD=secret
PGDATESTYLE=ISO
PGTZ=JST
PGCLIENTENCODING=EUC-JP
export PGHOST PGPORT PGDATABASE PGUSER PGPASSWORD PGDATESTYLE
PGTZ PGCLIENTENCODING
Predefined Constants
The constants below are defined by this extension, and will
only be available when the extension has either been compiled
into PHP or dynamically loaded at runtime.
PGSQL_ASSOC (integer)
PGSQL_NUM (integer)
PGSQL_BOTH (integer)
PGSQL_CONNECTION_BAD (integer)
PGSQL_CONNECTION_OK (integer)
PGSQL_SEEK_SET (integer)
PGSQL_SEEK_CUR (integer)
PGSQL_SEEK_END (integer)
PGSQL_ESCAPE_STRING (integer)
PGSQL_ESCAPE_BYTEA (integer)
PGSQL_EMPTY_QUERY (integer)
PGSQL_COMMAND_OK (integer)
PGSQL_TUPLES_OK (integer)
PGSQL_COPY_OUT (integer)
PGSQL_COPY_IN (integer)
PGSQL_BAD_RESPONSE (integer)
PGSQL_NONFATAL_ERROR (integer)
PGSQL_FATAL_ERROR (integer)