Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP and an Access database

Status
Not open for further replies.

MHUK

Programmer
Nov 30, 2002
139
GB
Hi,
Just a quick question. Does anyone know if PHP can be used with an Access database? I'm not sure if they are compatible because Access is a Microsoft product.

When I connect to my MySQL database I normally use a line of code as follows:
$conn = mysql_connect( "localhost", "root", "");

If it is possible to connect to an Access database what code would have to be used to establish a connection to the database?

Thanks for any help.
MHUK
 
It's very easy from Win32. Just use PHP's ODBC functions.

From a non-Win32 OS, it is not possible. Access databases require the use of the Jet database engine. Database engines differ from database servers in that database server architecture is client/server -- you only have to use some client libraries to access the data. Engine-driven databases require you to run the database engine locally -- and I have yet to find an engine for Access that will run on Linux.

If you are running on a non-Win32 OS, I recommend that you migrate the data from Access to MySQL or PostgreSQL. Any Access users can still get to the data -- just modify the Access database to link to the data using ODBC links. Want the best answers? Ask the best questions: TANSTAAFL!
 
$DBCon = new COM("ADODB.Connection");
$DBCon->Open('PROVIDER=MSDASQL;DRIVER={Microsoft Access Driver (*.mdb)};DBQ='.realpath("../path/to/database.mdb"));
register_shutdown_function("kill");

Function kill() {
@$DBCon->close();
$DBCon = "";
}

There's your connect and disconnect.

It is ESSENTIAL that you have the shutdown function. Access only allows 5 concurrent users, and PHP doesn't release the resource itself! --BB
 
Thank you for all your messages. That is very helpful. I'm using Windows 98 and it is definitly a win32 OS, although I'm not sure what the win32 refers to. What does this mean? I know Linux/Unix are non-win32 OS. If an OS is referred to as win32 does it just mean it is Windows based?

Thank you for all your help.
 
Win32 is the Mi¢ro$oft so-called API that is the core of W95, W98, NT, W2K, and XP. I say so-called API, because last time I checked, for something to be an API its callable functions had to be documented or at least published. And although Win32 is the backbone of all those OSes, not all of them support exactly the same subset of the overall call set. Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top