Build Your Own Database Driven Website Using PHP & MySQL: Pt. 4
January 24, 2002
This is it -- the stuff you signed up for! In this chapter, you'll learn how to take information stored in a database and display it on a Web page for all to see. So far you have installed and learned the basics of MySQL, a relational database engine, and PHP, a server-side scripting language. Now you'll see how to use these two new tools together to create a true database-driven Web site!
A Look Back at First Principles
Before we leap forward, it's worth a brief look back to remind ourselves of the goal we're working toward. We have two powerful, new tools at our disposal: the PHP scripting language, and the MySQL database engine. It's important to understand how these two will fit together.
The whole idea of a database-driven Web site is to allow the
content of the site to reside in a database, and for that content
to be dynamically pulled from the database to create Web pages
for people to view with a regular Web browser. So on one end of
the system you have a visitor to your site who uses a Web browser
As shown in the diagram above, the PHP scripting language is the go-between that speaks both languages. It processes the page request and fetches the data from the MySQL database, then spits it out dynamically as the nicely-formatted HTML page that the browser expects. With PHP, you can write the presentation aspects of your site (the fancy graphics and page layouts) as "templates" in regular HTML. Where the content belongs in those templates, you use some PHP code to connect to the MySQL database and -- using SQL queries just like those you used to create a table of jokes in Chapter 2 -- retrieve and display some content in its place.
Just so it's clear and fresh in your mind, this is what will happen when someone visits a page on our database-driven Web site: