Hammy has asked for the wisdom of the Perl Monks concerning the following question:
the fatal piece is invoked, with the code below, I get the "Internal Server Error". Second, fatal is a custom error routine that emails me and puts a nice message up for the user. I only want that error to show up after I have tried a few times. Here is the code:DBI->connect(....) || fatal(error message)
Thanks in advance for your suggestionssub openDB { my ($database, $user_id, $password) = (); open( CFG, $db_cfg ) or fatal("Cannot open databse config file."); ($database, $user_id, $password, $pwkey) = split( ',', <CFG>); $done = 0; $num_tries = 0; while (!$done) { $num_tries += 1; # If we exceeded the custom amount of attempts call error rou +tine if ($num_tries > 4) { fatal (" Could not open database: $DBI::errstr"); $done = 1; } else { # Make the database connection eval { $dbh = DBI->connect("DBI:mysql:$database:<ipaddress:po +rt>", $user_id, $password); } # If there is an error try again if ($@) { next; } # No error drop out of loop else { $done = 1; } } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Attempting to trap a DBI->connect error
by mifflin (Curate) on Jan 06, 2007 at 03:46 UTC | |
by Hammy (Scribe) on Jan 07, 2007 at 16:57 UTC | |
|
Re: Attempting to trap a DBI->connect error
by kyle (Abbot) on Jan 06, 2007 at 03:50 UTC | |
|
Re: Attempting to trap a DBI->connect error
by Cabrion (Friar) on Jan 06, 2007 at 11:51 UTC |