Getting Microsoft PHP PDO for SQL Server working
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:
- Is the file name definitely correct?
- Is the
.dll
definitely in the right place? - Is the file a
thread-safe
ornon-thread-safe
version? This is very important! - 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
Sam
Updated on June 27, 2022Comments
-
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 modifiedPHP.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 0The file does exist. I checked it with DEPENDS.EXE and was missing
MSVCR100.DLL
andMSVCP100.DLL
and I ran all VC++ runtime packs and got the DLLs. DEPENDS reports two missing dependencies,LINKINFO.DLL
andIESHIMS.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+ buildsphp_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 about 12 yearsHi 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 about 12 yearsThe
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 thephp_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 about 12 yearsif 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 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 about 12 yearsthanks 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 over 7 yearsThank 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 over 7 yearsphp_sqlsrv is not the same as php_pdo_sqlsrv