MySQL is a database. It stores your information, your users’ information, and anything else you want to stuff into it. But, beyond its ability to store information, MySQL is popular. In fact, it’s the most popular open-source database system in the world. It has literally millions of users working with it, finding and reporting problems, and testing its limits. And, it has thousands of developers that at some point have helped improved its code base
MySQL is essentially a warehouse in which you can store things to be looked up later. Not only that, MySQL provides you with a really fast mechanism to find all that stuff you stuck in the warehouse whenever it’s needed. By the time you’re through this book, you’ll love MySQL. It will do work that you could never do on your own, and it will do that work tirelessly and quickly.
It’s also the perfect companion to PHP. It’s easy to install on any system; it doesn’t take up huge resources like larger commercial offerings such as Oracle’s or IBM’s products; and its easy to connect to. In fact, you’ll find that PHP and MySQL are perfectly matched, with a ton of easy-to-use functions that let PHP scripts to do just about anything you can imagine with a MySQL database.
About This Book
PHP is a web-based language not a program that comes in a box. Tens of thousands (maybe even hundreds of thousands) of websites have bits of PHP tutorial or instruction on them. That’s great, right? Well, not so much. Those websites aren’t all current. Some are full of bugs. Some have more information in the comment trails-scattered amongst gripes, complaints, and lambasting from other programmers-as they do in the main page. It’s no easy matter to find what you’re looking for.
The purpose of this book therefore, is to serve as the manual that should have been included when you download PHP. It’s the missing PDF, if you will maybe the missing eBook, if you’re a Kindle or Nook or iPad person). In this book’s pages, you’ll find step-by-step instructions for getting PHP running, writing your first program and your second program …and eventually building a web application from scratch.
In addition, you’ll find clear evaluations of the absolutely critical parts of PHP that you’ll use every day, whether you’re building a personal blog or a corporate intranet.
Macintosh and Windows
PHP and MySQL work almost precisely the same in their Macintosh and Windows versions. Even more important, you’ll do most of your work by uploading your scripts and running your database code against a web server. That means that your hosting provider has to deal with operating system issues; you get to focus on your code and information.
In the first few chapters you get your system set up to write code and deal with PHP scripts. Thereafter you will soon forget about whether you’re on a Macintosh or using a Windows-based computer. You’ll just be writing code the same way you write HTML and CSS. And remember you’ll soon be uploading your scripts to remote web servers so your own computer is only part of the solution
FTP: It’s Critical
One piece of software that’s absolutely critical is a good FTP client. No matter how awesome your scripting skills become-and they’re gonna be formidable!-you have to actually get your scripts to your web hosting server. That’s where FTP comes in: it’s the means by which a file on your computer gets placed in just the right location on a remote server.
points you to several great editors, and the fancier ones will have FTP built right in. If you don’t opt for an integrated solution, a dedicated FTP program is great, too. You can write a script throw it online and test it all with a few mouse clicks. 50 go ahead and get that FTP program downloaded, configured for your web hosting service (which might also be called your ISP)and fired up. You’re gonna need it.
About the Outline
is divided into five parts each containing several chapters:
• Part 1: PHP and MySQL Basics
In the first four chapters, you install PHP, get it running on your computer, write your first few PHP programs, and learn to do a few basic things like collect user information via a web form and work with text. You also install MySQL and become thoroughly acquainted with the structure of a database.
• Part 2: Dynamic Web Pages
These are the chapters in which you start to build the basics of a solid web application. You add a table in which you can store users and their information, and get a grasp of how easily you can manipulate text. From URLs and emails to Twitter handles you use regular expressions and string handling to bend letters numbers and slashes to your will.
• Part 3: From Web Pages to Web Applications
With a solid foundation, you’re ready to connect your web pages into a more cohesive unit. You add custom error handling so that your users won’t become confused when things go wrong. You also add your own debugging to help you find problems. You also learn how to store references to users’ images of themselves store the images themselves in a database and learn which approach is best in which situations
• part 4: Security and the Real World
In even the simplest of applications, logging in and logging out is critical. In this section, you build an authentication system and then deal with passwords (which are important, but a bit of a pain). You then work with cookies and sessions, and use both to create a group-based authorization system for your web application.
• Part 5: Appendixes.
Although the first several chapters show you how to get PHP and MySQL onto your own Macintosh or Windows-based computer the easy way using the WampServer software package or the Mac’s built-in installation the two appendixes in this section show you how to install the software manually for full control of all the details.
At the Missing Manual website you can find every single code example, from every chapter in the state it is shown for that chapter
About the Online Resources
As the owner of a Missing Manual you’ve got more than just a book to sead Online you can find example files so that you can get some hands-on experience as well as tips articles and maybe even a video or two. You can also communicate with the Missing Manual team and tell us what you love (or hate) about the book. Head over to go directly to one of the following sections.
This book doesn’t have a CD pasted inside the back cover but you’re not missing out on anything. Go to to download code samples code samples and also some code samples. Yup, there are a lot of them. Every chapter has a section of code for that chapter. And you don’t just get completed versions of the book’s scripts: You get a version that matches up with each chapter so you’ll never get too confused about exactly how your version of a script or web page should look.
And so you don’t wear down your fingers typing long web addresses the Missing CD page also offers a list of links that you can click to bring you to the websites mentioned in this book.
If you register this book at you’ll be eligible for special offers-like discounts on future editions of PUP & MySQL: The Registering takes only a few clicks. To get started, type into your browser to hop directly to the Registration page
Got questions? Need more information? Fancy yourself a book reviewer? On the Feedback page, you can get expert answers to questions that come to you while reading, share your thoughts on this Missing Manual, and find groups for folks who share your interest in PHP, MySQL, and web applications in general. To have your say
In an effort to keep this book as up-to-date ano accurate as possible each time we print more copies, we’ll make any confirmed corrections you’ve suggested. We also note such changes on the book’s website so you can mark important corrections into your own copy of the book if you like. Go to to report an error and view existing corrections
Safari” Books Online
With a subscription, you can read any age and watch any video from the library online. You can read books on your cell phone and mobile devices access new titles before they are available for print and get exclusive access to manuscripts in development and post feedback for the authors. You can copy and paste code samples organize your favorites download chapters bookmark key sections create notes print out pages and benefit from tons of other time-saving features.
O’Reilly Media has uploaded this book to the Safari Books Online service. To have full digital access to this book and others on similar topics from O’Reilly and other publishers sign up for free at