Client 2—Adding Error Checking

You've seen that PHP will simply dump error messages into the output stream sent to the web browser. That makes it easy to debug PHP scripts, but it's not particularly kind to your users.

There are two error messages displayed in Figure 15.4. The first error occurs when you call the pg_connect() function. Notice that the error message includes the name of the script that was running at the time the error occurred. In this case, my_connect__pg.php encountered an error on line 9—that's the call to pg_connect(). The second error message comes from line 13 of client1b.php, where you try to use the database handle returned by my_connect_pg(). When the first error occurred, pg_connect() returned an invalid handle and ...

Get PostgreSQL, Second Edition 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.