Hi Monks! I am new to DB access via perl and would like some guidance on how to manage/improve exception handling for my code. I have included below the DB code from my overall script and I would greatly appreciate your input on this.
my $server_name = 'test_server'; my $database_name = 'test_db'; my $database_user = ''; my $database_pass = ''; if($DB_insert =~ /true/i) { my $DSN = "driver={SQL Server};server=$server_name;database=$datab +ase_name;uid=$database_user;pwd=$database_pass;"; my $dbh = DBI->connect("dbi:ODBC:$DSN", {PrintError =>0, RaiseErro +r =>1}); eval { if (!$dbh) { #testing connection to DB print "Could not connect to database: $DBI::errstr"; } if($dbh) { print "Connected to DB!!"; } my $sql = "INSERT INTO test_table VALUES ('test_env','$partner +','$id','$filename','$date $time','$line_count')"; my $sth = $dbh->prepare($sql); $sth->execute(); }; if($@) { $dbh->disconnect(); QuitProgram("DB Failure: $@"); } $dbh->disconnect(); }
In reply to DB Exception Handling by sowais
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |