in reply to Perl DBI Question

You might want to look at the "RaiseError" section of the DBI manual, I think this is what you're looking for.

$dbh = DBI->connect($dsn, $user, $password, { RaiseError => 0, AutoCommit => 0 });

--twerq

Replies are listed 'Best First'.
Re^2: Perl DBI Question
by Coruscate (Sexton) on Jan 21, 2004 at 22:34 UTC

    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;