用perl 连接access,用了ODBC数据源
1.在Win32下安装ActivePerl 然后在PPM下安装DBI和DBD::ODBC
2.创建一个access数据库
3.创建ODBC数据源
3.1控制面板-->管理工具-->数据源(ODBC)
3.2选"系统DSN"-->添加
3.3选择"Driver do Microsoft Access (*.mdb)"
3.4然后有个对话框,填入数据源名,点确定
4试着运行以下代码:
#!/usr/bin/perl
use warnings; use strict; use DBI; use DBD::ODBC;
$username = "";
$pwd = ""; my $dbh = DBI->connect("DBI:ODBC:Employee", $username, $pwd) or die("Couldn't make connection to database:$DBI::errstr"); #注意:这里的Employee是你刚才填数据源时填入的名字
my $sth = $dbh->prepare(q{SELECT * FROM employee}) or die("Cannot prepare statement:", $dbh->errstr(),"\n"); my $rc = $sth->execute() or die("Cannot execute statement:", $sth->errstr(), "\n");
my @array;
while (@array = $sth->fetchrow_array()) { write(); }
warn($DBI::errstr) if $DBI::err; $dbh->disconnect(); $sth->finish();
format STDOUT = @<<<<<<@<<<<<<<<<@<<<<<<<<<<@<<<<<@<<<<<<<<<@<<<<<<<<<<<<<< $array[0],$array[1],$array[2],$array[3],$array[4], $array[5] .
|
阅读(2284) | 评论(0) | 转发(0) |