如何使用Perl连接到MS Access数据库? [英] How do I connect to an MS Access database using Perl?

查看:228
本文介绍了如何使用Perl连接到MS Access数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的本地机器上有一个.accdb文件,我试图连接到它,并从DB中的3个表中读取一些数据。如何使用Perl建立连接?

I have a .accdb file on my local machine and I am trying to connect to it and read some data from 3 tables within the DB. How do I establish the connection using Perl?

到目前为止,我已经一起抓这个MS Access,但我得到错误说,我没有使用正确的驱动程序。任何想法?

So far I have scraped together this much for MS Access, but I am getting errors saying that I am not using the correct driver. Any ideas?

my $msaccess_dbh = DBI->connect(
    'dbi:ODBC:driver=microsoft access driver (*.accdb);' .
    'dbq=C:\path\to\database\databasefile.accdb'
);

谢谢!

澄清,我没有真正的要求。我只需要从这个MS Access数据库做2或3个选择,然后我会完成它。所以任何帮助连接和选择将是伟大的。

Just to clarify, I have no real requirements here. I just need to do 2 or 3 selections from this MS Access DB, and then I will be done with it. So any help with connecting and selecting would be great. Thanks again.

推荐答案

根据你的连接字符串,它看起来像你是(a)在Win32和数据库。如果我是正确的为什么打扰ODBC,当你可以直接与Jet连接?参考如下:

Based on your connection string it looks like you are (a) on Win32 and (b) connecting to a database on your local machine. If I am correct why bother with ODBC when you can connect directly with Jet? Refer below:

#!/usr/bin/perl
use strict;use warnings;

use Win32::OLE;

my $DBFile  = qw( X:\Path\To\Your\Database.mdb ); # 
#Choose appropriate version of Jet for your system
my $Jet = Win32::OLE->CreateObject('DAO.DBEngine.36')   or die "Can't create Jet database engine.";
my  $DB = $Jet->OpenDatabase( $DBFile );

my $SQLquery = "DELETE * FROM Test_Table";
$DB->Execute($SQLquery, 128); #128=DBFailOnError

这篇关于如何使用Perl连接到MS Access数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆