Using a Database Management System

Using a Database Management System

Data is such an important part of modern programming that entire programming languages are devoted to manipulating databases. The primary standard for database languages is Structured Query Language (SQL). SQL is a standardized language for creating databases, storing information into databases and retrieving this information. Special applications and programming environments specialize in interpreting SQL data and acting on it.

Often a programmer will begin by creating a data structure in SQL, then will write a program in some other language (such as PHP) to allow access to that data. The PHP program can then formulate requests or updates to the data, which are passed on to the SQL interpreter. This approach has a couple of advantages. First, once you learn SQL, you can apply it easily to a new programming language. Also, you can easily add multiple interfaces to an existing data set because many programming languages have ways to access an SQL interpreter. Many relational database management systems are available, but the MySQL environment is especially well suited to working with PHP. However, the basic concepts of SQL remain the same no matter what type of database you are working on. Most of the SQL commands described in this chapter work without modification in Microsoft Access, Microsoft SQL Server, and Oracle, as well as a number of other RDBMS packages.

I'll begin this chapter by explaining how to create a simple database in MySQL. There are a number of ways to work with this package, but I'll start by showing you how to write a script that builds a database in a text file. I'll use the SQL language, which is different in syntax and style from PHP. Then I'll show you SQLyog, a wonderful front-end package for working with MySQL databases. In Chapter 8, "Connecting to Database Within PHP," I'll show you how to contact and manipulate your MySQL database from within PHP.