Databases are a mission-critical part of any company's resources. If you program in Perl, you'll want to learn about the DBI, which can help you connect to many popular databases. This article, the first part of a series, is excerpted from chapter 15 of the book Beginning Perl (Apress; ISBN: 159059391X).
It is now time to talk about one of Perl’s best modules: the Database Independent (DBI) module.DBIprovides an easy-to-use and portable (both across operating systems and across databases) application programming interface (API) that allows us to connect to a wide variety of databases including Oracle, Sybase, Informix, MySQL, mSQL, Postgress, ODBC, and many others, even files with comma-separated values (CSV). With this module we can access and administer databases from our Perl programs, combining the power and enjoyment of Perl with the usefulness of databasing information.
In this chapter we will introduce the concept of SQL and discuss the most common ways to use it. Then we will discussDBIand the relatedDBD(Database Driver) modules. We will then write some Perl code to access and update a MySQL database. Finally, we will take our newfound knowledge and connect it with our topic from the last chapter and create a simple web interface to a database by combining Perl,DBIand CGI. This sounds like fun, so let’s get to it.
Structured Query Language (SQL, pronounced as “EssQueueEl” by most and “Sequel” by some) is a language allowing a programmer access to a relational database. It is relatively easy to use—compared to Perl, learning SQL is a snap. We will talk about some of the most common SQL queries, or commands that access a database, and in talking about them we will describe the language to the point that learning the remaining details will be simply a matter of referring to an SQL book or website.
But we are getting ahead of ourselves. Before we can talk about SQL we need to discuss relational databases.