13.2. An Example

Now that we've reviewed the theoretical background of persistent database connections with PHP and PostgreSQL, it's time to take a look at some practical examples.

If you are a user of PostgreSQL 7.2, you will see that two processes are running at startup time. You can easily find this out by piping the content of the process table to grep:

[hs@athlon html]$ ps ax | grep postgres
21647 pts/4    S      0:00 postgres: stats buffer process
21649 pts/4    S      0:00 postgres: stats collector process
 4338 pts/4    S      0:00 grep postgres

Let's write a script that does nothing but connect to the database and display a message:

 <?php $dbh = pg_connect("host=localhost user=postgres dbname=phpbook"); if (!$dbh) { echo "error while connecting.<br>\n"; } ...

Get PHP and PostgreSQL: Advanced Web Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.