Article
Beginning Databases with PostgreSQL - Chapter 15: Accessing PostgreSQL from PHP
Adding PostgreSQL Support to PHP
Before you can begin developing PHP scripts that interface with a PostgreSQL database, you will need to include PostgreSQL support in your PHP installation.
If you're not sure whether your existing PHP installation already has PostgreSQL support, create a simple script named phpinfo.php (which should be placed in your web server's document root), containing the following line:
<?php
phpinfo();
?>
Examine the output of this script in your web browser. If PostgreSQL support has already been included, the output will contain a section similar to the following:
If your PHP installation already has PostgreSQL support, you can continue on to the next section.
If you have the PHP source code, it is fairly easy to add PostgreSQL support. Simply pass the --with-pgsql option to the configure script:
$ ./configure --with-pgsql
You can optionally specify the directory of your PostgreSQL installation if the configure script is unable to locate it by itself:
$ ./configure --with-pgsql=/var/lib/pgsql
Remember that you might need to pass additional options to the configure script depending on your build requirements. For example, to build PHP with support for PostgreSQL, LDAP, and XML, you would use the following command line:
$ ./configure --with-pgsql --with-imap --enable-xml
Refer to the PHP documentation (specifically the INSTALL document included with the PHP distribution) for additional compilation options and installation instructions. You can also find them at http://www.php.net/manual/en/html/installation.html.