Chapter 7. Database Basics


We're now going to introduce you to basic database structure so that you have an understanding of databases. Adding MySQL to PHP and combining the applications for your dynamic web site is a great start. But, it helps tremendously to structure your database right. We'll give you a solid understanding of both database design and the language that's used to communicate with the database, SQL. The first step in setting up your database is to design how you'll store your data. Then, you'll learn how to add, view, and change data.

Databases are a repository for information. They excel at managing and manipulating structured information. Structured information is a way to organize related pieces of information, which we discussed previously in our chapters on PHP. The basic types of structured information, which can also be called data structures, include:

  • Files

  • Lists

  • Arrays

  • Records

  • Trees

  • Tables

Each of these basic structures has many variations and allows for different operations to be performed on the data. An easy way to understand this concept is to think of the phone book. It's the most widespread database, and it contains several items of informationname, address, and phone number, as well as each phone subscriber in a particular area. Phone books have evolved, and some people may have bolded names, but for the most part, each entry in the phone book takes the same form.

If you think of the physical hardcopy phone book in similar terms as a database, the phone book is a table, which contains a record for each subscriber. Each subscriber record contains three fields (also known as columns or attributes): name, address, and phone number. These records are sorted alphabetically by the name field, which is called the key field. The phone book is alphabetized by last names first; look at Figure 7-1 for how typical record and fields display in your database based on the phone book analogy.

Figure 7-1. Phone book record and fields


If you took the same data from the phone book and put it into a database, you could build queries such as who has the phone number 651-668-2251 or everyone in a specific zip code who has the last name Davis. This type of database is like a big spreadsheet; it can be called a flat-file database, which means each database is self-contained in a single table. Since the 1970s, relational databases for managing data have replaced flat files.

The advantages of a fully relational RDBMS system are wide-ranging, including:

  • Unbeatable performance

  • Capability and power benefits

  • Scalable and distributable systems

  • Able to easily take advantage of new hardware technology

  • Flexibility for evolution of users' data



Learning PHP and MySQL
Learning PHP and MySQL
ISBN: 0596101104
EAN: 2147483647
Year: N/A
Pages: 135

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net