CS145 - Autumn 2009
Introduction to Databases
Project Part 3: AuctionBase Web Site
Due Thursday November 19

Overview

As a baseline, you will design a set of queries and updates for your AuctionBase system and create a simple web interface for them using PHP. Ambitious students may turn the simple front-end into a user-friendly web interface that looks like a real auction site, and may exploit other MySQL and/or PHP features for additional functionality. Use your creativity. Several projects will be selected to be demonstrated on the last day in class (for glory, not grades).

Getting familiar with PHP

Your first task is to become familiar with PHP by setting up your web directory and experimenting with sample PHP pages.

Even if you haven't used PHP before (and we're assuming you haven't), it may be possible to complete the basic project with minimal help from additional PHP materials. However, if you like to read tutorial materials before jumping in, or if you're feeling confused about PHP, we recommend this PHP MySQL Introduction. This reference, and many others you may find useful, are linked to the class Support Materials page.

Functionality

The functionality of your final AuctionBase system is quite flexible and open-ended, however you must implement at least the following basic capabilities in order to receive full credit on the project. Your AuctionBase system should support realistic bidding behavior. Specifically, the system should not accept bids on closed auctions, from users that don't exist, or that are less than or equal to the current highest bid. Also, as specified above with "Automatic auction closing," a bid at the buy-price should close the auction. You can choose to implement these requirements either by querying your database in PHP or by creating additional triggers.

Full credit also requires general error- and constraint-checking as specified in the Transactions, errors, and constraint-checking section of this document, below. All of your required constraints from Part 2 of the project should be enforced in your "live" AuctionBase system.

Here are some examples of additional capabilities beyond our basic expectations that you might consider adding to your system if you're feeling ambitious. Use your imagination to come up with even more.

A note on extra functionality: You can receive full credit on the project by implementing just the basic capabilities in the first bullet list, constraint-checking, and a simple web interface. That is the standard against which projects will be graded. Many of you will realize that it is not difficult to add functionality or "pretty-up" the interface. You will not receive additional points for doing so. However, in addition to the possibility of winning the AuctionBase contest (described below), we will make a note of students whose project goes well beyond the basic expectations. Such notes do not affect the grading curve, but they can on occasion affect an individual grade -- in a borderline case, or when an earlier project part was botched or missed entirely. If you have questions about this policy, please ask the course staff.

Miscellaneous hints and requirements

Transactions, errors, and constraint-checking

Commands that modify the database need to be handled carefully, and you should group them into transactions whenever it makes sense for them to be executed as a unit. Using transactional behavior, each unit should either complete in its entirety or, due to failed constraints or other errors, should not modify the database at all. Constraint violations or other errors due to data entry errors or bad input values should be managed gracefully: it should be possible for users to continue interacting with the system after a constraint violation is detected, and the database should not be corrupt. You should inform users when errors occur, but your error message need not indicate the exact violation that caused the error.

If it helps, you may assume that AuctionBase has only one user operating on it at a time. Although transactions may be useful for database modifications and constraint-checking, you do not need to worry about transactions as a concurrency-control mechanism. That said, even without special effort your system may turn out to be fairly robust for multiple users.

Reminder: You must create your tables using the "InnoDB" storage engine for constraint-checking and transactions to work properly.

Here is an example of how you might structure code that involves database modifications.
   <?php

    // kill script after 20 seconds
    set_time_limit(20);

    // function to handle errors: rollback and exit
    function error_exit ($con, $errormsg="unspecified"){
       echo "We're sorry: a system error occurred.<p></p>";
       echo "Error Message: " . $errormsg;
       mysqli_rollback($con);  // if error, roll back transaction
       mysqli_close($con);
       exit();
    }

    // establish MySQL connection
    $link = mysqli_connect($host,$username,$password,$dbname);
    if (mysqli_connect_errno()) {
       printf("Connect failed: %s\n", mysqli_connect_error());
       exit();
    }

    // step 1: turn off auto-commit
    $result = mysqli_autocommit($link, FALSE);
    if (!$result) {
       error_exit($link, "autocommit");  // if error, roll back transaction
    }

    // step 2: perform action
    // run command 1
    $com1 = "select/insert/delete/update ... ";
    $result = mysqli_query($link, $com1);
    if (!$result) {
       error_exit($link, "com1");  // if error, roll back transaction
    }

    // run command 2
    $com2 = "select/insert/delete/update ... ";
    $result = mysqli_query($link, $com2);
    if (!$result) {
       error_exit($link, "com2");  // if error, roll back transaction
    }
   
    // step 3: assuming no errors, commit transaction
    $result = mysqli_commit($link);
    if (!$result) {
       error_exit($link, "commit");  // if error, roll back transaction
    }
    echo "Success";

    // close connection
    mysqli_close($link);
    ?>

Here's some explanation of the above code:

User interface

While the functionality of your AuctionBase system is quite open-ended, the interface itself is extremely open-ended. CS145 is not a user interface class and you can certainly get full credit for a solid system with simple input boxes, menus, and simple HTML output tables, similar in style to the sample PHP files and code in the PHP MySQL Introduction. (However, under no circumstances should you be exposing SQL to the end user.) Of course we welcome much snazzier interfaces, with the zenith being a near-replica of eBay itself.

Browser compatibility

Before turning in your final project please ensure that it operates correctly using the Firefox browser on the Myth machines. If there is a compelling reason you cannot make your system work in the Myth browser environment (e.g., you really want to exploit certain features in Internet Explorer), you must get "preapproval" from the course staff to use a different browser environment. Send an email message to cs145@cs.stanford.edu telling us precisely what browser environment you wish to use for your project. The message must be sent by Friday November 13 so that we have time to work things out if your browser environment poses a problem for us. You will receive a reply within 24 hours of your message, and you must receive a positive confirmation message before assuming that your alternate environment is okay.

When the preapproval process is not followed, projects that have problems on the Myth Firefox browsers may lose points, possibly all points if we cannot run your project at all.

System testing and open connections

We suggest that you debug your queries directly on MySQL before hooking them into your web interface. Use the MySQL command-line interface first, to ensure that your queries are working properly and are finishing in a reasonable amount of time. In the command-line interface, you can kill runaway queries using Ctrl-C. Once you are certain your queries are working properly, incorporate them into your web interface.

If you notice an unexplained slowdown in system performance, it may be due to a large number of open MySQL connections. Here are some tips to avoid this problem:

Using other languages and tools

You are not required to implement your AuctionBase web site using PHP. Any web programming environment and means of connecting to MySQL is fine with us. However, only PHP has guaranteed support from the course staff in terms of system problems, knowledge, and general help. If you choose to use alternate languages or tools, you may be on your own, and you are still required to meet the project specifications.

Most importantly: It is imperative that we can run your project with a minimum of effort on the Myth machines. Due to the size of the class we will not be able to set up separate environments for individual projects, or conduct private demos.


Having trouble?

If you run into difficulties, before contacting the course staff please consult the Project Part 3 FAQ Page. We will keep it up-to-date with answers to common questions.

What to submit

Prepare a submission directory containing a text file called README.txt, along with all of the files necessary to make your website run correctly when copied into the grader's cgi-bin directory.

Your README.txt file should include at least the following, in this order:

  1. The line "I WOULD LIKE TO ENTER THE AUCTIONBASE CONTEST" if you want your project to be considered for the contest described below. Otherwise leave blank.
  2. A description of how the user gets to each of the basic capabilities required by the assignment.
  3. A short description of the input parameters a user can provide when browsing auctions.
  4. A list of any capabilities in your system beyond the basic requirements, how the user gets to them, and a short description of any relevant input parameters.

Since we will be connecting to your MySQL database through your web application, make sure that before submission and throughout the grading period your database is loaded with all of the appropriate data, constraints, and triggers.

If you did not use PHP: It's imperative that we can run your project with a minimum of effort on the Myth machines. You must submit detailed instructions and all of your source code.

As usual, from your submission directory execute the script:

    /usr/class/cs145/bin/submit-project
You may resubmit as many times as you like, however only the latest submission and timestamp are saved, and those are what we will use for grading your work and determining late penalties. Submissions via email will not be accepted.

Remember that points may be deducted if you do not follow the submission procedures exactly as specified.

The (Optional) CS145 AuctionBase Contest

We will select a small number of AuctionBase systems as winners of our annual CS145 AuctionBase Contest. Winners of the contest will:

The criteria for selection will be some combination of beyond-the-basics functionality and a good user interface.

Important - If you want your project to be considered for the contest, you must clearly indicate so at the top of your README file, as described in What to submit above.