从Linux上的php连接到MS Access远程.mdb文件 [英] Connect to MS Access remote .mdb file from php on linux

查看:179
本文介绍了从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.

  1. 我们在运行WindowsXP的服务器上有一个file.mdb,因此我需要将其添加到ODBC数据源中.我以简单的步骤完成此操作,最后以"System DSN"结束,该操作允许访问该.mdb文件
  2. 我需要在同一台服务器上安装某种ODBC桥,这将允许我创建到该服务器的远程连接,使该桥连接到服务器ODBC DSN,并查询我的东西(找不到任何免费的ODBC桥)
  3. 在UNIX(FreeBSD)计算机上,我需要安装unixODBC和php5-odbc软件包,以启用到ODBC(已安装)的连接
  4. 要连接到远程ODBC并使用MS Access db驱动程序,我需要在UNIX计算机内部的.so文件中有一个用于unixODBC的驱动程序(找不到任何免费的MS Access驱动程序)
  5. 使用PHP odbc_connect(DSN,user,password)连接到该服务器,在DSN中,我需要提供一些连接信息和驱动程序,我需要使用它们(MS Access驱动程序).

纠正我,如果我弄错了,请给我更多建议,以了解如何建立这种联系.

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

推荐答案

最后,我找到了解决方法.

Finally, I found solution.

  1. 在Win服务器上设置 FreeSSHd ,配置连接帐户并将目录设置为一个,您需要
  2. 在UNIX服务器 sshfs
  3. 上设置
  4. 使用.mdb文件安装Win服务器目录

  1. Set up on Win server FreeSSHd, configure connection account and set directory to one, you need
  2. Set up on unix server sshfs
  3. Mount Win server directory with .mdb files

sshfs {user} @:/{unix安装点} -o解决方法=重命名,allow_other

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

在Unix服务器上设置 mdbtools

Set up on unix server mdbtools

因此,我使用了文档中的默认PHP代码并编写了以下PHP脚本:

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);

  • /usr/bin/mdb-export 的路径应该是您的mdb-export文件的路径(如果找不到,请使用find / -name "mdb-export").
  • 安装点 {unix安装点} 应该是一个空文件夹(我使用的是/usr/home/remotemdb )
  • {table} 应该是mdb文件中的表名.使用命令mdb-tables {unix mount point}/<file>.mdb
  • 查询mdb文件中的所有可能的表

    • 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}/<file>.mdb
    • 在这种情况下,通过ssh进行远程连接就不需要驱动程序,配置或其他东西,仅需要简单的mdbtools和文件访问即可.您可以根据需要安装保险丝包,以自动方式安装远程目录,但这是另一个问题.

      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.

      希望有帮助的人.

      这篇关于从Linux上的php连接到MS Access远程.mdb文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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