in reply to how to test a connection with mysql db

DBI->connect() will return undef if the connection failed, so you can call first one, then another on failure by,

my $dbh = DBI->connect(@pref_args) || DBI->connect(@alt_args) or die $DBI::errstr;
You will want to avoid setting RaiseError or PrintError in the connect calls. Set those you want as soon as convenient after connecting.

Your error message suggests that your connection may be failing due to bad arguments. I'm not positive of that, but it's worth checking.

The $dbh->ping method is handy for checking if a connection is still alive, once made.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: how to test a connection with mysql db
by jZed (Prior) on Apr 15, 2005 at 22:02 UTC
    You will want to avoid setting RaiseError or PrintError in the connect calls.

    Actually, RaiseError defaults to 0 so you can just leave it off, but PrintError defaults to 1 so if you don't want messages printed, you'll need to explicitly set PrintError to 0 in the call to connect().