Added database connection

This commit is contained in:
hjp 2007-06-17 21:40:04 +00:00
parent 14cd9fc2fb
commit cd0fcfae1b
1 changed files with 20 additions and 0 deletions

View File

@ -30,6 +30,26 @@ sub new {
$self->{unknown_gid} = 65533;
$self->{fh_log} = exists($opt->{fh_log}) ? $opt->{fh_log} : \*STDERR;
$self->{log_level} = 99;
if ($opt->{dbi}) {
$self->{dbh} = DBI->connect(@{ $opt->{dbi} },
{ AutoCommit => 0,
PrintError => 1,
RaiseError => 1
}
);
} elsif ($opt->{dbi_file}) {
my $fn = $opt->{dbi_file};
open(FN, "<$fn") or die "cannot open $fn: $!";
my $line = <FN>;
close(FN);
my @cred = split(/[\s\n]+/, $line);
$self->{dbh} = DBI->connect(@cred,
{ AutoCommit => 0,
PrintError => 1,
RaiseError => 1
}
);
}
return $self;
}