advertisement

Print
Are PHP and MySQL the Perfect Couple?

by W.J. Gilmore
06/16/2000

Related Articles

YourSQL Database Might Just Be MySQL

How PostgreSQL Rose to Fame

I'm not afraid to admit the fact that I am an 80s music fan. A freak. A fanatic. I'm also a programmer, so, as you may surmise, I spend a lot of time in front of my computer listening to, well, 80s music. Do you remember the song by Dire Straits titled "I Want My P-H-P"? Or how about Jimmy Buffett's "Cheeseburger in PHP Paradise"?

OK, maybe I've mixed up my love for music with my other true love, PHP. However, this crush isn't without merit; PHP is one of the sexiest technologies to hit the web, and the recent release of version 4.0 proves that it's getting better with age.

So let me introduce you to PHP, and elaborate upon one of its finest features, database support. Specifically, I will focus on how well it integrates with an open source favorite in the database world: MySQL.

MySQL and PHP have developed a special sort of relationship over the past few years, perhaps due in large part to the fact that they are both freely available for download. The increased popularity of this dynamic duo, coupled with boundless enthusiasm from core developers of both technologies, culminated in a "meeting of the minds" in Israel earlier this year. This resulted in the MySQL library being packaged with the PHP 4.0 distribution, in addition to an agreement to help each other improve the performance quality of product integration whenever the opportunity arises.

What is PHP?

PHP 4.0 is perhaps best defined as a server-side web scripting language. It can be integrated directly alongside other web-based languages, such as HTML and WML, enabling the programmer to introduce dynamic content directly to their web applications.

Let's consider a few different ways in which PHP can be displayed within a browser:

Example 1 PHP alone:

<? print "PHP is cool."; ?>

Example 2 PHP embedded in HTML code:

<? print "PHP is"; ?> cool.

Example 3 An even cooler example:

Today's date is: <? print (date ("M d, Y")); ?>

While the ability to easily embed dynamic code into your web application is cool, this is just the beginning of what PHP has to offer. The ability to make mathematical calculations, parse strings, manipulate databases, and do much more via the web browser is easy given the hundreds of predefined PHP functions. PHP 4.0 further expands upon this vast functionality, offering several new features which greatly increase the overall appeal of the language.

PHP 4.0 features

It is worth noting that the PHP 4.0 parsing engine is a complete rewrite of its predecessor. Although there are many features of the language worth noting, here are a few of my favorite "standouts" in the new version.

  • Script interpretation vs. compilation: The incredible popularity of PHP inspired many developers to create large, complex applications using the scripting language, something that was rather unexpected given its humble origins. (Read more about PHP's creator and its history at the Zend Hall of Fame.) Although these attempts were wildly successful, the PHP team knew they could do better.

    The main obstacle to overcome was the fact that previous PHP scripts were interpreted line-by-line upon each execution. While this worked just fine for relatively small scripts, it was not the best solution for large and complex scripts, particularly when loops or function calls were involved. As a result, scripts are now entirely compiled before they are executed, eliminating repetitive interpretation and ultimately resulting in substantially faster execution times.

  • Web server flexibility: PHP had been, quite logically, developed for use in conjunction with the popular Apache web server. However, as time progressed, several other web servers popped up that proved to be quite popular in their own right, such as the Netscape Enterprise server, the Microsoft IIs server, and Zeus. Have no fear, as PHP 4.0 is now compliant to all of these servers, and then some.

  • Session management: Version 4.0 provides a great new feature that frees the developer from having to create and maintain session IDs. Several protocols are available that eliminate sole reliance on cookies for maintaining session data. For example, if the user turns cookies off, session data can be passed via the URL. Furthermore, session data can be stored via a variety of media, including plaintext files or databases.

  • Database support: Although there were no huge steps forward in the already marvelous database support in the 4.0 release per se, the packaging of the MySQL Library greatly increased the value of the PHP distribution. Let's discuss the MySQL package in further detail, and highlight PHP/MySQL implementation with a few examples.

Pages: 1, 2, 3

Next Pagearrow