Microsoft Word - Sam's Teach Yourself MySQL in 21 Days - SAMS.doc

(singke) #1

Installing the Perl DBI and the MySQL DBD


To take advantage of the Perl DBI you need to install the necessary modules. This process is easy, but it
can be a little intimidating for a beginner. The first step is to get the latest Perl DBI. You can find this in
several locations. The Comprehensive Perl Archive Network (CPAN) has the latest available version of the
interface, as well as the various database drivers. Another place to find the driver and interface is at the
MySQL Web site. This may not be the latest version, but it will still work. You can also find the Perl DBI and
the MySQL DBD on the CD-ROM that is included with this book. This will save you the hassle of
downloading it from the Internet.


Perl is made up of a series of modules. Each module extends the capabilities of MySQL. There are a
ton of modules that are available for Perl. There are modules for CGI, Tk, various math functions, and
even modules that extend other programs like the Apache Web server.
Installing modules is really easy with Perl. You can do it one of two ways. The first way is to download it
and install it as you would any other program, following the instructions in the README file. The other
way is to let Perl do it for you.
Unfortunately, the way to do this is different depending on the platform you are using, though they work
similarly. The next section covers Perl for the Window's platform.

Downloading and Installing Perl


You must have already installed the Windows version of Perl. This can be downloaded and installed from
ActiveState's Web site at http://www.activestate.com. You can also find a very useful FAQ at http://www.perl.com.
After you have installed Perl, go to the Perl directory. In it, you will find a subdirectory called bin. In this
directory, you will see all the various utilities that come with Perl. Find the file named PPM. This utility is the
Perl Package Manager. This neat little utility will find a Perl module on the Internet, download it, and install it
automatically. You can't ask for better service.
To begin installing the DBI, double-click the PPM file. A DOS shell window this window and the
command line. It's pretty basic, but that's Perl—programs that perform one job well. To see a list of
available commands, type help. A list of commands will scroll by, giving you several options. If you
would like a more thorough explanation of a command, type the word help followed by the command.
For example, if you wanted to learn more about the set command, you would type the following:
PPM> help set
This command would display a list of options from which you can choose. You are going to use the
install command. This will tell the PPM to install the specified package. Remember that this utility is
case sensitive, so all your commands and packages must be typed correctly or it will not function in the
expected manner. If you want to install the DBI from the Internet, make sure your Internet connection is
active, and then type the following command:
PPM> install DBI
The PPM will go out and search for the latest DBI module and begin downloading it. Unfortunately, the
PPM provides no indicators on where it stands in the process, so be patient. It may not look like PPM is
doing anything—rest assured that it is.
After the PPM has downloaded the package successfully, it will begin to install it. A lot of data will flash
across the screen, indicating that PPM is hard at work. After it has completed the process, it will tell you
if it was successful or not. More likely than not, you will have a successful install. If you don't, repeat the
process or try to install the module manually.
As you can see, PPM is a great tool to use to add modules to your Perl for Windows. All other platforms
can use a similar utility available as an option with the Perl command. You can accomplish the same
goal as PPM by typing the following from the command line (this assumes that you have Perl installed
and that it is part of your path):
%> perl –MCPAN –e shell
After typing this command, you will enter an interactive session, just like PPM. You will be asked a few
questions, mostly about where to find key files and so on. The defaults are generally correct. After you
have answered all the questions, type the following from the command line:
%> install DBI


This will install the DBI in the correct place.
Free download pdf