Below is my new code that seems to work.
I can now connect from Terminal A and B at the same time in different
databases.
Instead of my standard $dbh I used a hash instead.
Any glaring flaws?
Thanks to Joe Beard for his reply that directed me to some helpful
material.
Aaron Johnson
sub db_connect {
my $pd = shift;
if ($pd->{change}) { &db_disconnect($pd->{database}) };
if ($pd->{change} || !$dbh{$pd->{database}}) {
$dbh{$pd->{database}}=DBI->connect(
"dbi:mysql:$pd->{database}", 'user', 'password', {
PrintError => 1,
RaiseError => 1,
}
) || die $DBI::errstr;
return($dbh{$pd->{database}})
}
else {
# warn "No need to change!\n";
return($dbh{$pd->{database}})
}
}
sub db_disconnect {
my $db_to_disconnect = shift;
if ($dbh{$db_to_disconnect}) {
$dbh{$db_to_disconnect}->disconnect;
warn "Disconnected from: $db_to_disconnect\n";
}
}