Chapter 58. DBI

Alligator Descartes and Tim Bunce

DBI, the Database Interface for Perl, is an ongoing effort to provide a robust interface for database connectivity that insulates the programmer from the variability of different database systems. With the explosion in popularity of Perl as the de rigeur language for web programming, a simple and standard interface to databases is imperative.

The Architecture of DBI

The architecture of DBI (pictured in Figure 58-1) is elegant. We are channelled toward the solution by the very concept of the interface that we are trying to define. As usual, Perl helps us along by providing powerful syntactic constructs and regular expressions that facilitate data processing on the scale required by large database applications.

The DBI interface is the term used to describe both the interface specification—the methods used to build programs—and the software modules that make this possible. We’ll first take a look at why you should be using DBI, and then describe the modular structure of DBI and its interaction with Perl. Finally, we’ll show you some sample DBI code.

Why DBI?

Database programming, as you will learn after you’ve programmed or administered a few different databases, is pretty much all the same. Hence DBI. The fundamental processes involved in doing anything with a database are pretty similar right across the board: connecting to and disconnecting from the database, storing and retrieving data, and opening and closing cursors (data structures ...

Get Computer Science & Perl Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.