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

B.3 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.

B.3.1 Installing PEAR Packages

The optional PEAR package HTML_Template_IT is required. It 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, after you've installed EasyPHP, carry out the following steps:

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

  2. Run a command window. Do this by selecting the Run option from the Start Menu and typing command and then pressing OK. A window will appear that shows a prompt.

  3. Into the command window, type:

    C:\> C:\progra~1\easyph~1\php\pear\pear.bat install HTML_Template_IT

    Press Enter. The package will download and install. If something goes wrong, check that you've completed Steps 18 to 24 in Section B.2.

  4. Now, check if upgrades of the core packages used in this book are available. Into the command window, type:

    C:\> C:\progra~1\easyph~1\php\pear\pear.bat upgrade PEAR

    Press Enter and the package will be downloaded if required.

  5. Repeat Step 4, but type:

    C:\> C:\progra~1\easyph~1\php\pear\pear.bat upgrade Date

  6. Repeat Step 4, but type:

    C:\> C:\progra~1\easyph~1\php\pear\pear.bat upgrade DB

  7. Repeat Step 4, but type:

    C:\> C:\progra~1\easyph~1\php\pear\pear.bat upgrade Mail

B.3.2 Installing the Code Examples

The example PHP scripts from 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 B.3.5 for instructions.

To install the example scripts, follow these steps:

  1. Using a browser, download the file http://www.webdatabasebook.com/examples.zip into a temporary directory such as C:\windows\temp.

  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 in C:\Program Files\EasyPHP1-7\apache\conf.

    Open the httpd.conf file in an editor such as Notepad or WordPad, 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 by double-clicking the E icon in the taskbar, pressing the Apache button, and selecting Restart from the drop-down list.

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

    To do this, use Windows Explorer to create a new folder below C:\Program Files\EasyPHP1-7\www with the name wda, and then copy and paste the file C:\windows\temp\wda.zip into that folder.

  4. Unzip the wda.zip examples in their new directory using your Zip program.

    You can do this with a double-click on the wda.zip icon and then using your Zip program to extract the files into C:\Program Files\EasyPHP1-7\www\wda.

  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 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/.

  7. Test the examples from Chapter 2 to Chapter 4, and they should work.

    You'll find that some of the examples from Chapter 6 onwards 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 onwards work only if you've installed the PEAR package HTML_Template_IT.

B.3.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 a temporary directory such as c:\windows\temp.

  3. Unzip the download file into an install directory using your Zip program. If you're only planning to use the library with this book, then a good location is C:\Program Files\EasyPHP1-7\www\wda. This is a directory that's used in the previous section for the code examples.

    An alternative approach is to install the files into a shared file location such as C:\Program Files\EasyPHP1-7\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.

B.3.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 to Chapter 13, and to use the sample winestore application described in Chapter 16 to Chapter 20. MySQL must be installed and configured before the winestore database can be loaded.

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 a temporary directory such as C:\windows\temp.

  2. Uncompress the winestore database in any directory. You can do this with your Zip utility and save the file in the C:\windows\temp directory.

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

    You do this by choosing the Run option in the Start menu and typing:

    "C:\Program Files\EasyPHP1-7\mysql\bin\mysql.exe" -uroot -ppassword

    Then, load the database using:

    mysql> source C:\windows\temp\winestore.data

    Be patient, this may take a while.

  4. After the loading is complete (it may take a while) the database can be tested by running a query. To do this, 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.

B.3.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 EasyPHP.

Follow these steps:

  1. Using a browser, download the file http://www.webdatabasebook.com/wda2-winestore.zip into the directory C:\Program Files\EasyPHP1-7\www.

  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 B.3.2.

  3. Unzip the wda2-winestore.zip code in the document root directory using your Zip program. This will create the subdirectory wda2-winestore. You can usually do this by double-clicking on the wda2-winestore.zip icon and using your Zip program to extract the files into c:\Program Files\EasyPHP1-7\www\.

  4. 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.

  5. Edit the file wda2-winestore/includes/winestore.inc and locate the following three lines:

    // define("D_INSTALL_PATH", "c:/progra~1/easyph~1/www");
    
    // define("D_INSTALL_PATH", "/Library/WebServer/Documents");
    
    define("D_INSTALL_PATH", "/usr/local/apache2/htdocs");

    Uncomment the first line and comment-out the third so that you have the following:

    define("D_INSTALL_PATH", "c:/progra~1/easyph~1/www");
    
    // define("D_INSTALL_PATH", "/Library/WebServer/Documents");
    
    // define("D_INSTALL_PATH", "/usr/local/apache2/htdocs");

    Save the file and quit the editor.

    Note that forward slashes are used in the Microsoft Windows path.

  6. 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