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

I'm using PHP to connect to an Acccess database. Any way I write my connection string, I get SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified.

I see someone else figured it was a 64 bit vs 32 bit issues, I'm wondering if I have the same. I've created my DSN and even when I don't use the DSN and give the file path I get this error. I'm on a windows 10 machine and downloaded PHP today. Could this be that the PHP not compatible with 32 bit ODBC? Thanks for any help you can provide.


$dbName = $_SERVER["DOCUMENT_ROOT"] ."\PhillyCanineSportsClub\Database2.mdb";
//$dbName = 'pcsc';

$connStr = 'odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=' . $dbName;
$dbh = new PDO($connStr);

catch (PDOException $e) {
  echo $e->getMessage();
  echo $db;
Ted GAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Trying to get Dbq=... to work inside a Webserver environment.

Best to use an absolute path, starting with a drive letter.

The path you have will likely be treated as a path relative to the current working directory at the time... which will likely be pinned to somewhere in your Webserver runtime directory... so will never point to your database...

Test using an absolute path + see if that clears the error you're seeing.
Ted GAuthor Commented:
Thanks, but it doesn't make a difference when I write
$dbName = "C:\inetpub\wwwroot\PhillyCanineSportsClub\Database2.mdb";
Ted GAuthor Commented:
If I write echo 8 * PHP_INT_SIZE;, I get 64. Should that be 32? Someone else checked this value and it was 32, and someone said 32 was correct. Do I have the wrong version of PHP?
Maximize Customer Retention with Superior Service

The IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more to help build customer satisfaction and retention.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Run your php file on the command line (which absolute path) + provide the exact error (cut + paste) in a comment.

Also post the output of something like...

dir C:\inetpub\wwwroot\PhillyCanineSportsClub\Database2.mdb"

Open in new window

Or whatever equivalent command line file lister you use.
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
https://stackoverflow.com/questions/27865340/php-int-size-returns-4-but-my-operating-system-is-64-bit provides details.

And yes, looks like somehow you've (maybe) installed a 32 bit version of PHP.

You'll have to do some deep research to see if this will actually work.

Likely best to install a 64 bit version.
Ted GAuthor Commented:
not sure how to run the php file from the command line, doesn't seem to work.
And do you mean I downloaded a 64 bit instead of 32? My PHP_INT_Size is 8. 8x8=64
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
1) not sure how to run the php file from the command line, doesn't seem to work.

php -f path-to-your-php-file

which will look something like this...

 # php -f /david-favor/wptools/hello-world.php
Sun Feb 10 07:53:30 2019 (585735): Message Cached script '/david-favor/wptools/hello-world.php'
  <title>PHP Test</title>
 <p>Hello World</p>

2) And do you mean I downloaded a 64 bit instead of 32? My PHP_INT_Size is 8. 8x8=64

Julian HansenCommented:
Your code works perfectly here but you need to use double \\ to escape the backslashes.

If you change to
$dbName = "C:\\inetpub\\wwwroot\\PhillyCanineSportsClub\\Database2.mdb"; 

Open in new window

Ted GAuthor Commented:
Thanks Julian, but that didn't make a difference either. Here's the first few lines of the output from running the php file from the command prompt, as well as the dir for the db. I moved everything to C: so I didn't have to worry about slashes, but still same thing.

It is 64 bit PHP, is that not compatible with 32 bit Access? My OS is 64 bit. Is my Access db wrong?

C:\>php -f phpinfo.php
PCSC64<p>Hello World</p>SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specifiedphpinfo()
PHP Version => 7.2.7

System => Windows NT PCSSC 10.0 build 17134 (Windows 10) AMD64
Build Date => Jun 19 2018 23:09:10
Compiler => MSVC15 (Visual C++ 2017)
Architecture => x64
Configure Command => cscript /nologo configure.js  "--enable-snapshot-build" "--enable-debug-pack" "--disable-zts" "--with-pdo-oci=c:\php-snap-build\deps_aux\oracle\x64\instantclient_12_1\sdk,shared" "--with-oci8-12c=c:\php-snap-build\deps_aux\oracle\x64\instantclient_12_1\sdk,shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet=shared" "--without-analyzer" "--with-pgo"
Server API => Command Line Interface
Virtual Directory Support => disabled

C:\>dir Database2.mdb
 Volume in drive C is Windows
 Volume Serial Number is E65C-7BF6

 Directory of C:\

02/09/2019  02:38 PM           221,184 Database2.mdb
               1 File(s)        221,184 bytes
               0 Dir(s)  107,860,852,736 bytes free
Ted GAuthor Commented:
I found this...I'm guessing I have to run 32 bit PHP to be compatible with Access, even though my OS is 64.

Kathy S - Microsoft Support
Replied on January 22, 2010
Hi smantha11,

Currently Microsoft does not have any 64 bit ODBC drivers available for the Office products.
However, as long as the application that you want to connect to is 32 bit, you can use the 32 bit ODBC drivers to create the DSN.
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
You have 2x items to solve.

1) You database path, based on dir above should be...

$dbName = "C:\\Database2.mdb";

Open in new window

2) The above phpinfo.php error suggests no database driver is being referenced in your PHP config file.

Normally you'll have a directory like /etc/php/7.2/mods-available (or something similar) which should contain many .so objects or in the case of Windows, maybe .dll objects.

Then in /etc/php/7.2/fpm/php-fpm.conf you should see an include of all modules from mods-available, likely through symlinks.

Trying to debug this on a Linux install takes a few seconds, because inotifywait exists to track exactly what files are read during PHP restarts.

On Windows, there's nothing like this.

I'd suggest you use the https://github.com/thekid/inotify-win tool which approximates inotifywait, so you can determine order in which all your PHP config files are being loaded.

Likely something simple to fix... and finding the simple fix... may take some time.
Ted GAuthor Commented:
I also wonder why the odbc administrator says 64 bit at the top, but at the bottom says it's 32 bit???
Ted GAuthor Commented:
Changing the database path doesn't make any difference. And in the php.ini file it says this. The last item is the odbc, I added that yesterday. Someone else had suggested that.

Julian HansenCommented:
I connect to access all the time from PHP - no problems.

Only difference is I created an ODBC DSN for it and connect with that rather than directly.

I am assuming you have tried this.

dsn => 32 bit Driver do Microsoft Access (*.mdb)
Ted GAuthor Commented:
Yes, I have. Do you run 32 or 64 bit PHP? Thanks.
Ted GAuthor Commented:
I removed the version of php I was using by editing the hostconfig file and then downloaded an x86 version. I still had to edit the php.ini file adding the odbc...extension=php_pdo_odbc.dll at the very bottom of the file, and then it worked. Thanks for the efforts and hope I can help someone else with this issue. Also, I tried installing without using the MS Web Platform Installer and got other errors, so I recommend using the Web Platform Installer.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.