linux java访问mdb文件,从Linux上的php连接到MS Access远程.mdb文件

I have been digging internet for couple days, reading very old information, that leads to very old and nonexisting sites, still, I understood, what is needed to achieve my goal.

We have a file.mdb on server running WindowsXP, so I need to add it to ODBC data sources. I do that with simple steps, ending up with "System DSN", that allows access to that .mdb file

I need to install on this same server some sort of ODBC bridge, that would allow me to create remote connection to this server, making that bridge connect to servers ODBC DSN, and query out my stuff (could not find any free ODBC bridge)

On UNIX (FreeBSD) machine, I need to install unixODBC and php5-odbc packages, enabling connections to ODBC (already installed)

To connect to remote ODBC and use MS Access db driver, I need to have such a driver for unixODBC, in .so file, that is sitting inside UNIX machine (could not find any free MS Access drivers)

Connect to that server using PHP odbc_connect(DSN,user,password), and in DSN I need to give some connection information and driver, which I need to use (MS Access driver).

Correct me, if I'm mistaken and please give me more advice, how to achieve such a connection.

解决方案

Finally, I found solution.

Set up on Win server FreeSSHd, configure connection account and set directory to one, you need

Set up on unix server sshfs

Mount Win server directory with .mdb files

sshfs {user}@:/ {unix mount point} -o workaround=rename,allow_other

Set up on unix server mdbtools

So, I used default PHP code from docs and write this PHP script:

$rows = $cols = array();

if (($handle = popen('/usr/bin/mdb-export {unix mount point}/{file}.mdb {table} 2>&1', 'r')) !== FALSE) {

while (($data = fgetcsv($handle, 0, ",")) !== FALSE) {

$num = count($data);

if ($row == 1) { for ($c=0; $c < $num; $c++) { $cols[] = $data[$c]; } }

else { for ($c=0; $c < $num; $c++) { $rows[$row][$cols[$c]] = $data[$c]; } }

$row++;

}

pclose($handle);

}

print_r($rows);

Path to /usr/bin/mdb-export should be path to your mdb-export file (use find / -name "mdb-export", if you can't find yours).

Mount point {unix mount point} should be an empty file folder (I used /usr/home/remotemdb)

Table {table} should be the table name inside mdb file. Query all possible tables inside mdb file with command mdb-tables {unix mount point}/.mdb

There is no need for drivers, configuration or other stuff, just plain mdbtools and access to file, in this case, achieved with remote connection through ssh. In you want, you can install fuse package, to autmatically mount remote directory, but that is another question.

Hope someone this helps.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值