Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Create a Web storefront using PHP, Derby and PayPal, Part 1: Pouring the foundation database

Learn how to configure the tools you need and set up two user types

Tyler Anderson (tyleranderson5@yahoo.com), Freelance Writer, Stexar Corp.
Tyler Anderson graduated with a degree in computer science from Brigham Young University in 2004 and is currently in his last semester as a master's student in computer engineering. In the past, he worked as a database programmer for DPMG.com, and he is currently an engineer for Stexar Corp., based in Beaverton, Ore.

Summary:  This series chronicles the building of a Web storefront in PHP using PHP Data Objects to access a Derby database. The storefront includes a user manageable shopping cart that allows item purchases using PayPal, and includes the ability for merchants to notify customers via e-mail on successful orders automatically.

View more content in this series

Date:  08 Nov 2005
Level:  Intermediate PDF:  A4 and Letter (1064 KB | 42 pages)Get Adobe® Reader®

Activity:  6751 views
Comments:  

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.

About this series

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.


About this tutorial

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.


Prerequisites

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.

1 of 10 | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Open source, SOA and Web services
ArticleID=133576
TutorialTitle=Create a Web storefront using PHP, Derby and PayPal, Part 1: Pouring the foundation database
publish-date=11082005
author1-email=tyleranderson5@yahoo.com
author1-email-cc=troy@backstopmedia.com

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Special offers