This section shows you how to connect to and query the MySQL DBMS using PHP. The examples are illustrated with the first of three scripts from a simple but useful PHP application: a wedding gift registry that allows guests to log in, view a list of gifts wanted by the bride and groom, and reserve gifts that they plan to purchase by putting them on a shopping list. The complete application—including the database, scripts, and instructions on how to install it on your web site—is available at http://www.webdatabasebook.com/wedding/.
The gift registry application illustrates the basics of interacting with MySQL using PHP. It shows how to:
Call PHP library functions to connect to the MySQL DBMS, execute queries through the DBMS connection, and retrieve query result sets
Present query results using HTML
Interact with the user, and preprocess user data to minimize security risks
Add session support to an application so that a user can log in and out
Pass data between scripts by creating embedded hypertext links in
HTML, develop HTML
<form> environments, and
use HTTP headers
Handle MySQL errors with PHP
Manage DBMS credentials with include files
This section introduces the basics of interacting with MySQL using PHP. The script described here displays the gifts that are unreserved and the gifts that have been reserved by the current user. The output of the script rendered by a Netscape browser is shown in Figure 11-1. The script assumes the guest has already ...