From the Back Cover
The programmer's Guide to building robust web applications with PHP and MySQL
This is a comprehensive, practical guide for programmers who want to develop production-quality, database-enabled web applications with PHP and MySQL. Long-time developer Marc Wandschneider systematically addresses the entire process: not only coding, but also upfront application, user interface and database design, PLUS security, testing, and more.
You'll walk through building three applications from start to finish: a calendaring system, a weblog engine, and an e-commerce store. Along the way, you'll master essential strategies for creating robust web database applications and learn how to avoid the common pitfalls that trip up many developers moving to PHP and MySQL.
- Starts with a complete primer on PHP for developers including coverage of code organization, reuse, and object-oriented PHP
- Contains detailed treatments of data access, including transactions, foreign keys, and indexes
- Presents powerful data validation techniques utilizing PHP regular expressions
- Walks through planning web applications, including user interfaces and user management
- Offers systematic guidance on securing web applications from end to end
- Covers a wide range of implementation issues including internationalization, error handling, data validation, debugging, session management, and deployment
- Includes detailed chapters on XML, XML-based web services, and the PEAR framework for reusable PHP components
- Shows how to work with the Oracle and PostgreSQL databases
About the Author
Marc Wandschneider has worked extensively with open source platforms, and has written an Outlook Express-style email client for Linux using Qt. He travels the globe, consulting as a lead manager for software projects and teams. A graduate of the McGill University School of Computer Science, he spent five years working for Microsoft, where he developed and managed developers on the Visual Basic, Visual J++, and .NET Windows Forms teams.
© Copyright Pearson Education. All rights reserved.
Excerpt. © Reprinted by permission. All rights reserved.
This is the book I wish I had a couple years ago when I sat down and decided to learn something about web applications. The transition from programming standard window-system GUI applications to writing dynamic web applications was surprisingly complicated. Extremely productive languages such as PHP make the transition easier, but the learning curve remains steep.
With that in mind, I sat down to write this book and explain how to use the various technologies that go into writing web applications. I have made every mistake possible while learning about PHP and databases, and have therefore tried to incorporate as much of what I learned into this book. Far too many books published these days are merely a reprint of existing documentation or UNIX man pages, and I truly wanted to see something different in print.
The technologies, however, are only half the battle. Without strategies or systematic approaches to design and implementation, applications are doomed to an expensive and messy existence at best—or failure at worst. Therefore, this book focuses on a lot of things you might not see covered to the same extent in other books—design, testing, and security.
This book is targeted at people who need or want to write a web application. You might be a corporate developer looking to build an intranet application for your company or an Internet web application for customers. You might be a consultant helping a small business develop a web store, or just a hobbyist looking to learn more about web applications and write one of your own.
The assumption is that you have at least a passing familiarity with programming, although this book by no means expects you to be an expert. An understanding of basic programming constructs, such as variables and functions, and a basic understanding of HTML should be more than sufficient.
Because I knew next to nothing about databases when I started learning about web application programming, I likewise expect no more of the reader. This book covers databases from basic terminology and design to basic and advanced queries, with an appropriate balance between clear-and-simple instruction and interesting examples to help you in your development.
PHP began in 1994 as a series of scripts called PHP/FI (Personal Home Page/Forms Interpreter), and it was written by a fellow named Rasmus Lerdorf to help him manage documents on his web site. Over the years, PHP grew into something more serious. In 1997, a second version of the system came out with additional functionality.
In late 1998, PHP 3.0 was released, leading to a major rewrite of the code and the involvement of two new developers—Zeev Suraski and Andi Gutmans. The goal was to support progressively broader and more complex applications on the web. In early 2000, version 4.0 was released. Based on a new language engine called the Zend Engine, this version had much better performance and increased code modularity. By late 2004, the much-evolved version 5.0 was released. It included many new features, such as new language constructs, broader web server support, sessions, and additional third-party extensions. Among the new language features was a significantly improved and expanded object-oriented programming model, which this book uses extensively. Somewhere along the way, PHP ceased to refer to "Personal Home Page" and came to mean "PHP Hypertext Preprocessor," a so-called recursive acronym. (The acronym actually forms part of the term it defines!)
PHP is a remarkably productive language—you can sit down and crank out (yes, that's the technical term) large amounts of code in a short period of time, and this productivity is what drew me to it some years back. With PHP, I was able to put together surprisingly robust and dynamic travelogues of my journeys to various countries with relatively little code.
The one possible "fly in the ointment" is that the language can be quirky compared to other programming languages—especially if you, like me, come from a background of languages more similar to C/C++, Java, or Visual BASIC. In fact, many of the things covered in this book are the result of my sitting around and scratching my head for a couple of hours. However, after you become comfortable with it, the language proves fun to write and is surprisingly powerful.
This book is divided into six parts, which represents the logical progression of writing web applications.
Part I, "The Basics of PHP," covers the PHP language itself, starting with descriptions and discussions of the most basic types of language. Part I then moves on to functions, code structure, and object-oriented programming—before finishing off with a discussion of arrays and strings.
Part II, "Database Basics," covers databases, starting with terminology and progressing through design and data definition. Part II finishes by describing the use of databases and tables, ranging from the most basic queries to transactions and functions.
Part III, "Planning Web Applications," takes a step back from coding to discuss the design of your web applications. Many people get so involved in writing their code that they forget to sit down and actually think about it in advance. These chapters (hopefully) give you something to think about as you begin. This part also focuses heavily on securing your applications, as it is not something to be taken lightly.
Part IV, "Implementing Your Web Application," discusses the more advanced language features and concepts required to move beyond simple PHP and databases into writing web applications, covering topics such as errors, sessions, and XML—including plenty of sample code.
Part V, "Sample Projects and Further Ideas," presents three full web application samples that start with a simple appointment management system, progress through a web log system, and finish with an ecommerce store. These samples incorporate much of what the book has covered and are designed to be robust. Instead of killing large numbers of trees and listing all the code for the samples, you can download and run them. The book shows you only the most salient sections of the code and leaves you to download and run them in completion.
Part VI, "Appendixes," discusses the installation of the necessary software to run your web applications and how to perform various database actions on different database engines, and suggests some additional reading material.
Before You Begin
Before you begin reading the meat of this book, please take a moment to open the CD that accompanies this book and copy the source code to your computer. The phpwasrc/ directory contains the initial files you need.
In addition to the full source code (and installation instructions) for the three large samples from Part V of the book, there are also small snippets of code to accompany many of the chapters in the book. You can run these, debug them, or change and play with them to further help you learn how the language works.
Beyond the sample sources, the CD contains versions of PHP, the Apache HTTP Server, and MySQL that you can use to install the software on your local machine. Instructions are included on the CD.