Introducing PHP and MySQL
Introducing PHP and MySQLI'll be introducing you two the popular PHP language and MySQL database, two open source technologies which have played a major role in the evolution of the World Wide Web.
Although by now the Web has become a crucial part of your daily life, I'd venture there are a few in the audience whose understanding of how the Web works is akin to the typical person's understanding of how an automobile works. That is to say, you understand there's some sort of engine which makes everything happen, but haven't actually taken the time to look under the hood. So I thought I'd kick things off by quickly explaining what happens when a user access a web site. It's important to understand the sequence of events because it will help you understand how PHP fits into the picture later in this presentation.
Suppose you attempt to access the URL www.example.com/videos/sample.html. Using a routing approach known as DNS, this request eventually winds its way through the network to the web server where the website resides. The web server will then examine the URL to determine which resource is desired, in this case the sample.html file found in the videos directory, returning sample.html, and any other files referenced within sample.html, including things like JavaScript files and images. These files arrive at the user's computer, at which point it's the browser's job to parse the HTML, execute any JavaScript, and ultimately render the web page.
This is of course one of the most simple scenarios, a scenario in which the server plays a very small part. In fact, if this was all the Web could do, it would be a pretty boring place.
What about Dynamic Data?
What makes the web such an exciting place is the fact we can serve up dynamic data, such as weather forecasts based on a provided zip code or the latest news about your favorite sports team. Often underlying this content are features such as user registration and login, shopping carts, and integration with other technologies such RSS and the Facebook Platform. For this to be possible, there must be a brain of sorts residing behind the web site, and for millions of web sites around the world that brain is PHP.
[transition: PPT - Introducing PHP ] PHP is a programming language which executes on the web server, giving it an enormous power in
terms of being able to use the server's operating system, resources, and other installed applications to perform tasks such as database interaction, PDF generation, string manipulation, and much more.
You might be surprised to know PHP has been around for almost 15 years, with the first version having been released by its creator Rasmus Lerdorf back in 1995. Since then, PHP has climbed to be one of the most popular programming languages in the world, determined by some to be second only to Java, C, and C++ in terms of the number of active developers.
I'd say PHP's success is due to four factors. First, as you'll soon learn it's a pretty easy language to use, capable of doing something useful with as little as one line of code.
Second, it's open source, meaning you can install, use, and even modify it for free provided you do so in accordance with its liberal licensing terms.
Third, the tremendously active user community offers considerable support in the form of forums, online tutorials, blogs, and chat rooms. You'll also find commercial support in the form of books such as "Easy PHP Websites with the Zend Framework", and formal support packages such as those offered by Zend Technologies, a prominent PHP products and services company.
Finally, you'll find hundreds of high-quality PHP-driven applications, many of which are available for free. These applications can often be installed in just minutes, and are capable of doing everything from managing an online product catalog to powering a blog.
Who is Using PHP?
Like many open source technologies, PHP's impact is often understated as compared to commercial products whose marketing teams can have an undue influence on perception. As I'd mentioned earlier, PHP is installed on almost 21 million domains worldwide, however it's sphere of influence really shows when referring to specific well-known users. As you can see from this star-studded list, PHP not only runs some of the most popular websites on the planet, but can also be applied to a wide variety of purposes, whether it's a media-intensive website such as TWIT.tv, sites involving cutting-edge technology such as Adobe Systems' Flex.org, or massive social networking websites such as Facebook and Digg.
With this general introduction complete, let's talk a bit about how PHP fits works with the web server to produce dynamic web pages.
How the Web Works with PHP
Just as JavaScript is a programming language embedded into web pages and executes within the user's web browser, PHP is a programming language which is embedded into web pages but executes on the server. This diagram shows you what string of events occur which cause PHP code to execute.
Example file name: sample.php. Note how the file is named with a .php extension rather than .html as was the case in the previous example. Without getting into too much detail, this is the file extension the web server has been told will be used when PHP code is found within the file. The server receives this request, recognizes the .php extension, and passes the file to the PHP engine for processing.
The PHP engine will in turn examine this file, looking for PHP code to execute. As you'll learn later in this presentation, the file may consist solely of PHP code, or the PHP code may be intertwined with HTML. The PHP engine will execute any PHP code, rendering any data into the page as determined by the code, and return the page to the server.
Finally, the server will send this page and other related contents to the requesting browser, which will in turn render it in the same fashion as described in the first example. So in summary, PHP is just another tool which works in conjunction with languages such as HTML, CSS, and JavaScript to produce a web page.
So, I've explained in general terms how PHP integrates with the general flow of page requests and responses, however I'd imagine the language itself is still somewhat of a mystery to you. That said, I thought at least a brief intro to PHP syntax would be beneficial.
[transition: PPT - What Does PHP Code Look Like?] PHP code is most often used to supplement otherwise static content. For instance, this first example will use PHP's date function to output the current date, which today happens to be March 30, 2009. Remember when I mentioned earlier that the web server would pass PHP-enabled pages to the PHP engine so the engine could execute the PHP code? The PHP engine knows which parts of the pages are PHP thanks to the <?php and ?> delimiters. Anything found in between these delimiters will be treated as PHP code. Anything outside will be ignored by the PHP engine and returned to the web server along with anything output by the PHP engine.
If you've experience working with languages such as Java or C#, it's important to understand that PHP differs from them in that it's an interpreted language. There is no intermediary step of manually compiling the code before it's executed. This makes the development process rather fluid, allowing the developer to write and execute code in a fairly streamlined fashion.
On the matter of IDEs, you'll find solutions specifically created for PHP such as PHP Developer Tools and Zend Studio, as well as multi-purpose solutions which happen to offer PHP extensions such as Textmate which is popular in the OS X community, Vim, and Emacs. While I've used almost all of these, I'm particularly partial to PHP Developer Tools, which is built atop the Eclipse platform.
For documentation look no further than phpDocumentor, a fantastic solution used to create documentation from your code coments.
For testing the PHPUnit and SimpleTest frameworks have proven quite popular.
As far as frameworks go, the PHP community has built more solutions than there are stars in the sky, however three seem to have taken the lead in terms of popularity. These are CakePHP, Symfony, and Zend Framework. While the Zend Framework remains my favorite, I've used all three and find them to be fantastic solutions.
Finally, if you're looking for accelerators specific to optimizing the PHP code itself, check out eAccelerators, APC, and the Zend Platform. Of course, many general purpose caching solutions also exist, such as memcache.
[transition: PPT - Enterprise Integration] On the matter of enterprise integration, PHP is capable of connecting to essentially every mainstream database, in addition to several I've to this day never actually encountered. At any rate, support has long been available for the most popular, among them MySQL, PostgreSQL, SQLite, Oracle, and MS SQL Server.
Likewise, PHP is available for all mainstream operating systems, among them Linux, Mac OS X, and Windows. For the most part the cross-platform language capabilities are equivalent, making it easy to develop your website on for instance Windows or Mac OS X and then migrate it to a Linux-powered web server. It is worth noting Microsoft has taken a significant interest in PHP in recent years, collaborating with the PHP products and services company Zend Technologies to drastically improve PHP performance on the Microsoft IIS Web Server.
If your website needs to integrate with Java, several open source and commercial solutions are available, among them Quercus, IBM's Project Zero, and the Zend Platform.
Finally, in today's complex Web environment, chances are slim your website is going to remain on an island. Instead you'll likely want to integrate with a variety of third-party services which rely on protocols such as IMAP, LDAP, and OpenID. Solutions are also available for integrating with Twitter, Facebook, and Amazon Web Services. If you've purchased "Easy PHP Websites with the Zend Framework", be sure to check out the chapters and videos devoted to building Facebook and Amazon Web Services-driven applications.
PHP-Powered Applications
I think what's really interesting about the PHP language is that you can begin using it without ever having to write a line of code. On Sourceforge, you'll find almost 30,000 downloadable applications which use PHP as the development language. Furthermore, there are quite a few very well known PHP applications which have practically become household names for both online hobbyists and Fortune 500 companies alike. These projects include MediaWiki, the open source Wiki software which also happens to run the Wikipedia family of websites, SugarCRM, a fast-growing customer management solution used by thousands of organizations around the globe, and Drupal, the content management solution used to power popular websites such as The Onion.
Incidentally, if you want to learn more about e-commerce fundamentals and have purchased the Easy PHP Websites with the Zend Framework book package, I suggest checking out the video "An Introduction to E-Commerce", available at EasyPHPWebsites.com.
Thus concludes the introduction to PHP. Next let's move on to introduce a technology which is to PHP like Robin is to batman, like butter is to a toasted bagel, like ice cubes to a glass of iced tea… the MySQL database.
Introducing MySQL
Whether you wind up building custom web sites or using any of the aforementioned applications, you're almost certainly going to require the use of a database. Even if you're a newcomer to Web development you've probably heard of servers such as Oracle or Microsoft's SQL Server. Just as we've seen the rise of open source languages such as PHP over the past 2 decades, so have we seen the proliferation of open source databases, the most popular of which is MySQL.
MySQL is a popular relational database used primarily to store and manage data published through websites, although you'll also find it powering massive retail data warehouses and even within mammoth organizations such as the U.S. Census Bureau. Interestingly, it's also used within embedded applications such as kiosks and mobile devices.
MySQL is relevant to this presentation because of the long and storied history it has had with PHP, a history in fact dating back almost to the inception of MySQL itself. Very early on in MySQL's lifetime, a PHP extension capable of interacting with MySQL was made available, and its popularity spread like wildfire.
Interesting, MySQL originally started as a side project for a group of Swedish developers, with the first release being made public in 1996. This also happened to be a time when interest in web development was really starting to skyrocket, with thousands of developers looking for a cost-effective database capable of at least performing rudimentary data management tasks. As such, MySQL seemingly became an overnight hit, with the developers soon thereafter making the project a full-time endeavor. Regarding MySQL's popularity, more than 50,000 copies of the database are downloaded daily, an astounding number by any measure. Sun Microsystem's CEO Jonathan Schwartz mentioned in a 2008 interview that there are 11 million installations worldwide, making MySQL one of the most popular database solutions on the planet. Interestingly, MySQL's popularity has historically come at the expense of far more capable database solutions such as Oracle. I think the reason for MySQL's rapid ascension is logical; many developers were more than willing to tradeoff the often unused features of more powerful, not to mention expensive, database solutions for the speed and simplicity of MySQL. Over the years, the MySQL developers have expanded the database's capabilities to include features such as transactions, triggers, and stored procedures, in the process giving even more database developers reason to consider switching.
The January, 2008 sale of MySQL, Inc. to Sun Microsystems will no doubt ultimately serve to further solidify MySQL as a major player in the database field.
Who is Using MySQL?
Unlike PHP, MySQL has been backed by a corporate entity since its inception, meaning the project has had the luxury of a formalized marketing effort. However since MySQL is primarily identified as an open source project, you'll occasionally encounter misinformed individuals who have the impression it's not suitable for enterprise use. In reality, MySQL powers some of the largest websites on earth, including the list of behemoths you see here.





