Hi Brad,
You asked about getting the DB2 environment set up inside a Perl program.
As far as I know, you must have the DB2INSTANCE variable set for the DB2
connection to work, and I generally set up the DB2 environment with a BEGIN
block in the perl code that's going to use DBI.
Here's a small example:
#!/usr/bin/perl
BEGIN {
$ENV{DB2INSTANCE} = q(db2inst1);
$ENV{DB2PATH} = q(/usr/IBMdb2/V7.1);
}
die "Usage: $0 dbname username password\n" unless ( 3 == scalar @ARGV );
use DBI;
my $dbh = DBI->connect ( qq(DBI:DB2:$ARGV[0]), q($ARGV[1]), q($ARGV[2]) ) ||
die;
my $sth = $dbh->prepare("select tabschema, tabname from syscat.tables where
tabshema not like 'SYS%' order by tabname");
$sth->execute();
my $data = $sth->fetchall_arrayref({});
foreach my $row ( @$data ) {
map ( printf ("%s = %s\n", $_, $row->{$_}), sort keys %$row );
print "\n";
}
$dbh->disconnect();
In some of my code, I pass in the instance name from the command line or
from a config file. But the environment setting is almost always the same
as the above.
Stph