0

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

1 Answer 1

2

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.

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

2 Comments

.bws is not really a disk image. Some idiot renamed the extension. But I need to use it as is because it is needed as it is in another program.
symlink it if you really need to rename without renaming (man ln)

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.