2

I am currently working getting a PHP script to connect to a MS access database 2007, so that the PHP script can retrrive information from it.

Does anyone know any way of accomplishing this I do believe that creating an ODBC Connection may be the way forward but I would appreciate any guidance towards this matter.

Many thanks for any help anyone is willing to give me

James

4
  • May be of interest: stackoverflow.com/questions/11338264/… Commented Oct 27, 2012 at 20:18
  • 1
    Yeah, PDO with ODBC is the way to go. Alternatively, you could fire up ADO... I don't recommend it. Commented Oct 27, 2012 at 21:24
  • thanks guys, will it matter that the PHP script is on a external server from the (.mdb) database? Commented Oct 27, 2012 at 23:48
  • The piece of code that I am looking at shows me how to connect to a mdb database but doesnt say if it can be connected from an external server does anyone have an idea ? thanks Commented Oct 29, 2012 at 3:10

1 Answer 1

3

Normally, you'd do something like this:

$dbName = $_SERVER["DOCUMENT_ROOT"] . "products\products.mdb";
if (!file_exists($dbName)) {
    die("Could not find database file.");
}
$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$dbName; Uid=; Pwd=;");

A successful connection will allow SQL commands to be executed from PHP to read or write the database. If, however, you get the error message “PDOException Could not find driver” then it’s likely that the PDO ODBC driver is not installed. Use the phpinfo() function to check your installation for references to PDO.

If an entry for PDO ODBC is not present, you will need to ensure your installation includes the PDO extension and ODBC drivers. To do so on Windows, uncomment the line extension=php_pdo_odbc.dll in php.ini, restart Apache, and then try to connect to the database again.

In your case I believe it would work if the .mdb file is on an external server, but you'd have to be able to hit it from where you're serving the page.

Not sure if this is intranet or across the public internet, but if it's public internet you might want to rework your work flow a bit, as generally making your database accessible that way is not something you'd want to do.

Source: Using an Access Database with PHP

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.