Here's a script that will die with an error if any of the parts of the database communication process fail. You'll need to change the values for $dsn, $user, etc. but everything else should work regardles of which DBD you are using.
#!/usr/bin/perl -w
use strict;
use DBI;
print "Loaded the DBI module ... ok\n";
my($dsn,$user,$password,$attributes,$table)=
( 'dbi:CSV:'
, 'me'
, 'myPassword'
, { RaiseError=>1, PrintError=>0, AutoCommit=>1 }
, 'myTable'
);
my $dbh = DBI->connect( $dsn, $user, $password, $attributes );
print "Connected to database '$dsn' ... ok\n";
my $success = $dbh->ping;
print "Connection to database '$dsn' is active ... ok\n" if $success;
my $sth = $dbh->prepare( "SELECT * FROM $table WHERE 1=0" );
$sth->execute;
$sth->finish;
print "Accessed table '$table' ... ok\n";
$dbh->disconnect;
print "Disconnected ... ok\n";
__END__
|