0
votes

I have an access database which I would like to CRUD with PDO. When My database is stored on C:\\wamp\\www\\test.accdb I can connect. However, the database I am interested in is stored on our office server, at \\server1\abc\123\test.accdb . \server1 is mapped to drive z:\ on my computer.

My code looks like this (verbatim)

<?php
//attempt 1
$file = "\\server1\\abc\\123\\test.accdb";
$dbh = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb , *.accdb)};Dbq=$file");

//attempt 2    
$file = "Z:\\abc\123\\test.accdb";
$dbh = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb , *.accdb)};Dbq=$file");
?>

both of these give me error:

SQLSTATE[HY024] SQLDriverConnect: -1023 [Microsoft][ODBC Microsoft Access Driver] '(unknown)' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.

I am indeed connected to the server. Does anyone here have some wisdom to share?

1
What user is the PHP process running under? What user account has the drive mapped? Drive mappings are done by user account so if you login as administrator and map the drive, but the PHP process is run under IIS or Apache from WAMP as Network Service or a dedicated user account, it won't have the mapping. For the UNC path, try using $file = "\\\\server1\\abc\\123\\test.accdb";dlp
thanks for the input. "\\\\server1\abc\\123\\test.accdb" did not work. Same error results. Also, I suspected those complications would exist with network mapped drive name. I would much prefer to use "\\server1 ..... accdb"GRY
Last thing to try: $file = "\\\\server1\\abc\\123\\test.accdb"; $dbh = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb , *.accdb)};Dbq=$file;Uid=Admin");dlp
No, the user name is unrelated. Thank you for the advice though.GRY
Are you running the PHP code from the Windows command line, or is it being invoked via a web server (IIS, apache, ...)?Gord Thompson

1 Answers

0
votes

As a diagnostic check, try using the same mechanism you've been using to invoke your PDO script to invoke the following script:

<?php
$file = "\\\\server1\\abc\\123\\test.accdb";
if (is_file($file)) {
    echo "File exists.\r\n";
}
else {
    echo "File does not exist.\r\n";
}

That will test whether the account under which the script is running is allowed to access the network and "see" the file on the remote server. If it fails, then check the Windows rights for that account.

As a further test, you could try running that same script from the Windows command line using your regular user account (which presumably does have sufficient rights to access the network).