Helpful Information
 
 
Category: Database Management
access MS/ACCESS via ODBC from Linux PHP

We are trying to enable access to a Microsoft Access database on a windows 2000 machine from a Linux PHP client. Thought we had found freeware called MDBTools that had an Linux ODBC driver for MS\Access to accomplish this but have not been able to find the appropriate file in their download. Is anyone doing this and having any success? Are there other options available?

Thanks in advance for your help!

:confused:

You do have several options
One is an odbcless connection to the box (keep in mind though all your permissions need to be setup for any connection)

if (!$conn = new COM("ADODB.Connection"))
exit("Unable to create an ADODB connection<br>");
$strConn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("$data");
$conn->open([FILE PATH AND FILENAME HERE]);

The other option is to install php on the win2000 box and configure it for IIS

colmtourque - I don't think COM is available on a non-Windows PHP install.

Better to check out www.unixodbc.com. This should provide you with an ODBC client which can connect to an ODBC data source on your Windows 2000 server.

Nope, you need ODBC socket server http://sourceforge.net/projects/odbcsock/ or dbtcp http://www.fastflow.it/dbftp/ both seem to be actively developed.
Please report on your experience!

Here are more details on the problem:

We downloaded LINUX ODBC drivers for Access from http://mdbtools.sourceforge.net/. We also installed unixodbc. In the ODBC Manager on Linux I could define the DSN for a postgres database and it worked correctly. However when I went to setup the dsn for the mdbtool ODBC driver there was no associated setup file. So I guess that points me towards either manually creating the .ini entries or try a dsn-less connection.

If I try a dsn-less as suggested connection can I specify the direct path for the driver rather than what appears to be a dsn name. For example, can I specify this:
$strConn = "DRIVER={/usr/local/lib/libmdbsql.so.0}; DBQ=" . realpath

instead of this:
$strConn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath

Unfortunately IIS is not an option so I really have to try to make this work.....

Just saw the socket recommendation. Can you help my understand why I have to go that route????

I very much appreciate the feedback given thus far!

coo thanks for the information on Windows and PHP (I'm hoping to do the same thing here and that is a good bit of information)

You can find an excellent article about ODBC socket server at www.phpbuilder.com dbtcp has a user forum on his site.

Below you will find information on how I was successful with accessing a Microsoft access database on a Linux server from php using the MDBTools ODBC driver. I very much appreciate the comments I got thru this forum. I still plan on investigating the ODBC Socket option soon.....

I am wondering if anyone has any tips regarding the ability to access the Access database if it was on a windows server, still using the MDBTools ODBC driver. I have seen references to using Samba client and the associated mount utility which I suppose would allow me to 'map' a remote windows drive to Linux, as well as references to Konqueror which may be able to do something similar. If anyone has any tips I would appreciate it......

So.... here is how I was able to make the MDBTools ODBC driver work. Once we got the software installed (and we also already had the unixodbc software installed) I found that I also needed to manually update ODBC.INI and the ODBCINST.INI since there was no setup file for the driver. Here are my snippets of code to
help any others who are interested:

ODBC.INI:
...
[Microsoft Access]
Description = Microsoft Access
Driver = MDBToolsODBC
Database = /var/www/sites/base1/HARDWARE.MDB
Servername = localhost
UserName =
Password =
Port = 5432
...

ODBCINST.INI:
...
[MDBToolsODBC]
Description = MDB Tools ODBC drivers
Driver = /usr/local/lib/libmdbodbc.so.0
Setup =
FileUsage = 1
CPTimeout =
CPReuse =
...

myappl.PHP:
<?php
/* connect to microsoft access on dots machine */
$myDB = odbc_connect("Microsoft Access","","");
$query = "select mfg from tblModems";
$result = odbc_exec($myDB, $query);
$report = odbc_fetch_row($result);
echo odbc_result($result, 1);
odbc_close($myDB);

GREAT TRICK!!

Hi, I'm trying to reproduce your setup on my Mandrake 8.2, I've installed unixODBC and it works (tested on MySQL), I've installed MDBTools from RPM, but I can't find the ODBC driver!
Could you please tell me how did you install it?
Thanks in advance for your help!

Well, in order to get the ODBC driver you have to compile from source, but I'm running in other problems with the driver ... arghh.
Thanks anyway

I know this is an ancient thread, however I found it on google and I'm having the same trouble. I have to connect to an ODBC running on Windows from a Mandrake 9.1 linux box. They are not on the same network even.

I've installed mdbtools, and mdbtools-odbc however the other file mentioned... unixODBC-generic-2.2.5-1.i386.rpm.... refuses to install due to a failed dependency of odbc is needed by unixODBC-generic-2.2.5-1. I can't find where that is! :p

Beyond that, I'll probably still be lost. Right now the error Im getting from the PHP is:

Fatal error: Call to undefined function: odbc_connect() in /var/www/html/support/rnw_reports.php on line 6

Here is my PHP:

<?
# connect to a DSN "mydb" with a user and password "marin"
$server = "not_for_your_eyes";
$db = "not_for_your_eyes";
$pass = "not_for_your_eyes";
$connect = odbc_connect("$server", "$db", "$pass");
# query the users table for name and surname
$query = "SELECT name, surname FROM users";
# perform the query
$result = odbc_exec($connect, $query);
# fetch the data from the database
while(odbc_fetch_row($result)){
$name = odbc_result($result, 1);
$surname = odbc_result($result, 2);
print("$name $surname\n");
}
# close the connection
odbc_close($connect);
?>

Which is probably normal if it doesn't find odbc... Can anyone walk me through this, step by step, as detailed as possible so hopefully I can get this working?

Any help is greatly apreciated.

Any Help?

I don't think your php has odbc support, check with the classic <?php phpinfo() ?> page.

is connecting to ACCESS via ODBC the same as connecting to MSSQL server?

I need to connect to MSSQL via ODBC...

Well I *think* I've installed all the nessisary software...
The box is on a local network, so I can't link you to the phpinfo() but here is it's output. Please let me know if you see anything I'm missing....

http://mail.flippydisk.com/phpinfo.html

Yes, you don't have ODBC support enabled.
For example on Madrake you would have to install unixODBC and this (http://rpms.mandrakeclub.com/rpms/mandrake-devel/contrib/i586/php-unixODBC-4.3.4-1mdk.i586.html) rpm.
Great!!! Look at this howto (http://bryanmills.net:8086/archives/000099.html) to use Access with Linux.

Ok, so treat me like a smal child here so I can get it right.

How do I enable it?

Look at the howto I suggested, but after installing unixODBC and before MDBTools install support for ODBC in php, I provided a link to an rpm for Mandrake, but there are other available for various distros.
After installation of unixODBC and php module, check phpinfo for anything with ODBC in it.

ah ha! Sorry, I replied before you edited your last post :p I'll check that out and see what comes of it. Thanks a bunch!










privacy (GDPR)