Kiang has asked for the wisdom of the Perl Monks concerning the following question:

DBI experts, I'm a novice of DBI, appreciate any help you can provide.
I'm working on Solaris 2.8, coding a Perl script to connect to DB2 using DB2 connect. The sample program I got from IBM uses following to connect:
use DBI; use DB2Util; print "\nCalled DB2Util\n"; my(%database,$user,$password)=CmdLineArgChk(@ARGV); print "\nConnect to datbase... \n"; my $dbh=DBI->connect($database,$user,$password) ||die "Cannot connect +o database :$DBI:errstr";
But DBI is not installed on the Unix box.
After reading FAQ and DBI pages on cpan.org website, I found DBI-1.48.tar.gz is free for download that has the Database Independence Interface for Perl I need. Can I just download the file and copy Unix server ? After download, where (which directory) on Unix should I install DBI.pm ? Is DBI.pm the only file I need to copy or all the files in the zip file.
From reading other nodes, it seems DBI needs to be installed. Is it free that can be download from the web ? Where ?
Appreciate your help.
Kiang

Replies are listed 'Best First'.
Re: Install DBI on Unix
by holdyourhorses (Monk) on Sep 14, 2005 at 19:42 UTC
Re: Install DBI on Unix
by Codon (Friar) on Sep 14, 2005 at 19:46 UTC
    The easiest way to go about getting DBI installed on a *nix machine is to use Perl's CPAN interface. You will most likely need your sysadmin to do this. DBI by itself, however, does not know how to talk to any database. You need to install a database driver. Since you mentioned DB2, you will want Bundle::DBD::DB2. This includes Bundle::DBI which in turn includes DBI, DBI::Shell, Storable, Net::Daemon,RPC::PlServer, and DBD::Multiplex. If you have root on the box, try the following.
    perl -MCPAN -e shell
    This will ask you if you want to manually configure. I generally say 'No' on my dev boxes; Perl seems to select reasonable defaults and it all works. Once configuration is done, you should get a cpan> prompt. Here you can just type:
    install Bundle::DBD::DB2
    This will download the latest sources; determine any pre-dependencies; download and install any missing pre-dependencies; then make && make test && make install all of the packages mentioned above.

    Note: DBD::DB2 will need to know the libraries and paths for DB2 in order to properly build and possibly even how to connect to a database to run make test.

    Ivan Heffner
    Sr. Software Engineer, DAS Lead
    WhitePages.com, Inc.

      Last time I checked, the DBD::DB2 tests were superficial and didn't do anything whatsoever with DB2 (past loading the libraries). Which is why DB2::db's tests actually connect to a server, create a database, and do some minor stuff with it.

      That said, DBD::DB2 still does need the install path for DB2 (v8.2 by the sounds of the OP's question) to compile/link. I've been after the author of DBD::DB2 for years to get better tests into the suite, but he does this on company time (IBM actually pays someone to develop this), and this is but one of his responsibilities.