Sinan
Sinan

Reputation: 5980

Connecting to MS Access DB with PHP

I need to access a MS Access database with PHP.

The MSAccess file's name can change so I am trying to use DSN'less connection string shown on PHP.net.

$mdbFilename='test.mdb';
$user = '';
$password = '';
$connection = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$mdbFilename", $user, $password);

I am getting error;

Warning: odbc_connect(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Could not find file '(unknown)'., SQL state S1000 in SQLConnect in ...

I need some help connecting to that file.

(Extra question what to do if the file extension is not ".mdb" It's something like ".bws" )

Thanks

Upvotes: 0

Views: 2005

Answers (1)

Sinthia V
Sinthia V

Reputation: 2093

I believe you need the full path, not just the file name in the dbq parameter. everything else looks ok. .mdb is the standard extension for access database files. .bws is a disk image file. You may need to extract the file with something like Daemon Tools before you can use it.

The syntax for a symlink in Windows Vista or 7 is

MKLINK [[/D] | [/H] | [/J]] Link Target

    /D      Creates a directory symbolic link.  Default is a file
            symbolic link.
    /H      Creates a hard link instead of a symbolic link.
    /J      Creates a Directory Junction.
    Link    specifies the new symbolic link name.
    Target  specifies the path (relative or absolute) that the new link
            refers to.

It won't work on a network share or from another OS, but a hard link (/H) will allow you to make a target for the ODBC driver that it can't distinguish from the real thing.

Upvotes: 2

Related Questions