Datasheet
9
Chapter 1 ✦ Why PHP and MySQL?
If you have no relational database experience or are coming from an environment such as
Microsoft Access, MySQL’s command line interface and lack of implicit structure may at first
seem a little daunting. Again, the word easy is relative. However, MySQL’s increasingly faithful
adherence to the ANSI SQL-92 standard and a comprehensive suite of external client pro-
grams, coupled with graphical administration tools such as PHPMyAdmin and the new
MySQL Control Center, will get even neophyte users up and running quickly compared to
other databases. None of these will substitute for learning a little theory and employing
good design practices, but that subject is for another chapter.
HTML-embeddedness
PHP is embedded within HTML. In other words, PHP pages are ordinary HTML pages that
escape into PHP mode only when necessary. Here is an example:
<HEAD>
<TITLE>Example.com greeting</TITLE>
</HEAD>
<BODY>
<P>Hello,
<?php
// We have now escaped into PHP mode.
// Instead of static variables, the next three lines
// could easily be database calls or even cookies;
// or they could have been passed from a form.
$firstname = ‘Joyce’;
$lastname = ‘Park’;
$title = ‘Ms.’;
echo “$title $lastname”;
// OK, we are going back to HTML now.
?>
. We know who you are! Your first name is <?php echo
$firstname; ?>.</P>
<P>You are visiting our site at <?php echo date(‘Y-m-d H:-- i:s’);
?></P>
<P>Here is a link to your account management page: <A
HREF=”http://www.example.com/accounts/<?php echo
“$firstname$lastname”; ?>/”><?php echo $firstname; ?>’s account
management page</A></P>
</BODY>
</HTML>
When a client requests this page, the Web server preprocesses it. This means it goes through
the page from top to bottom, looking for sections of PHP, which it will try to resolve. For one
thing, the parser will suck up all assigned variables (marked by dollar signs) and try to plug
them into later PHP commands (in this case, the
echo function). If everything goes smoothly,
the preprocessor will eventually return a normal HTML page to the client’s browser, as shown
in Figure 1-1.
03 557467 ch01.qxd 4/5/04 11:06 AM Page 9