linux下的mysql access_在Linux下实现对Microsoft Access Database(.mdb)查询访问

本文档详细介绍了如何在Linux(RedHat 9.0)环境中配置和使用Unix ODBC、MDB Tools及MDB Tools ODBC驱动来访问MDB数据库。主要步骤包括安装Unix ODBC和MDB Tools RPM包,创建ODBC模板文件,定义数据源名称,并通过PHP读取数据。尽管MDB Tools当时不支持写入访问,但适用于仅读取数据到MySQL数据库的情况。文章还提到了一个关于查询带有下划线的表或列的已知错误,并提供了修复此问题的自编译版本。

介绍了如何在Linux访问MDB数据库, 感觉非常有用:)

You will need the following:

Linux ( I’m running RedHat 9.0)

PHP

Apache

UnixODBC

MDBTools

INSTRUCTIONS

1) Download the UnixODBC RPM, found here. I installed unixODBC version 2.2.5.1.

rpm -ivh unixODBC-2-2.5-1.i386.rpm

2) Download the MDBTools rpm, found here. I installed mdbtools version 0.5.1. Read limitations!

rpm -ivh mdvtools-0.5-1.i386.rpm

3) Download the MDBTools ODBC driver rpm. Again I installed version 0.5-1.i386.rpm. Read limitations!

rpm -ivh mdbtools-odbc-0.5-1.i386.rpm

4) Add the mdbtools driver to your unixODBC config.

Create a new text file. NON-LINUX user: Beware do not do this on windows as you might get werid new lines, use vi.

[MDBToolsODBC]

Description = MDB Tools ODBC drivers

Driver = /usr/lib/libmdbodbc.so.0

Setup =

FileUsage = 1

CPTimeout =

CPReuse =

NOTE: The driver may be in /usr/local/lib/libmdbodbc.so.0. This happens if you build from source and use the make install command. The RPM puts it in /usr/lib.

Now install the driver using the file you created. This is called a template file.

odbcinst -i -d -f template.file

5) Define the datasource name. This is done in the /etc/odbc.ini file. So pull up this file in vi or another text editor and add the following lines.

[Dogs]

Description = Microsoft Access Database of Dogs

Driver = MDBToolsODBC

Database = /var/data/my_dog_db.mdb

Servername = localhost

UserName =

Password =

port = 5432

That’s it you should now have an odbc connection available. I will demonstrate using php, this assumes that your php is compiled with UnixODBC support, the version that ships with Redhat 9 does if yours does not then you can learn how here.

So I will write a quick php script to query my dogs database and print out the names and weights of my dogs.

$myDB = odbc_connect(”Dogs”,”",”");

$query = “select name, weight from dog_list”;

$result = odbc_exec($myDB, $query);

while (odbc_fetch_row($result)) {

print “Name = ” . odbc_result($result,”name”);

print “

Weight = ” . odbc_result($result,”weight”);

}

If you get a php error that says odbc_connect is not a function then see if you have php-odbc installed. Do rpm -qa php-odbc. If you see php-odbc returned then you have it if not install it., the rpm is available on the redhat discs.

Limitations:

- As of the time of writing this entry MDBTools did not support write access to the mdb files. This was fine for my purposes as I was reading data in and sticking it into a mysql database.

- There is a bug in MDBTools v0.5 which does not allow you to query tables or columns with an underscore. This was a bug I hit early on, but it has been fixed in new version 0.6 but that has not been released as of the time of writing this article. So I recompiled the 0.5 source code with the fix from the 0.6 CVS repository. I have bundled it into a 0.5 release and have the two rpms mentioned above here:

mdbtools-0.5-1.i386.rpm

mdbtools-odbc-0.5-1.i386.rpm

I would check the official download site before using my hacked version as I’m sure this bug will be fixed in 0.6 (plus rumor has write access will be present as well).

posted on 2006-10-09 11:19 泡泡牛 阅读(5049) 评论(0)  编辑 收藏 引用 所属分类: Linux

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值