in reply to Re^2: Ignoring/Trapping the DIE signal
in thread Ignoring/Trapping the DIE signal
Didn't quite understand the DB def for 'value' being empty in example, but tried it anyway, got 'DBD::mysql::st execute failed: No database selected' at each execute, so tried filling in with real values as above, and got same errors as in orig post, ending with 'Can't call method "quote" on an undefined value at ./pd.pl line 83', then perl died.use Tie::Constrained; # Other code as before, with and without SIG{__DIE__} sub db_connect { my ( $dsn, # data source name $error_msg # if any ); # Set up connection string... $dsn = "DBI:mysql:database=xxx;host=somehost;port=nn"; tie $cfg::dbh, 'Tie::Constrained' => { test => sub { $_[0]->isa('DBI::db') and $_[0]->ping; }, value => DBI->connect($dsn, "user", "passwd", #'DBI:mysql:','','', {RaiseError => 0, AutoCommit => 1}), fail => sub { $_[1] = DBI->connect($dsn, "user", "passwd", {RaiseError => 0, AutoCommit => 1}); if( $DBI::errstr) { # FAIL $error_msg = "db_connect(): $DBI::errs +tr"; print "$error_msg\n"; $cfg::db_retry_cnt++; if( !$cfg::db_cxn_msg_sent && $cfg::db_retry_cnt > 3 ) { print "would have sent email/sms\n +"; $cfg::db_cxn_msg_sent = 1; } } else { # SUCCESS $cfg::db_cxn_msg_sent = 0; $cfg::db_retry_cnt = 0; } } }; $Tie::Constrained::STRICT = 1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Ignoring/Trapping the DIE signal
by McDarren (Abbot) on Jun 15, 2006 at 16:54 UTC | |
by chrism01 (Friar) on Jun 15, 2006 at 23:45 UTC |