PHP/PostgreSQL Lab

Tom Kelliher, CS 318

Feb. 20, 2002

The purpose of this lab is to let you get some hands-on experience connecting to PostgreSQL databases through PHP.

  1. In ~kelliher/pub/cs318 on phoenix you'll find three files: login.html, authenticate.php, and query.php. Copy them to your public_html directory and verify that you can access the registration database via the files you just copied.

  2. Modify the files so that you can access any database on the system. You'll need to do the following:
    1. Note that the files, as is, use two levels of authentication. For this extension, the second level is unnecessary. Eliminate it.

    2. You'll need to add a field to the login form so the user can specify which database to which to connect. You'll need to make use of this information in the pg_connect() call and store it as an additional session variable.

    3. Fix-up anything else necessary to generalize these files.

  3. As is, authenticate.php will fail if called directly. This makes sense if the session variables haven't been created yet, but it will still fail even if the session variables have been created. Fix this anomalous behavior.

  4. Instead of returning a table, INSERT, DELETE, and UPDATE return the number of tuples affected. Modify query.php to reflect this. Refer to the descriptions of stristr and pg_cmdtuples in the online PHP documentation.



Thomas P. Kelliher
Mon Feb 18 16:21:57 EST 2002
Tom Kelliher