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;
In reply to Database Error Handling by sowais
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |