Tim Bunce, the lead developer of DBI.pm, asserts 'The DBI is a database access module for the Perl programming language. It defines a set of methods, variables, and conventions that provide a consistent database interface, independent of the actual database being used. [..] The DBI is a layer of 'glue' between an application and one or more database driver modules. It is the driver modules which do most of the real work. The DBI provides a standard interface and framework for the drivers to operate within.' (http://search.cpan.org/~timb/DBI-1.38/DBI.pm)
However, DBI attempts to make it simple for programmers by creating almost seamless integration with drivers. It's only when databases have different specifications that one actually has to take note of which database they're using. The most notable differences are between transactional databases, and specific functions that may be linked to specific queries, such as fetching the index of an automatically incrementing database. This tutorial will cover the basics of databases, assuming that you will have access to a server with Perl, MySQL, and DBI.
Opening The Connection
use DBI; $dsn = 'dbi:mysql:dbname=NameOfDatabase'; $user = 'mysqlusername'; $password = 'mysqlpassword'; $dbh = DBI->connect($dsn, $user, $password, { RaiseError => 1, AutoCommit => 0 }); |
What exactly this code mean? Obviously, you're connecting to the database, but what are these variables standing for?