Solved

Querying Remote MS Access DB on Linux via PHP

Posted on 2011-03-02
10
442 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

809 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