in reply to Re: What to do when DBI connect fails
in thread What to do when DBI connect fails

# # ----------------------------------------------- # open the database handle if possible, if not return proper error +msgs # ( $ret , $msg , $dbh ) = $self->doConnectToDb ( $db ) ; # ----------------------------------------------- sub doConnectToDb { my $self = shift ; my $db = shift || 'non_accessible_db' ; my $ret = 400 ; my $msg = 'cannot connect to the "' . $db . '" database: '; my $dbh = undef ; $dbh = DBI->connect("dbi:Pg:dbname=$db", "", "" , { 'RaiseError' => 0 # otherwise it dies !!! , 'ShowErrorStatement' => 1 , 'PrintError' => 1 , 'AutoCommit' => 1 , 'pg_utf8_strings' => 1 }) ; if ( defined $dbh ) { $ret = 0 ; $msg = "" ; } else { $msg .= DBI->errstr ; } return ( $ret , $msg , $dbh ) ; }