Before you start
In this tutorial, Part 1 of a three-part series, you will set up both the user and the administrative sides of the storefront. The shopper will be able to browse items in the storefront, and administrators will be able to add or edit items in the storefront using a Web browser. User sessions are also covered. This tutorial assumes basic knowledge of PHP, including if statements, functions, include and require statements, as well as knowledge of variables submitted using GET and POST.
Our hypothetical situation for this series is Ghastly Computers, a computer hardware and software shop. Its owners want to set up a presence online, and for obvious reasons, they want the online store to be constructed and managed with minimal fuss. This three-part series covers the whole process, from creating a storefront with an integrated shopping cart from scratch in PHP to using PayPal for payment. With e-commerce booming and a growing number of online shoppers using PayPal and other forms of payment to make purchases, creating an online storefront is a good way to attract customers from around the world. The benefit of creating a shopping cart from scratch is the absolute control it gives programmers.
Part 1 focuses on setting up a Derby database and creating the basic storefront. You will access Derby through PHP data objects. User sessions are started to help set up for Part 2 of the series, where a shopping cart will be associated with a user's session ID.
Part 2 covers creating and managing the shopping cart. The shopping cart will be stored in the Derby database, and the user's session ID will become the cart ID. The shopping cart, if containing items, will be shown under the listing of categories in the storefront with Manage cart and Checkout links. Checking out will involve taking a user's Ship-to/Bill-to information, which will be submitted for payment to PayPal. After completing the payment to PayPal, the user is shown a Thank you page and given a new session ID.
Part 3 covers viewing orders, shipping, and e-mail notification. Transactions using PHP data objects will also be introduced. Adding shipping to the checkout process will be incorporated via UPS, offering real-time shipping prices. E-mail notification will be sent to the customer showing an order summary. PayPal, by default, also sends a payment confirmation e-mail to the user and the merchant.
In this tutorial, you prepare for creating a storefront from scratch by setting up a Derby database that houses the information of your storefront. Editing and querying the database is accomplished via PHP data objects (PDOs), as PDOs encapsulate much of the technical and database-specific details on connecting to and executing SQL queries and commands in a database. The owner of Ghastly Computers has requested an administrative (from here on referred to as "admin") and user entry into the storefront. Adding and editing items via a Web browser makes it easy for administrators anywhere, including the new programmer Ghastly Computers is planning to hire a few states away, to update the content of a storefront and the items contained therein. User sessions will also be introduced to set up the connection between a user and a shopping cart in Part 2 so that, as users move between areas of a storefront, their shopping carts will be carried with them.
To follow along, you will need to install and test the following tools:
- Web server
- Pick any Web server and operating system. Feel free to use Apache V2.X, or the IBM HTTP Server.
- PHP
- Due to the use of PHP data objects, the latest version, PHP V5.1, is necessary to fully follow along in this tutorial. Note that V5.1 is is a release candidate (RC) and is not yet an official release. Be sure to configure PHP with the following option to include support for Derby:
--with-pdo-odbc=ibm-db2,/home/db2inst1/sqllib. See Resources for information about configuring Apache or the IBM HTTP Server with PHP. - Database
- This tutorial uses Derby. Download Derby V10.1, the current IBM DB2 JDBC Universal Driver, and the DB2® run-time client from IBM. Be sure to follow the instructions on each page carefully. Follow either the Linux® or Windows® instructions for downloading and installing the DB2 run-time client.
You may also use Cloudscape for this tutorial. The internals of Cloudscape are the same as Derby. However, the DB2 JDBC Universal Driver and other things are packaged into Cloudscape, and it is supported by IBM. Download Cloudscape V10.1, and the DB2 run-time client from IBM. - Java™
- Derby requires Java technology. I have found the gcj provided in Red Hat Linux distributions insufficient. Download Java technology from Sun.




