Link to home
Start Free TrialLog in
Avatar of mtaylor584
mtaylor584

asked on

Querying Remote MS Access DB on Linux via PHP

I have an MS Access database stored internally on our network in an .mdb file. I want to connect to and query this database via PHP from a remote location (internet).

Here is one way I've come up with to get the mdb file onto the internet: I am using GoodSync to sync the .mdb file to our external web server (linux) twice a day. This may give us downtime during syncs. I could live with this if there is not a better way. But the main problem with this is that because the server is linux so ADODB does not work with access files under linux.

While under windows I used this to successfully connect to the MDB file, but it was stored on the local machine and used a driver to interface with it:
  define("MDB_TAPIT_SOURCE",						"\\\\techsprt\\tapitw32\\DATA\MAIN\\Tapitdb.mdb");
  define("MDB_DATA_SOURCE",							"Driver={Microsoft Access Driver (*.mdb)};Dbq=" . MDB_TAPIT_SOURCE);

odbc_connect(MDB_DATA_SOURCE, "","");  // This called for the connection

Open in new window

Avatar of wwwdeveloper2
wwwdeveloper2

A couple of initial thoughts here:

Could you setup a shared directory on the remote computer on your network and store the access file in it and then map a network drive from the linux machine to the shared directory?  This should allow the linux server to access it via a drive.  That might be able to eliminate the syncing you are doing right now.

I haven't used ADOdb class library for PHP, but it is supposed to be able to connect to access databases.  Here is an article describing the install and information on how to use it:

http://www.databasejournal.com/features/php/article.php/2222651/An-introduction-to-the-ADOdb-class-library-for-PHP.htm


Here is some example php code on how to connect to the access database using ADOdb and a drive path:

http://code.activestate.com/recipes/163447-microsoft-access-database-connectivity-dsn-less/

Good luck, I hope this helps.  If you have any other thoughts or questions, just let me know.
Sorry, I pasted the wrong url into the example code.

Connecting to access via the ADOdb class should look like this:

$db =& ADONewConnection('access');
      $dsn = "Driver={Microsoft Access Driver (*.mdb)};Dbq=d:\\northwind.mdb;Uid=Admin;Pwd=;";
      $db->Connect($dsn);


Here is a manual for it with code examples:

http://phplens.com/adodb/code.initialization.html#access
Avatar of mtaylor584

ASKER

Hi there!

I suppose I didn't clarify this, but the linux server is not on our domain, it is actually hosted by rackspace so it's outside of our network completely. Without a VPN I am not sure you can map a drive on a remote computer (in this case a linux box).

That would have likely solved the issue otherwise. Let me know your thoughts.
And as I mentioned before, I don't believe ADOdb for MS Access Databases works on Linux as you'll see here under "Databases Supported"...I could be wrong:

http://phplens.com/lens/adodb/docs-adodb.htm
Ok, well that is all I had.  Maybe somebody will be able to help.

Good luck
Thanks for trying wwwdeveloper2.

Anybody have any suggestions? Do I need to install drivers on the linux box to be able to query the .mdb?

I have spent many hours on what seems like a very simple issue. Connecting to a Microsoft Access DB via PHP on a Linux webserver sounds like a very common scenario.
The best method to do this would be to somehow 'host' the .mdb file that is currently being written to on the Windows machine in our network. This would allow us to query the database in realtime. I am currently able to interface with it via PHP on our internal network via a UNC path (//server/path/to/file.mdb), but this does not allow me to query it outside of our network.
ASKER CERTIFIED SOLUTION
Avatar of Steve Bink
Steve Bink
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Unfortunately the problem was never resolved. Creating a web service was the best suggestion thus far.