PDO with Access, IIS and Windows Server 2008

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 ...
LVL 1
cescentmanAsked:
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.

Dave BaldwinFixer of ProblemsCommented:
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
David Johnson, CD, MVPOwnerCommented:
you also would use relative urls from your website root rather than c:\inetpub\...
0
Dave BaldwinFixer of ProblemsCommented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Dave BaldwinFixer of ProblemsCommented:
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

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
cescentmanAuthor Commented:
@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
cescentmanAuthor Commented:
@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
cescentmanAuthor Commented:
OMG I'm getting old and stupid:-

extension=php_pdo_mysql.dll

... is the wrong extension. I'll try again :>{
0
cescentmanAuthor Commented:
... 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
Dave BaldwinFixer of ProblemsCommented:
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
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
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.