Specifications

Using MySQL
P
ART II
228
Previously, in our work with PHP, we used a flat file to store and retrieve data. When we
looked at this in Chapter 2, Storing and Retrieving Data, we mentioned that relational data-
base systems make a lot of these storage and retrieval tasks easier, safer, and more efficient in a
Web application. Now, having worked with MySQL to create a database, we can begin con-
necting this database to a Web-based front end.
In this chapter, well explain how to access the Book-O-Rama database from the Web using
PHP. Youll learn how to read from and write to the database, and how to filter potentially trou-
blesome input data.
Overall, well look at
How Web database architectures work
The basic steps in querying a database from the Web
Setting up a connection
Getting information about available databases
Choosing a database to use
Querying the database
Retrieving the query results
Disconnecting from the database
Putting new information in the database
Making your database secure
Other useful PHPMySQL functions
Other PHP-database interfaces
How Web Database Architectures Work
In Chapter 7, Designing Your Web Database, we outlined how Web database architectures
work. Just to remind you, here are the steps again:
1. A users Web browser issues an HTTP request for a particular Web page. For example,
the user might have requested a search for all the books written by Michael Morgan at
Book-O-Rama, 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.
13 7842 CH10 3/6/01 3:36 PM Page 228