sowais has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks! I am somewhat new to PERL and wanted to get some help in error handling for DB access. I have written the below code for a simple record INSERT, which works perfectly fine, but I know there is room for improvement and would appreciate it if you guys can offer any tips for error handling. Thanks in advance!
use strict; use warnings; use DBI; my $server_name = 'Smoke\Reporting'; my $database_name = 'DBtest'; #do not need user/pass to connect my $DSN = "driver={SQL Server};server=$server_name;database=$database_ +name;"; my $dbh = DBI->connect("dbi:ODBC:$DSN"); if (!$dbh) { #testing connection to DB print "Could not connect to database: $DBI::errstr"; } if($dbh) { print "Connected to DB!!"; } my $sql = "INSERT INTO RecordCount VALUES ('filename','date','count')" +; my $sth = $dbh->prepare($sql); $sth->{ChopBlanks} = 1; $sth->execute(); $dbh->disconnect(); exit 0;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Database Error Handling
by runrig (Abbot) on Aug 12, 2013 at 16:40 UTC | |
|
Re: Database Error Handling
by mje (Curate) on Aug 12, 2013 at 16:45 UTC |