13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

216 Chapter 8 Designing Your <strong>Web</strong> Database<br />

The first way means adding a Review column to the Books table.This way, there is a<br />

field for the Review to be added for each book. If many books are in the database, <strong>and</strong><br />

the reviewer doesn’t plan to review them all, many rows won’t have a value in this<br />

attribute.This is called having a null value.<br />

Having many null values in your database is a bad idea. It wastes storage space <strong>and</strong><br />

causes problems when working out totals <strong>and</strong> other functions on numerical columns.<br />

When a user sees a null in a table, he doesn’t know whether it’s because this attribute is<br />

irrelevant, whether the database contains a mistake, or whether the data just hasn’t been<br />

entered yet.<br />

You can generally avoid problems with many nulls by using an alternate design. In<br />

this case, you can use the second design proposed in Figure 8.7. Here, only books with a<br />

review are listed in the Book_Reviews table, along with their reviews.<br />

Note that this design is based on the idea of having a single in-house reviewer; that is,<br />

a one-to-one relationship exists between Books <strong>and</strong> Reviews. If you want to include<br />

many reviews of the same book, this would be a one-to-many relationship, <strong>and</strong> you<br />

would need to go with the second design option. Also, with one review per book, you<br />

can use the ISBN as the primary key in the Book_Reviews table. If you have multiple<br />

reviews per book, you should introduce a unique identifier for each.<br />

Summary of Table Types<br />

You will usually find that your database design ends up consisting of two kinds of tables:<br />

n Simple tables that describe a real-world object.They might also contain keys to<br />

other simple objects with which they have a one-to-one or one-to-many relationship.<br />

For example, one customer might have many orders, but an order is placed by<br />

a single customer.Thus, you put a reference to the customer in the order.<br />

n Linking tables that describe a many-to-many relationship between two real objects<br />

such as the relationship between Orders <strong>and</strong> Books.These tables are often associated<br />

with some kind of real-world transaction.<br />

<strong>Web</strong> Database Architecture<br />

Now that we’ve discussed the internal architecture of the database, we can look at the<br />

external architecture of a web database system <strong>and</strong> discuss the methodology for developing<br />

a web database system.<br />

The basic operation of a web server is shown in Figure 8.8.This system consists of<br />

two objects: a web browser <strong>and</strong> a web server. A communication link is required between<br />

them. A web browser makes a request of the server.The server sends back a response.<br />

This architecture suits a server delivering static pages well.The architecture that delivers<br />

a database-backed website, however, is somewhat more complex.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!