Getting Microsoft PHP PDO for SQL Server working

17,015

Solution 1

I noticed a footnote in the Microsoft documentation saying PHP >= 5.3.6 was required for Version 3 of the PDS drivers. As I am running 5.3.1, and I can't move from it, the older ones work fine, despite being deprecated.

Solution 2

I suffered from the same problem for 2 days and finally find a solution.

1.Install PHP: 5.3 is recommended. (All .dll files related to 5.4 won't work!) http://www.php.net/downloads.php
2.Download Microsoft Drivers: Do not use 3.0, only 2.0 dll files will work! http://www.microsoft.com/en-us/download/details.aspx?id=20098
3.Copy drivers to "ext" folder (default in php 5.3, and can be changed in php.ini)
4.Update php.ini (Use text editor or PHP Manager) e.g. extension=php_pdo_sqlsrv_53_nts_vc9.dll (vc6 won't work!)
5.Restart IIS
6.Check PDO support in phpinfo(): "sqlsrv" should be in "enable" list.
7.Connection String: sqlsrv:Server=19x.1xx.1xx.1xx;Database=lab

Here is my environment: Windows 7 + IIS 7 + SQL Server 2008 R2, PHP 5.3

Believing in latest version from MS is my fault.

Solution 3

The reason why it is saying no value for the PDO Drivers is simply because it has not loaded any drivers. The php_PDO.dll is just a library that the additional PDO drivers run off, it is not a driver. The issue remains with the php_pdo_sqlsrv_53_nts.dll that you are trying to load.

The phpinfo() that you have supplied is irrelevant as we know that the dll is not being loaded. We need to get to the bottom of why the php_pdo_sqlsrv_53_nts.dll is not being loaded.

Few basic steps before we go further:

  1. Is the file name definitely correct?
  2. Is the .dll definitely in the right place?
  3. Is the file a thread-safe or non-thread-safe version? This is very important!
  4. Did the file download correctly? It may be corrupted

Solution 4

A little help in the subject:

If you happen to have an existing SQL Server 2012 installation with Native client 11, you can't install Native client 10 over it, which is required for Offical PHP Driver. One solution is to remove NC 11 and dependent components, then install NC 10 and NC 11 in this order, but that's not a possibility for actively used servers.

A workaround for this is to use an unoffical release, made for NC 11 , e.g.: http://robsphp.blogspot.hu/2012/06/unofficial-microsoft-sql-server-driver.html

Share:
17,015
Sam
Author by

Sam

Updated on June 27, 2022

Comments

  • Sam
    Sam almost 2 years

    I am trying to get the PHP PDO driver for SQL server working. I obtained the file from Microsoft.

    I am using PHP 5.3. I copied php_pdo_sqlsrv_53_nts.dll to my PHP extension directory and modified PHP.INI. The error log shows

    [31-Mar-2012 20:11:38] PHP Warning: PHP Startup: Unable to load dynamic library 'c:\php\ext\php_pdo_sqlsrv_53_nts.dll' - The specified module could not be found.
    in Unknown on line 0

    The file does exist. I checked it with DEPENDS.EXE and was missing MSVCR100.DLL and MSVCP100.DLL and I ran all VC++ runtime packs and got the DLLs. DEPENDS reports two missing dependencies, LINKINFO.DLL and IESHIMS.DLL. Not sure what either of them are.

    I don't have a PHP_PDO.DLL; from what I read it's indicated that PHP 5.3+ builds php_pdo.dll into PHP.phpinfo has a section "PDO" which has "PDO drivers" = "no value". I'm not sure if this value is what it should be.

    I tried restarting the web server (as opposed to not just restarting the service) as suggested in another post but that didn't fix it.

    Running on Windows Server 2008 with IIS and on x64.

  • Sam
    Sam about 12 years
    Hi Ben. 1. Yes file is correctly named, 2. It is in the /ext/ directory with other extensions, 3. it is linked with PHP5.DLL and phpinfo() says it is not thread safe, 4. File was part of an archive which would have been checked at installation.
  • Ben Carey
    Ben Carey about 12 years
    The phpinfo() is not seeing the .dll so how can it know whether the file is thread safe or not. If you are using IIS, your PHP installation will be non-thread safe, this is what you will be reading. What you need to make sure is that the php_pdo_sqlsrv_53_nts.dll library is non-thread safe so that it can run with your PHP installation. It looks like it is because of the 'nts' in the name. Can you explain what you mean by 'it is linked with PHP5.DLL'?
  • Sam
    Sam about 12 years
    if it was the thread safe version it would be linked when compiled with PHP5TS.DLL from what I've read. The filename is php_pdo_sqlsrv53_nts.dll 100%, I even copied the name of the file and pasted it into php.ini to make sure I wasn't bleary eyed and missing something.
  • Ben Carey
    Ben Carey about 12 years
    @Sam It is definitely non-thread safe, so we can rule this out. What I need to know is what you mean by 'linked with PHP4.dll'? This should be irrelevant! All you should need to do is browse to the file in the php.ini. Could you copy and paste the extensions part of the php.ini to your question so I can double check it?
  • Sam
    Sam about 12 years
    thanks for your help. I ended up solving it by using the older version of the drivers. I noticed an endnote in MSFT documentation saying that PDO library v3 required PHP >= 5.3.6. I'm at 5.3.1 and can't move due to an incompatibility with some other software.
  • holm50
    holm50 over 7 years
    Thank you! I was trying to load a thread safe dll when my server had thread safety disabled. My Phpinfo() stated "Thread Safety: disabled" so I added the non-thread-safe version of php_pdo_sqlsrv_56_nts.dll to my extensionList and it worked.
  • Walt Sorensen
    Walt Sorensen over 7 years
    php_sqlsrv is not the same as php_pdo_sqlsrv