Data source name not found and no default driver specified

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
pm4698
New php-forum User
New php-forum User
Posts: 2
Joined: Wed Jan 31, 2018 6:28 am

Wed Jan 31, 2018 7:00 am

Hello there,

PHP Version: 5.6.3
Server: Windows Server 2008 R2 with IIS 7.5
I use odbc driver to load data from an access database file.

PHP code is this:

Code: Select all

$connStr ='odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};' . 'Dbq=C:\\inetpub\\wwwroot\\dir\\dir.accdb;';

$dbh = new PDO($connStr);

$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql="my_sql_query";
$sth = $dbh->prepare($sql);
$params=array();
$sth->execute($params);
In a local computer this works but when i uploaded to the main server i get this message when trying to access site:
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified' in C:\inetpub\wwwroot\dir\index.php:424
Stack trace:
#0 C:\inetpub\wwwroot\dir\index.php(424): PDO->__construct('odbc:Driver={Mi...')
#1 {main}
thrown in C:\inetpub\wwwroot\dir\index.php on line 424

I have installed 64bit ODBC Driver 11 for SQL Server and extensions are enabled in php.ini file. I saw a few tutorials indicating that i have to open ODBC Data Source Administrator go to System DSN tab and create a System Data Source. If i have to do this, at Server to connect what should i select, because i am actually using this driver for accessing an access database file. Also in test environment i did't have to do something like this.

Any ideas?

Thank you in advance

pm4698
New php-forum User
New php-forum User
Posts: 2
Joined: Wed Jan 31, 2018 6:28 am

Wed Jan 31, 2018 11:40 pm

OK. I did the following:
1) I installed MS Visual C++ 2015 because i was missing a dll file for Microsoft Access Database engine 2016(This adds the driver missing in ODBC). 2) Installed MS Access Database engine 2016.
3) After those 2 installations i created a DSN and pointing it to my access file

When i try to run the php file i get this:

Code: Select all

PHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[HY009]:                                                                          
Invalid use of null pointer: 0 [Microsoft][ODBC Microsoft Access Driver]Invalid use of null pointer  (SQLPrepare[0] at ext\pdo_odbc\odbc_driver.c:206)' in C:\inetpub\wwwroot\dir\index.php:434
Stack trace:
#0 C:\inetpub\wwwroot\dir\index.php(434): PDO->prepare('')
#1 {main}
  thrown in C:\inetpub\wwwroot\dir\index.php on line 434 
Any ideas?

Post Reply