I use odbc driver to load data from an MS Access database file.
PHP code:
$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:
Error:
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
System:
- PHP Version: 5.6.3
- Server: Windows Server 2008 R2 with IIS 7.5
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 didn't have to do something like this.
Any ideas?
Thank you in advance
EDIT 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:
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??