doufan9377 2011-10-27 22:44
浏览 56
已采纳

使用PHP连接到MS Access DB

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条回答 默认 最新

  • doujie1917 2011-10-27 23:11
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?