What Are Dynamic Web Sites?


Dynamic Web sites are flexible and potent creatures, more accurately described as applications than merely sites. Dynamic Web sites

  • Respond to different parameters (for example, the time of day or the version of the visitor's Web browser)

  • Have a "memory," allowing for user registration and login, e-commerce, and similar processes

  • Normally involve HTML forms, so that people can perform searches, provide feedback, and so forth

  • Often have interfaces where administrators can manage the site's content

  • Are easier to maintain, upgrade, and build upon

There are many technologies available for creating dynamic Web sites. The most common are ASP.NET (Active Server Pages, a Microsoft construct), JSP (Java Server Pages), ColdFusion, and PHP. Dynamic Web sites do not necessarily rely on a database, but more and more of them do, particularly as database applications like MySQL are available at little to no cost.

What's New in PHP 5

PHP 5, like PHP 4 before it, is a major new development of this popular programming language. The most critical changes in PHP 5from a developer's standpointinvolve object-oriented programming (OOP). PHP has supported objects for a long time, but now it does so in a way that's more in keeping with true OOP thinking.

Besides the OOP alterations, PHP 5 uses a new version of the Zend Engine (the driving force in PHP), resulting in better performance. PHP 5 also has extended capabilities, a smattering of new functions, and a different set of supported extensions out of the box.


What Is PHP?

PHP originally stood for "Personal Home Page" as it was created in 1994 by Rasmus Lerdorf to track the visitors to his online résumé. As its usefulness and capabilities grew (and as it started being used in more professional situations), it came to mean "PHP: Hypertext Preprocessor."

According to the official PHP Web site, found at www.php.net (Figure i.1), PHP is "an HTML embedded scripting language." It's a complex but descriptive definition, whose meaning I'll explain.

Figure i.1. The home page for PHP.


To say that PHP is HTML embedded means that PHP can be interspersed within HTML, which makes developing dynamic Web sites much easier. Also, PHP is a scripting language, as opposed to a programming language: PHP was to designed to write Web scripts, not stand-alone applications. The scripts run only after an event occursfor example, when a user submits a form or goes to a URL.

I should add to this definition by stating that PHP is a server-side, cross-platform technology, both descriptions being important. Server-side refers to the fact that everything PHP does occurs on the server (as opposed to on the client, which is the Web site viewer's computer). Its cross-platform nature means that PHP runs on most operating systems, including Windows, Unix (and its many variants), and Macintosh. More important, the PHP scripts written on one server will normally work on another with little or no modification.

At the time the book was written, PHP was at version 5 (5.0.4, technically), with version 4.3 still being maintained and commonly found on servers. This book will use PHP 5 specifically (see the sidebar), but you should not have problems if you are using a slightly older version. Obviously, it would be preferable to work on a server using the latest version of PHP, but since you cannot always control these things, this book promotes version-indifferent code as much as possible. In cases where recently added functions or variables are being used, notes are made indicating alternative solutions.

Why use PHP

Put simply, when it comes to developing dynamic Web sites, PHP is better, faster, and easier to learn than the alternatives. What you get with PHP is excellent performance, a tight integration with nearly every database available, stability, portability, and a nearly limitless feature set due to its extendibility. All of this comes at no cost (PHP is open source) and with a very manageable learning curve. PHP is one of the best marriages I've ever seen between the ease with which beginning programmers can begin using it and the ability for more advanced programmers to do everything they require.

Finally, the proof is in the pudding: PHP has seen an exponential growth in use since its inception (Figure i.2), overtaking ASP as the most popular scripting language being used today. It's the most requested module for Apache (the most-used Web server), and by the time this book hits the shelves, PHP will be on about 20 million domains.

Figure i.2. This chart from Netcraft (www.netcraft.com) shows PHP's phenomenal growth over the past few years.


How PHP works

As previously stated, PHP is a server-side language. This means that the code you write in PHP resides on a host computer called a server. The server sends Web pages to the requesting visitors (you, the client, with your Web browser).

When a visitor goes to a Web site written in PHP, the server reads the PHP code and then processes it according to its scripted directions. In the example shown in Figure i.3, the PHP code tells the server to send the appropriate dataHTML codeto the Web browser, which treats the received code as it would a standard HTML page.

Figure i.3. How PHP fits into the client/server model when a user requests a Web page.


This differs from a static HTML site where, when a request is made, the server merely sends the HTML data to the Web browser and there is no server-side interpretation occurring (Figure i.4). Hence, to the end user and the Web browser there is no perceptible difference between what home.html and home.php may look like, but how that page's content was created will be significantly different.

Figure i.4. The client/server process when a request for a static HTML page is made.


Pronunciation Guide

Trivial as it may be, I should clarify up front that MySQL is technically pronounced "My Ess Que Ell," just as SQL should be said "Ess Que Ell." This is a question many people have when first working with these technologies. While not a critical issue, it's always best to pronounce acronyms correctly.


What Is MySQL?

MySQL (www.mysql.com, Figure i.5) is the world's most popular, and some might argue best, open source database. In fact, particularly as versions 4 and 5 add new features, MySQL is a viable competitor to the pricey goliaths such as Oracle and Microsoft's SQL Server. Like PHP, MySQL offers excellent performance, portability, and reliability, with a moderate learning curve and little to no cost.

Figure i.5. The home page for the MySQL database application.


MySQL is a database management system (DBMS) for relational databases (therefore, MySQL is an RDBMS). A database, in the simplest terms, is a collection of interrelated data, be it text, numbers, or binary files, that are stored and kept organized by the DBMS.

There are many types of databases, from the simple flat-file to relational and object-oriented. A relational database uses multiple tables to store information in its most discernable parts. Prior to the early 1970s (when this concept was developed), databases looked more like spreadsheets with single, vast tables storing everything. While relational databases may involve more thought in the designing and programming stages, they offer an improvement to reliability and data integrity that more than makes up for the extra effort required. Further, relational databases are more searchable and allow for concurrent users.

By incorporating a database into a Web application, some of the data generated by PHP can be retrieved from MySQL (Figure i.6). This further moves the site's content from a static (hard-coded) basis to a flexible one, flexibility being the key to a dynamic Web site.

Figure i.6. How most of the dynamic Web applications in this book will work, using both PHP and MySQL.


MySQL is an open source application, like PHP, meaning that it is free to use or even modify (the source code itself is downloadable). There are occasions in which you should pay for a MySQL license, especially if you are making money from the sales or incorporation of the MySQL product. Check MySQL's licensing policy for more information on this.

The MySQL software consists of several pieces, including the MySQL server (mysqld, which runs and manages the databases), the MySQL client (mysql, which gives you an interface to the server), and numerous utilities for maintenance and other purposes. PHP has always had good support for MySQL, and that is even more true in the most recent versions of the language.

MySQL has been known to handle databases as large as 60,000 tables with more than five billion rows. MySQL can work with tables as large as eight million terabytes on some operating systems, generally a healthy 4 GB otherwise.

At the time of this writing, MySQL is on version 4.1.12, with version 5 in development. As the version of MySQL you have affects what features you can use (see the sidebar), it's important that you know what you're working with. For this book, MySQL 4.1 was used, and comments are included in the text where a feature is version-specific.



    PHP and MySQL for Dynamic Web Sites. Visual QuickPro Guide
    PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    ISBN: 0321336577
    EAN: 2147483647
    Year: 2005
    Pages: 166
    Authors: Larry Ullman

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net