Listing 1. Sammple Library Coding

<?php //connect to postgres database $conn=pg_pconnect("user=tim dbname=db_example"); //see if our connection was successful if (!$conn) { //connection failed-exit the page with an //error //you could also try to proceed without the //database-it's up to you echo pg_errormessage($conn); exit; } //now let's set up a common site header function site_header ($title) { return '<HTML> <HEAD> <TITLE>'.$title.'</TITLE> </HEAD> <BODY>'; } //common HTML to be output at the end of the page function site_footer () { return '</BODY></HTML>'; } //a simple wrapper to reduce the code needed //for each postgres query function query($sql) { global $conn; return pg_exec($conn,$sql); } //have PHP4 set up/restore your session state //automatically on every page session_start(); ?>