Chapter 8. Using PHP

Table of Contents
Building PHP with PostgreSQL libraries
Things to be aware of
A small example
Building practical PHP apps

Building PHP with PostgreSQL libraries

You want to access your PostgreSQL databases from PHP and your webserver.

Solution

Make sure you use the --with-pgsql option when running ./configure for PHP. You can specify the path to Postgresql's files if PHP has problems finding them.

    ./configure --with-pgsql=/usr/local/pgsql ...
   

There were some problems with PHP finding a particular PG header file with the early 4.0.x releases. If you find this, get the current source for PHP and you should be fine.

The other thing to make sure of is that PostgreSQL is listening on an internet port, and that the port is secured. To do the first make sure you have the following in your postgresql.conf file.

    tcpip_socket = true
   

Then make sure that you update your pg_hba.conf file. For example to allow to all your databases from the local machine you would use:

    host    all    127.0.0.1   255.255.255.255  trust
   

You'll want to put the IP address of your webserver in there. Note that this arrangement doesn't impose any password checking - see the comments in the file for details.