Specifications

FIGURE 7.8
The client/server relationship between a Web browser and Web server requires communication.
The Web database applications we will build in this book follow a general Web database struc-
ture that is shown in Figure 7.9. Most of this structure should already be familiar to you.
Designing Your Web Database
C
HAPTER 7
7
DESIGNING YOUR
WEB DATABASE
181
Browser
Response
Request
Web Server
Browser
6
1
Web Server
5
2
PHP Engine
4
3
MySQL Server
FIGURE 7.9
The basic Web database architecture consists of the Web browser, Web server, scripting engine, and database server.
A typical Web database transaction consists of the following stages, which are numbered in
Figure 7.9. We will examine the stages in the context of the Book-O-Rama example.
1. A users Web browser issues an HTTP request for a particular Web page. For example,
she might have requested a search for all the books at Book-O-Rama written by Laura
Thomson, using an HTML form. The search results page is called results.php.
2. The Web server receives the request for results.php, retrieves the file, and passes it to the
PHP engine for processing.
3. The PHP engine begins parsing the script. Inside the script is a command to connect to
the database and execute a query (perform the search for books). PHP opens a connec-
tion to the MySQL server and sends on the appropriate query.
4. The MySQL server receives the database query and processes it, and sends the results
a list of booksback to the PHP engine.
5. The PHP engine finishes running the script, which will usually involve formatting the
query results nicely in HTML. It then returns the resulting HTML to the Web server.
6. The Web server passes the HTML back to the browser, where the user can see the list of
books she requested.
The process is basically the same regardless of which scripting engine or database server you
use. Often the Web server software, the PHP engine, and the database server all run on the
same machine. However, it is also quite common for the database server to run on a different
machine. You might do this for reasons of security, increased capacity, or load spreading. From
a development perspective, this will be much the same to work with, but it might offer some
significant advantages in performance.
10 7842 CH07 3/6/01 3:34 PM Page 181