# 开始连接
my $DSN = "driver=Microsoft Access Driver (*.mdb);dbq=C:\\temp\\try.mdb";
my $dbh = DBI->connect("dbi:ODBC:$DSN",'','')
or die "Can't connect to Database: $DBI::errstr";
# 读取记录
my $sth = $dbh->prepare( q{
SELECT * FROM table1
}) or die "Can't prepare statement: $DBI::errstr";
my $rc = $sth->execute
or die "Can't execute statement: $DBI::errstr";
# 显示出前三列
print "Query will return $sth->{NUM_OF_FIELDS} fields.\n\n";
print "Field names: @{ $sth->{NAME} }\n";
my $ary_ref;
while ( $ary_ref = $sth->fetchrow_arrayref) {
print "$ary_ref->[0] : $ary_ref->[1] : $ary_ref->[2]\n";
}
# 关闭连接
die $sth->errstr if $sth->err;
$dbh->disconnect;