Close, but not what the OP was asking for. That will automatically die if the connection fails. Either what pg provided or something like the following would be more of a workable solution:
#!c:/perl/bin/perl -w
$|++;
use strict;
use DBI;
my $table = 'table_name';
my @db = (
['localhost', 'user1', 'pass1'],
['other.server.com', 'user2', 'pass2'],
['last.attempt.com', 'user3', 'pass3'],
);
my $dbh;
for my $db (@db) {
eval {
$dbh = DBI->connect(
'dbi:mysql:database=' . $table . ';host=' . $db->[0],
$db->[1], $db->[2],
{ AutoCommit => 1, RaiseError => 1 }
);
};
next if $@;
}
die "Unable to connect to any database!\n"
if not defined $dbh;
|