Contents / Previous / Next


Installation Issues

Postgresql support is usually already included in the PHP distribution.
If not, you have to re-compile PHP to enable PostgreSQL support.
The option --with-pgsql[=DIR] is required when you compile PHP. DIR is the PostgreSQL base install directory, defaults to /usr/local/pgsql.

If the PostgreSQL shared object module is available, it may be loaded using the extension directive in php.ini or the dl() function.


Runtime Configuration

The behavior of PHP PostgreSQL functions is affected by the settings in php.ini:

pgsql.allow_persistent "1" :
Whether to allow persistent Postgres connections. pgsql.max_persistent integer

pgsql.max_persistent "-1" :
The maximum number of persistent Postgres connections per process.

pgsql.max_links "-1" :
The maximum number of Postgres connections per process, including persistent connections.

You can change these option directly from PHP with the ini_set() function. You can find a short explanation of the configuration directives in the documentation of ini_set().


PostgreSQL Environment Variables

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.
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 default parameters (code to use in a shell or your .profile):
PGHOST=pgsql.example.com
PGPORT=5432
PGDATABASE=web-system
PGUSER=web-user
PGPASSWORD=secret
PGDATESTYLE=ISO
PGTZ=JST
PGCLIENTENCODING=EUC-JP

export PGHOST PGPORT PGDATABASE PGUSER 
export PGPASSWORD PGDATESTYLE PGTZ PGCLIENTENCODING
You can see a list of all the environmental variables by using phpinfo().



Predefined Constants used as parameters or return values by PHP's PostgreSQL functions :

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)