Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 730
  • Last Modified:

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 ...
0
cescentman
Asked:
cescentman
  • 4
  • 4
1 Solution
 
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
Technology Partners: 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!

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now