Link to home
Start Free TrialLog in
Avatar of cescentman
cescentmanFlag for United Kingdom of Great Britain and Northern Ireland

asked on

PDO with Access, IIS and Windows Server 2008

And I thought all of my woes were over after I got such fabulous help with https://www.experts-exchange.com/questions/28540367/PDO-with-Access.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:-

User generated image
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 ...
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

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.  
User generated imagePlus 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.
you also would use relative urls from your website root rather than c:\inetpub\...
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.
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cescentman

ASKER

@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:-

User generated image
@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?
OMG I'm getting old and stupid:-

extension=php_pdo_mysql.dll

... is the wrong extension. I'll try again :>{
... 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
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.
User generated image