LAMP(PHP)使用MDBTools驱动程序通过ODBC访问Access数据库 [英] LAMP (PHP) accessing Access Database with ODBC with MDBTools Driver

查看:161
本文介绍了LAMP(PHP)使用MDBTools驱动程序通过ODBC访问Access数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我在Ubuntu和PHP上使用unixODBC驱动程序对SQL的支持是否有限?我已经在Ubuntu 11.10上设置了一个基本的灯泡服务器,并且正在尝试查询Access数据库.我已经安装了php5-odbc和MDB工具.这是一些示例代码:

<?php

$conn = odbc_connect('logindb','','');

if (!$conn) {
   echo "failed";
}

$sql = "SELECT * FROM class";
//$sql = "SELECT class.desc, event_classes.event_class_id FROM class inner join
//event_classes on class.class_id = event_classes.class_id";

$rs = odbc_exec($conn, $sql);

while ($d = odbc_fetch_array($rs)) {
    var_dump($d);
}

?>

第一个查询(简单选择)效果很好.但是,当尝试执行联接(第二条注释查询)时,我收到0条记录.我能够在Access中的SQL编辑器中成功运行SQL,所以我知道我的SQL是正确的,并且联接在此正常工作.有没有人有这方面的经验?我知道Linux并非与专有的Microsoft产品兼容,但是不幸的是我必须在Ubuntu上读取Access数据库.任何帮助,我们将不胜感激.

自2004年以来,sourceforge上的mdbtools尚未更新.它对SQL的支持从未如此出色,它是只读的,而且我从在DB1 :: ODBC的Perl下尝试使用它的经验知道,很多测试都失败了.我认为您会很难过.

还有其他更可靠的方法可以从Linux访问MS Access数据库,但据我所知,它们都是商业用途.要从Linux访问MS Access数据库,我了解以下内容:

Easysoft具有ODBC-ODBC桥(可用于使用MS Access ODBC驱动程序访问Windows计算机上的MS Access DB),但是它需要在Windows计算机上安装服务. Easysoft还具有MS Access ODBC驱动程序,只要可以从Linux上看到它,就可以使用该驱动程序直接访问mdb/accdb文件.

Openlink还有其他商业ODBC桥.

Can anyone tell me if there is limited SQL support using unixODBC drivers on Ubuntu with PHP? I've setup a basic lamp server on Ubuntu 11.10, and I'm trying to query an Access database. I've installed php5-odbc and MDB Tools. Here is some sample code:

<?php

$conn = odbc_connect('logindb','','');

if (!$conn) {
   echo "failed";
}

$sql = "SELECT * FROM class";
//$sql = "SELECT class.desc, event_classes.event_class_id FROM class inner join
//event_classes on class.class_id = event_classes.class_id";

$rs = odbc_exec($conn, $sql);

while ($d = odbc_fetch_array($rs)) {
    var_dump($d);
}

?>

The first query, the simple select, works just fine. However, when trying to perform a join (second commented query), I receive 0 records. I was able to run the SQL successfully in the SQL editor within Access, so I know my SQL is correct and the join is working there. Has anyone had any experience with this? I know Linux wasn't made to be compatible with proprietary Microsoft products, but unfortunately I have to make reading an Access database on Ubuntu work. Any help is greatly appreciated.

解决方案

mdbtools on sourceforge has not been updated since 2004. I see someone has put it on github and seems to have made a few small changes. The SQL support in it was never that good, it was read only and I know from experience trying it under Perl with DBD::ODBC a lot of the tests failed. I think you are going to have a hard time with it.

There are other more reliable ways to access a MS Access database from Linux but they are all to my knowledge commercial. To access a MS Access database from Linux I know of the following:

Easysoft have an ODBC-ODBC Bridge (which can be used to access a MS Access DB on a windows machine using the MS Access ODBC Driver) but it requires installing a service on the Windows machine. Easysoft also have a MS Access ODBC driver which can be used for direct access to the mdb/accdb file so long as it is visible from Linux.

There are other commercial ODBC bridges from Openlink.

这篇关于LAMP(PHP)使用MDBTools驱动程序通过ODBC访问Access数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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