Supplemental files and examples for this book can be found at http://examples.oreilly.com/9780596008642/. Please use a standard desktop web browser to access these files, as they may not be accessible from all ereader devices.
All code files or examples referenced in the book will be available online. For physical books that ship with an accompanying disc, whenever possible, weve posted all CD/DVD content. Note that while we provide as much of the media content as we are able via free download, we are sometimes limited by licensing restrictions. Please direct any questions or concerns to .
Preface
Database management systems are the electronic filing cabinets that help individuals and organizations to manage the mass of information they process each day. With a well-designed database, information can be easily stored, updated, accessed, and collated. For example, a freight company can use a database to record data associated with each shipment, such as the sender and recipient, origin and destination, dispatch and delivery time, current location, and shipping fee. Some of this information needs to be updated as the shipment progresses. The current status of a shipment can be read off the database at any time, and data on all shipments can also be summarized into regular reports.
The Web has inspired a new generation of database use. Its now very easy to develop and publish multi-user applications that dont require any custom software to be installed on each users computer. Adding a database to a web application allows information to be automatically collected and used. For example, a customer can visit an online shopping site, see whats in stock, place an order, submit payment information, and track the order until the goods are delivered. He can also place advance orders for goods that arent available, and submit reviews and participate in discussions on items he has purchased. If all goes well, the sites staff doesnt need to intervene in any of these actions; the less staff intervention required during normal operation, the more scalable the application is to large numbers of users. The staff are then free to do more productive tasks, such as monitoring sales and stock in real time, and designing special promotions based on product sales.
Both authors of this book have always been interested in using computers as a tool to make things faster, more efficient, and more effective. Over the past few years weve repeatedly found that the MySQL database management systemand the PHP and Perl programming languagesprovide a perfect platform for serious applications such as managing research records and marking student assignments, and not-so-serious ones like running the office sweepstakes. On the way, weve learned a lot of lessons that wed like to pass on; this book contains the tips that we think most readers will find useful on a daily basis.
Who This Book Is for
This book is primarily for people who dont know much about deploying and using an actual database-management system, or about developing applications that use a database. We provide a readable introduction to relational databases, the MySQL database management system, the Structured Query Language (SQL), and the PHP and Perl programming languages. We also cover some quite advanced material that will be of interest even to experienced database users. Readers with some exposure to these topics should be able to use this book to expand their repertoire and deepen their understanding of MySQL in particular, and database techniques in general.
Whats in the Book
The book is divided into six main parts:
Introduction
Using MySQL
Advanced Topics
Web Database Applications with PHP
Interacting with MySQL using Perl
Appendix
Lets look at how the individual chapters are laid out.
Introduction
We first provide some context for the book in , where we describe how MySQL and web database applications fit into the domain of information management tools and technologies.
In , we explain how you can configure the software required for this book on different operating systems. This chapter provides far more detail than most books because we know that its hard to learn MySQL if you cant first get it up and running.
introduces the standard text-based interface to the MySQL server. Through this interface, you can control almost every aspect of the database server and the databases on it.
Using MySQL
Before we dive into creating and using databases, we look at proper database design in . Youll learn how to determine the features that your database must have, and how the information items in your database relate to each other.
In , we explore how to read data from an existing MySQL database and how to store data in it.
In , we explain how to create a new MySQL database and how to modify an existing one.
covers more advanced operations such as using nested queries and using different MySQL database engines.
continues the advanced operations theme; in this chapter, youll find a discussion of importing and exporting data, and peeking under the hood to see how the MySQL server processes a given query.
In any serious application, youll need to prevent unauthorized data access and manipulation. In , we look at how MySQL authenticates users and how you can allow or disallow access to data or database operations.
Advanced Topics
Data stored on a computer can be lost due to hardware failure, theft, or other incidents such as fire or flood. If you need your database, youll save yourself a lot of hair-pulling by setting up regular and complete backups of your database structure and data. In , we introduce techniques that can help you easily recover from a data loss or corrupted database.
MySQL is highly configurable; in , we describe how you can use configuration files to modify the behavior of the MySQL server and associated programs.
In , we introduce several ways to customize your MySQL server and your application database for improved performance. Small speedups for frequently used queries can markedly improve the overall performance of your system.
Web Database Applications with PHP
In , we examine how web database applications work.
follows with an introduction to the PHP programming language and a discussion of how PHP can be used to access and manipulate data in a MySQL database.
In , we walk through the design of a wedding gift registry to illustrate the process of developing a full-fledged web database application.
Interacting with MySQL Using Perl
In , we present an easy-to-follow introduction to the powerful Perl programming language.
We continue in by using the Perl DBI module to connect to a MySQL database to store and read information, and to import and export data.
We conclude this part in by using the Perl CGI module to create dynamic web pages that can interact with a MySQL database.
Appendix
The Appendix contains all the source code for the wedding gift registry developed in . You can download this source code, and much more, from the books web site.