Chapter 12. Introducing Databases and SQL

In the last chapter you learned how your PHP scripts can use external files to store and retrieve data. Although files do a great job in many circumstances, they're pretty inflexible as data storage solutions go. For example, if you need to filter or sort the data retrieved from a file, you have to write your own PHP code to do it. Not only is this tiresome, but if you're working with large sets of data — for example, hundreds of thousands of user records — your script will probably grind to a halt. Not good if you're hoping to build a popular Web site.

Databases are specifically designed to get around this problem. With their capabilities of organization and immaculate record keeping, they're a bit like lending libraries staffed by super-heroes. No more searching for hours through shelves of musty tomes; just a word at the front desk, a blur of blue and red, and the last remaining copy of Love in the Time of Cholera appears — as if by magic — on the desk in front of you.

This is the first in a series of three chapters in which you explore databases and learn how you can use them to create powerful, efficient PHP applications. The next chapter shows you how to access data in databases, and Chapter 14 looks at inserting, updating, and deleting data.

The aim of this chapter is to get you started with databases. In this chapter you:

  • Examine the general advantages of using databases rather than files to store your data

  • Learn about some of the popular ...

Get Beginning PHP 5.3 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.