Setting Up The Database
To keep this example simple on screen, the address book contains only the person's first name, last name, and e-mail address. If you download the sample code (see Resources), though, you'll find additional fields that make the application more useful.
This example uses MySQL, but you could use any database that PHP supports. If you use another database (such as Oracle or ODBC), you will need to adapt the listing because PHP's API is slightly different for each database. For example, for ODBC connections you would use odbc_pconnect instead of connecting with the mysql_pconnect function.
Note that I've used MySQL's auto-increment feature in these examples. It's a handy way to generate unique integer keys for a table column. You can do the same thing with other databases by using stored procedures and triggers.
First, you must set up a valid MySQL login and password to use PHP. See the MySQL documentation for details (see Resources).
Then use the SQL commands in Listing 3 to set up the PERSON table within a database called ADDRESS_BOOK and add a single entry into the database. Enter the text using the mysql command-line program that is part of the MySQL distribution.
Listing 3. The commands for setting up the MySQL database and for entering the first contact
|
View Script Web databases quickly with PHP Discussion
Page: 1 2 3 4 5 6 7 8 Next Page: Retrieving Data