# In file Database.pm package Database; our @ISA = qw(Exporter); our @EXPORT_OK = qw( DB_connect DB_disconnect ); use DBI; my %config = ( type => 'mysql', name => 'SUN', ); sub DB_connect { # Allow the user to override anything they want to in %config %config = (%config, @_); my $connect_string = join(':', 'DBI', $config{type}, $config{name}, ); my $dbh = DBI->connect( $connect_string, $config{user}, $config{password}, $config{options}, ); unless ($dbh) { die "Cannot open connection to $connect_string with $config{user} / $config{password}\n" . DBI->errstr, $/; } return $dbh; } sub DB_disconnect { my ($dbh) = @_; $dbh->disconnect if UNIVERSAL::isa($dbh, 'DBI'); return 1; } 1;