Index
    Preface
      What This Book Is About
      What You Need to Know
      How This Book Is Organized
      How to Use This Book
      Conventions Used in This Book
      Using Code Examples
      How to Contact Us
      Web Site and Code Examples
      Acknowledgments
      Chapter 1.  Database Applications and the Web
      Section 1.1.  The Web
      Section 1.2.  Three-Tier Architectures
      Chapter 2.  The PHP Scripting Language
      Section 2.1.  Introducing PHP
      Section 2.2.  Conditions and Branches
      Section 2.3.  Loops
      Section 2.4.  Functions
      Section 2.5.  Working with Types
      Section 2.6.  User-Defined Functions
      Section 2.7.  A Working Example
      Chapter 3.  Arrays, Strings, and Advanced Data Manipulation in PHP
      Section 3.1.  Arrays
      Section 3.2.  Strings
      Section 3.3.  Regular Expressions
      Section 3.4.  Dates and Times
      Section 3.5.  Integers and Floats
      Chapter 4.  Introduction to Object-Oriented Programming with PHP 5
      Section 4.1.  Classes and Objects
      Section 4.2.  Inheritance
      Section 4.3.  Throwing and Catching Exceptions
      Chapter 5.  SQL and MySQL
      Section 5.1.  Database Basics
      Section 5.2.  MySQL Command Interpreter
      Section 5.3.  Managing Databases and Tables
      Section 5.4.  Inserting, Updating, and Deleting Data
      Section 5.5.  Querying with SQL SELECT
      Section 5.6.  Join Queries
      Section 5.7.  Case Study: Adding a New Wine
      Chapter 6.  Querying Web Databases
      Section 6.1.  Querying a MySQL Database Using PHP
      Section 6.2.  Processing User Input
      Section 6.3.  MySQL Function Reference
      Chapter 7.  PEAR
      Section 7.1.  Overview
      Section 7.2.  Core Components
      Section 7.3.  Packages
      Chapter 8.  Writing to Web Databases
      Section 8.1.  Database Inserts, Updates, and Deletes
      Section 8.2.  Issues in Writing Data to Databases
      Chapter 9.  Validation with PHP and JavaScript
      Section 9.1.  Validation and Error Reporting Principles
      Section 9.2.  Server-Side Validation with PHP
      Section 9.3.  JavaScript and Client-Side Validation
      Chapter 10.  Sessions
      Section 10.1.  Introducing Session Management
      Section 10.2.  PHP Session Management
      Section 10.3.  Case Study: Using Sessions in Validation
      Section 10.4.  When to Use Sessions
      Section 10.5.  PHP Session API and Configuration
      Chapter 11.  Authentication and Security
      Section 11.1.  HTTP Authentication
      Section 11.2.  HTTP Authentication with PHP
      Section 11.3.  Form-Based Authentication
      Section 11.4.  Protecting Data on the Web
      Chapter 12.  Errors, Debugging, and Deployment
      Section 12.1.  Errors
      Section 12.2.  Common Programming Errors
      Section 12.3.  Custom Error Handlers
      Chapter 13.  Reporting
      Section 13.1.  Creating a Report
      Section 13.2.  Producing PDF
      Section 13.3.  PDF-PHP Reference
      Chapter 14.  Advanced Features of Object-Oriented Programming in PHP 5
      Section 14.1.  Working with Class Hierarchies
      Section 14.2.  Class Type Hints
      Section 14.3.  Abstract Classes and Interfaces
      Section 14.4.  Freight Calculator Example
      Chapter 15.  Advanced SQL
      Section 15.1.  Exploring with SHOW
      Section 15.2.  Advanced Querying
      Section 15.3.  Manipulating Data and Databases
      Section 15.4.  Functions
      Section 15.5.  Automating Querying
      Section 15.6.  Table Types
      Section 15.7.  Backup and Recovery
      Section 15.8.  Managing Users and Privileges
      Section 15.9.  Tuning MySQL
      Chapter 16.  Hugh and Dave's Online Wines:A Case Study
      Section 16.1.  Functional and System Requirements
      Section 16.2.  Application Overview
      Section 16.3.  Common Components
      Chapter 17.  Managing Customers
      Section 17.1.  Code Overview
      Section 17.2.  Customer Validation
      Section 17.3.  The Customer Form
      Chapter 18.  The Shopping Cart
      Section 18.1.  Code Overview
      Section 18.2.  The Winestore Home Page
      Section 18.3.  The Shopping Cart Implementation
      Chapter 19.  Ordering and Shipping at the Online Winestore
      Section 19.1.  Code Overview
      Section 19.2.  Credit Card and Shipping Instructions
      Section 19.3.  Finalizing Orders
      Section 19.4.  HTML and Email Receipts
      Chapter 20.  Searching and Authentication in the Online Winestore
      Section 20.1.  Code Overview
      Section 20.2.  Searching and Browsing
      Section 20.3.  Authentication
      Appendix A.  Linux Installation Guide
      Section A.1.  Finding Out What's Installed
      Section A.2.  Installation Overview
      Section A.3.  Installing MySQL
      Section A.4.  Installing Apache
      Section A.5.  Installing PHP
      Section A.6.  What's Needed for This Book
      Appendix B.  Microsoft Windows Installation Guide
      Section B.1.  Installation Overview
      Section B.2.  Installing with EasyPHP
      Section B.3.  What's Needed for This Book
      Appendix C.  Mac OS X Installation Guide
      Section C.1.  Getting Started
      Section C.2.  Installing MySQL
      Section C.3.  Setting Up Apache and PHP
      Section C.4.  What's Needed for This Book
      Appendix D.  Web Protocols
      Section D.1.  Network Basics
      Section D.2.  Hypertext Transfer Protocol
      Appendix E.  Modeling and Designing Relational Databases
      Section E.1.  The Relational Model
      Section E.2.  Entity-Relationship Modeling
      Appendix F.  Managing Sessions in theDatabase Tier
      Section F.1.  Using a Database to Keep State
      Section F.2.  PHP Session Management
      Section F.3.  MySQL Session Store
      Appendix G.  Resources
      Section G.1.  Client Tier Resources
      Section G.2.  Middle-Tier Resources
      Section G.3.  Database Tier Resources
      Section G.4.  Security and Cryptography Resources
      Appendix H.  The Improved MySQL Library
      Section H.1.  New Features
      Section H.2.  Getting Started
      Section H.3.  Using the New Features
    Colophon
    Copyright



 

Previous Section  < Day Day Up >  Next Section

A.6 What's Needed for This Book

This section shows you how to download and install our example database, all of the book code examples, the sample online winestore application, and the additional packages that are used throughout the book.

A.6.1 Installing PEAR Packages

The following optional PEAR package is required:


HTML_Template_IT

This is needed to work with Chapter 7 and all later chapters.

Detailed instructions to install optional packages can be found in Chapter 7. You'll also find a discussion there about how to find about, install, and upgrade packages.

In brief, to install and upgrade the packages you need for this book do the following:

  1. Log in as the root user.

  2. If you're not already, connect to the Internet.

  3. Type the following to install the optional package:

    % pear install HTML_Template_IT

  4. Type the following to check if upgrades of the core packages used in this book are available:

    % pear upgrade PEAR
    
    % pear upgrade Date
    
    % pear upgrade DB
    
    % pear upgrade Mail

A.6.2 Installing the Code Examples

The example PHP scripts in this book are available from our book's web site, http://www.webdatabasebook.com. In this section, we show you how to install them for use on your machine. The winestore application isn't installed in this section; see Section A.6.5 for instructions.

We assume you've already followed the instructions in this chapter to install MySQL, PHP, and Apache. We also assume you've installed these tools in the locations we recommend; if you haven't, replace the directory /usr/local/apache2/htdocs with your document root location during the following steps.

To install the example scripts, follow these steps:

  1. Using a browser, download the file http://www.webdatabasebook.com/examples.zip into the /tmp directory.

  2. To start, you need to configure your Apache web server so that it won't show users the content of the .inc include files if they're retrieved with a web browser. There are several ways to do this, but the simplest is to edit your httpd.conf configuration file. You'll find the file in /usr/local/apache2/conf/. To edit the file, you'll need to login as the root user.

    Now, open the httpd.conf file in an editor, and add this to the end of the file:

    <Files ~ "\.inc$">
    
        Order allow,deny
    
        Deny from all
    
        Satisfy All
    
    </Files>

    Save the file and exit the editor. You now need to restart your Apache server. You can do this by typing:

    % /usr/local/apache2/bin/apachectl restart

  3. Now, create a directory in your Apache document root to store the examples, and copy the downloaded file to that location:

    % mkdir /usr/local/apache2/htdocs/wda
    
    % cp /tmp/examples.zip /usr/local/apache2/htdocs/wda

  4. Unzip the wda.zip examples in their new directory by doing this:

    % cd /usr/local/apache2/htdocs/wda
    
    % unzip examples.zip

  5. Edit the file db.inc in the wda directory and modify the lines beginning with $username and $password so that fred and shhh are replaced with the username and password you chose for your user when installing MySQL:

    <?php
    
       $hostName = "127.0.0.1";
    
       $databaseName = "winestore";
    
       $username = "fred";
    
       $password = "shhh";

    Save the file and exit the editor.

  6. You may also need to set the file permissions so that examples are accessible through your web browser. To do this, use:

    % chmod a+rx /usr/local/apache/htdocs/wda
    
    % chmod a+r /usr/local/apache/htdocs/wda/*

  7. You should now be able to load the example list by requesting the following URL with a web browser running on the same machine as the web server: http://127.0.0.1/wda/. Test the examples from Chapter 2 through Chapter 4—they should work.

    You'll find that some of the examples from Chapter 6 onward run only if the winestore database has been loaded into the MySQL DBMS by following the instructions in the next section. In addition, most examples from Chapter 7 onward work only if you've installed the PEAR package HTML_Template_IT.

A.6.3 Installing the PDF PHP Library

To work with the PDF PHP library in Chapter 13, you need to download the class files. To do this, follow these steps:

  1. Visit the web site http://ros.co.nz/pdf/.

  2. From the Downloads section, choose the link to the Zip file that contains the class, sample, and the required font metric files. Save the file in /tmp.

  3. Change directory to the temporary directory and unzip the download file. into an install directory.

    If you're only planning to use the library with our examples, first install the code examples as described in the previous section, and then use:

    % unzip pdfClassesAndFonts_009e.zip -d /usr/local/apache2/htdocs/wda

    This installs the class files and fonts in the examples directory.

    An alternative approach is to install the files into a shared file location such as /usr/local/src/pdf-php. Then, edit your php.ini file and include the directory at the end of the include_path directive. This allows you to include the path in a PHP script using only the class name and without specifying the directory.

A.6.4 Loading the Winestore Database

A local copy of the winestore database is required to test the SQL examples in Chapter 5, to test some of the web database application examples in Chapter 6 through Chapter 13, and to use the sample winestore application described in Chapter 16 through Chapter 20. In addition, MySQL must be installed and configured before the winestore database can be loaded.

We assume you've installed MySQL in the location we recommend; if you haven't, replace the directory /usr/local/mysql with your MySQL installation directory in the following steps.

The steps to load the winestore database are as follows:

  1. Using a web browser, download the file http://www.webdatabasebook.com/database.zip into the /tmp directory.

  2. Uncompress the winestore database in any directory by typing the following in a shell window:

    % unzip database.zip

  3. Run the MySQL command-line interpreter using the root username and the password you set, and load the winestore database:

    % /usr/local/mysql/bin/mysql -uroot -p
    
    password
    
     < /tmp/winestore.data

    Be patient, this may take a while. Exit the command interpreter by typing quit.

  4. After the loading is complete (it may take a while) the database can be tested by running a query. To do this, use the username and password you created when installing and configuring MySQL:

    % /usr/local/mysql/bin/mysql -uusername -ppassword

    Now type:

    mysql> SELECT * FROM region;

    This should produce the following list of wine regions as output:

    +-----------+---------------------+
    
    | region_id | region_name         |
    
    +-----------+---------------------+
    
    |         1 | All                 |
    
    |         2 | Goulburn Valley     |
    
    |         3 | Rutherglen          |
    
    |         4 | Coonawarra          |
    
    |         5 | Upper Hunter Valley |
    
    |         6 | Lower Hunter Valley |
    
    |         7 | Barossa Valley      |
    
    |         8 | Riverland           |
    
    |         9 | Margaret River      |
    
    |        10 | Swan Valley         |
    
    +-----------+---------------------+

The winestore database has now been loaded and tested.

A.6.5 Installing the Winestore Application

The sample online winestore application is available from our book's web site, http://www.webdatabasebook.com. In this section, we show you how to install it on your machine.

We assume you've installed the winestore database by following the instructions in the previous section. We also assume you've already followed the instructions in this chapter to install MySQL, PHP, and Apache, and that you've installed these tools in the locations we recommend; if you haven't, replace the directory /usr/local/apache2/htdocs with your document root location in the following steps.

Follow these steps:

  1. Using a browser, download the file http://www.webdatabasebook.com/wda2-winestore.zip into the /tmp directory.

  2. If you haven't configured your Apache web server so that it won't show users the content of the .inc include files, follow Step 2 in Section A.6.2.

  3. Log in as the root user and move the application into your Apache document root:

    % cp /tmp/wda2-winestore.zip /usr/local/apache2/htdocs/

  4. Unzip the wda2-winestore.zip code in the document root directory. This will create the subdirectory wda2-winestore:

    % cd /usr/local/apache2/htdocs/
    
    % unzip wda2-winestore.zip

  5. Edit the file wda2-winestore/includes/db.inc and modify the lines beginning with $username and $password so that fred and shhh are replaced with the username and password you selected when configuring MySQL:

    <?php
    
       $hostname = "127.0.0.1";
    
       $databasename = "winestore";
    
       $username = "fred";
    
       $password = "shhh";

    Save the file and exit the editor.

  6. You may also need to set the file permissions so that examples are accessible through your web browser. To do this, use:

    % chmod a+rx /usr/local/apache2/htdocs/wda2-winestore
    
    % chmod a+r /usr/local/apache2/htdocs/wda2-winestore/*

  7. You should now be able to load the application index by requesting the following URL with a web browser running on the same machine as the web server: http://127.0.0.1/wda2-winestore/. Click on the Use the Application link and you should be able to use the application.

    Previous Section  < Day Day Up >  Next Section







    Copyright © 2010 | Domen maybe sale - bye this domen