PHP failed to connect to Microsoft Access Database

2019-09-09 15:02发布

I am trying to connect to a Microsoft Access Database using PHP PDO, but got this error message:

SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager]Data source name not found, and no default driver specified

The error happens at this line:

 $dbh = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb,*.accdb)};Dbq=C:\\wamp\\www\\phprestsql\\UTILITY.accdb");

I do not have an user name setup for the database, I also tried

$dbh = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb,*.accdb)};Dbq=C:\\wamp\\www\\phprestsql\\UTILITY.accdb;User=Admin");

and the problem still remains

What could be the problem? I checked the path for the Access Database file and it is correct. I am using the WAMP for the PHP.

The system is Windows 7 Home Premium. Do I need to install some ODBC driver?

Edit: I downloaded the ACE according to HansUp's suggestion, but still has the same problem. I have also tried to convert my file to .mdb, but still has the same problem. In the PHP code I verified the ,mdb file does exist. So it must be some kind of environment issue.

Update Forgot to mention that I was running Virtual Box on Mac. Perhaps that was the problem. Got really frustrated, then moved on to an old Windows Vista 32 bit machine and setup the environment using all 32 bit tools. It worked in the first run. Thanks Ray

0条回答
登录 后发表回答