Solved

PDO with Access, IIS and Windows Server 2008

Posted on 2014-10-23
9
528 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
  • 4
  • 4
9 Comments
 
LVL 83

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 79

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 83

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 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 83

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

810 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