Solved

Querying Remote MS Access DB on Linux via PHP

Posted on 2011-03-02
10
413 Views
Last Modified: 2013-09-05
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

0
Comment
Question by:mtaylor584
  • 5
  • 3
10 Comments
 
LVL 3

Expert Comment

by:wwwdeveloper2
ID: 35023545
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.
0
 
LVL 3

Expert Comment

by:wwwdeveloper2
ID: 35023574
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
0
 

Author Comment

by:mtaylor584
ID: 35023713
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.
0
 

Author Comment

by:mtaylor584
ID: 35023724
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
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 3

Expert Comment

by:wwwdeveloper2
ID: 35023753
Ok, well that is all I had.  Maybe somebody will be able to help.

Good luck
0
 

Author Comment

by:mtaylor584
ID: 35030122
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.
0
 

Author Comment

by:mtaylor584
ID: 35030356
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.
0
 
LVL 50

Accepted Solution

by:
Steve Bink earned 500 total points
ID: 35043264
You could create a local web service that queries the Access file for you.

Access was never really meant to serve in the capacity you want.  The best option would be to migrate it to a real database service, a-la MSSQL or MySQL.
0
 

Author Closing Comment

by:mtaylor584
ID: 39468873
Unfortunately the problem was never resolved. Creating a web service was the best suggestion thus far.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
This article discusses four methods for overlaying images in a container on a web page
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now