Preface There are lots of PHP and MySQL resources. So why did we decide to add this book to the market? We made the decision after we started teaching graduate students how to program with PHP in 1999. We found that the PHP and MySQL manuals, as well as most books, train people to use particular tools. But almost no resources explained the principles of programming for the Web. We realized that Web administrators and programmers needed to know more than what PHP functions to use and how to write SQL queries. That’s where this book comes in: it’ll help you learn about web database development, as well as understand the principles. This book explains what to do and why, along with how it’s done in PHP and MySQL. You’ll find information here that you won’t find elsewhere. Hopefully, you’ll use this knowledge with whatever web tools you choose in the future. But you’ll also learn about the breadth and depth of PHP and MySQL. When you finish this book, you’ll be able to build an online store, a portal, or a content management system. What This Book Is About This book is for developers who want to build database applications that are integrated with the Web. We show you the principles and techniques for developing small- to medium-scale web database applications that store, manage, and retrieve data. The architecture we describe is a successful framework for applications that can run on modest hardware and process more than a million hits per day. We show you all of the critical tasks you need to know to build successful web software. We cover programming fundamentals for the Web. We show you the principles and practice of working with databases using the SQL query language. We teach you about tracking users with sessions, securing an application, separating presentation from code, writing database-independent code, writing reports, adding error handling, and advanced object-oriented and database topics. An important feature of this book is our case study, Hugh and Dave’s Online Wines. It’s a complete but fictional online retail store that illustrates how most of the techniques described in the book can be put together to build a real application. The winestore application allows users to browse and search a database of wines, add items to a shopping cart, manage their membership, and purchase wines. It has all the basic security, user-tracking, and error-handling features of a real-world application. It features a medium-size database that we use in querying examples throughout the book. We use Open Source software, and we show you how to use it on Unix-based platforms such as Linux and Mac OS X, and under Microsoft Windows 2000, 2003, and XP. Our database server is MySQL, a system known for its suitability to applications that require speed but low resource overheads. Our scripting language is PHP, which is best known for its function libraries that interact with more than 15 relational database systems, the web environment, and many other services. Apache is our web server of choice, but most other web servers can be used successfully with MySQL, PHP, and this book.