According to our definition, a database is an organized collection of data that serves some purpose. Simply having MySQL up and running is not sufficient to give your database a purpose. How you use the data you put in your MySQL database defines its purpose. Imagine a library where nobody ever reads the books. There would not be much point in storing and organizing all those books if they’re never used. Now, imagine a library where you could not change or add to the collection. The utility of the library as a database would decrease over time since obsolete books could never be replaced and new books could never be added. In short, a library exists so that people may read the books and find the information they seek.
Databases exist so that people can interact with them. In the case of electronic databases, the interaction occurs not directly with the database, but indirectly through software applications. Before the emergence of the World Wide Web, databases typically were used by large corporations to support various business functions: accounting and finance, shipping and inventory control, manufacturing planning, human resources, and so on. The Web and more complex home computing tasks have helped move the need for database applications outside the realm of the large corporation.
Therefore, it is not surprising that the area in which databases have experienced the most explosive growth—an area where MySQL excels—is web application development. As the demand for more complex and robust web applications grows, so does the need for databases. A database backend can support many critical functions on the Web. Virtually any web content can be driven by a database.
Consider the example of a catalog retailer who wants to publish on the Web and accept orders online. If the contents of the catalog are entered directly into one or more HTML files, someone has to hand edit the files each time a new item is added to the catalog or a price is changed. If the catalog information is instead stored in a relational database, it is possible to publish real-time catalog updates simply by changing the product or price data in the database. It is also possible to integrate the online catalog with existing electronic order-processing systems. Using a database to drive such a web site has obvious advantages for both the retailer and the customer.
Here is how a simple web application typically interacts with a database. The database is on your web server or another machine to which your server can talk (a good DBMS makes this kind of distributed responsibility easy). You put a form on one web page that the user fills in with a query or data to submit. When the user submits the form to your server, the server runs a program that you’ve written to extract the data from the form. These programs are most often written as CGI scripts and Java servlets, but they can also be implemented by embedding programming commands directly inside the HTML page. We will look at all of these methods later in this book.
Now your program knows what the user is asking for or wishes to add to the database. The program issues an SQL query or update, and the database magically takes care of the rest. Any results obtained from the database can be formatted by your program into a new HTML page to send back to the user.