?
Solved

PDO with Access, IIS and Windows Server 2008

Posted on 2014-10-23
9
Medium Priority
?
622 Views
Last Modified: 2014-10-24
And I thought all of my woes were over after I got such fabulous help with http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28540367.html.

I'm trying to connect to an Access DB on Server 2008 running IIS with PHP installed. I've downloaded and installed the MS ACCESS database engine at: http://www.microsoft.com/en-us/download/details.aspx?id=13255.

I'm including the following code in a file called DBConnect.php on line 1 of to index.php:-

<?php
    $strDBPath = 'D:\\Media\\Database_Management\\DB\\'; 
 
    $strDBName = 'MHSchool.mdb';
    $strFullName = $strDBPath . $strDBName;

    if (!file_exists($strFullName)) {
        die("Could not find database file.");
    }
    $strCon = 
        'odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=' . $strFullName;
        //'odbc:Provider=Microsoft.ACE.OLEDB.12.0;Data Source=' . $strFullName;
        //'odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=' . $strFullName;
        //'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' . $strFullName;
    $objThumbs = new PDO($strCon);
?>

Open in new window


I've tried the 4 different connection strings above. They all produce the error:-

Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in 
C:\inetpub\wwwroot\SchoolMedia\t+include\DBConnect.php:15 Stack trace: #0 
C:\inetpub\wwwroot\SchoolMedia\t+include\DBConnect.php(15): 
PDO->__construct('Provider=Micros...') #1 C:\inetpub\wwwroot\SchoolMedia\index.php(1): 
include_once('C:\inetpub\wwwr...') #2 {main} thrown in 
C:\inetpub\wwwroot\SchoolMedia\t+include\DBConnect.php on line 15 

Open in new window


I had expected to have to enable PDO ODBC in php.ini:-

PDO on IIS
However I see that "On Windows, PDO_ODBC is built into the PHP core by default. It is linked against the Windows ODBC Driver Manager so that PHP can connect to any database cataloged as a System DSN, and is the recommended driver for connecting to Microsoft SQL Server databases." (http://php.net/manual/en/ref.pdo-odbc.php) and I'm at a loss to understand from that what I need to do. I'm trying to avoid becoming a help troll over this issue but ...
0
Comment
Question by:cescentman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 40400818
You still need to enable the 'php_pdo_odbc.dll' extension in 'php.ini' and restart IIS.  Like I showed you last time from PHP on my Windows / IIS set up.  
PDO drivers in phpinfo()Plus you quoted it wrong.  ODBC does Not equal PDO_ODBC.  From 'php.ini':
Note that ODBC support is built in, so no dll is needed for it.
0
 
LVL 82

Expert Comment

by:David Johnson, CD, MVP
ID: 40400863
you also would use relative urls from your website root rather than c:\inetpub\...
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 40400876
No, that's not true.  The Windows ODBC driver needs an absolute path on the server.  I gave @cescentman working code on his previous question so I don't know what's going on here.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 total points
ID: 40400889
Apparently I misread your statement about PDO_ODBC  but so did you.  The keywords are 'System DSN' which is not what you are doing in your code.  A 'System DSN' must be setup in the ODBC Manager in Windows.  For anything that is not a 'System DSN', you still need to enable the 'php_pdo_odbc.dll' extension in 'php.ini' and restart IIS.
0
 
LVL 1

Author Comment

by:cescentman
ID: 40401148
@Dave Baldwin

In my php.ini I have this:-

; Windows Extensions
; Note that ODBC support is built in, so no dll is needed for it.
; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)
; extension folders as well as the separate PECL DLL download (PHP 5).
; Be sure to appropriately set the extension_dir directive.

;extension=php_bz2.dll
;extension=php_curl.dll
;extension=php_dba.dll
;extension=php_dbase.dll
;extension=php_fdf.dll
extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_gmp.dll
;extension=php_ifx.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
;extension=php_mbstring.dll
;extension=php_exif.dll
;extension=php_mcrypt.dll
;extension=php_mhash.dll
;extension=php_mime_magic.dll
;extension=php_ming.dll
;extension=php_msql.dll
;extension=php_mssql.dll
extension=php_mysql.dll
extension=php_mysqli.dll
;extension=php_oci8.dll
;extension=php_openssl.dll
extension=php_pdo.dll
;extension=php_pdo_firebird.dll
;extension=php_pdo_mssql.dll
extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_oci8.dll
extension=php_pdo_odbc.dll
extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
extension=php_pgsql.dll
;extension=php_pspell.dll
;extension=php_shmop.dll
;extension=php_snmp.dll
;extension=php_soap.dll
;extension=php_sockets.dll
extension=php_sqlite.dll
;extension=php_sybase_ct.dll
;extension=php_tidy.dll
;extension=php_xmlrpc.dll
;extension=php_xsl.dll
;extension=php_zip.dll

zend_extension_ts="C:\Program Files (x86)\NuSphere\PhpED\php5\extensions\dbg-php-5.2.dll"
zend_extension_ts="C:\Program Files (x86)\NuSphere\PhpED\php5\extensions\phpexpress-php-5.2.dll"

;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;

Open in new window


So expected to find the same on the 2008 server; it's different however:-

; Windows Extensions
; Note that ODBC support is built in, so no dll is needed for it.
; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)
; extension folders as well as the separate PECL DLL download (PHP 5).
; Be sure to appropriately set the extension_dir directive.
;

; The MIBS data available in the PHP distribution must be installed. 
; See http://www.php.net/manual/en/snmp.installation.php 


;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;

Open in new window


I have tried adding: extension=php_pdo_mysql.dll at line 10 and restarting IIS but it made no difference there is still no ODBC listed in the PDO module section, FYI this is the header information from phpinfo:-

PHPInfo header
0
 
LVL 1

Author Comment

by:cescentman
ID: 40401151
@David Johnson not sure about relative URLS. If that was the case wouldn't I end up with the result:-

"Could not find database file."

... as the if statement would be true?
0
 
LVL 1

Author Comment

by:cescentman
ID: 40401152
OMG I'm getting old and stupid:-

extension=php_pdo_mysql.dll

... is the wrong extension. I'll try again :>{
0
 
LVL 1

Author Comment

by:cescentman
ID: 40401169
... and it works. It was the fact hat the extension entries were missing on the 2008 box. That coupled with the red herring of the System DSN I took the wrong turn :>{

Thanks @Dave Baldwin
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 40401233
Ok, let us know if there are any more problems.  This is what I have on 7 Windows computers here, 3 IIS, 3 Apache, and 1 nginx web servers.
PDO in phpinfo()
0

Featured Post

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question