Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Microsoft PHP PDO for SQL Server working

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.

like image 352
Sam Avatar asked Mar 31 '12 09:03

Sam


People also ask

Does PHP work with SQL Server?

The Microsoft Drivers for PHP for SQL Server enable integration with SQL Server for PHP applications. The drivers are PHP extensions that allow the reading and writing of SQL Server data from within PHP scripts.

How enable Sqlsrv in PHP INI?

The SQLSRV extension is enabled by adding appropriate DLL file to your PHP extension directory and the corresponding entry to the php. ini file. The SQLSRV download comes with 8 driver files, four of which are for PDO support. The most recent version of the driver is available for download here: » SQLSRV download.

What is Pdo_dblib?

PDO_DBLIB is a driver that implements the PHP Data Objects (PDO) interface to enable access from PHP to Microsoft SQL Server and Sybase databases through the FreeTDS library. This extension is not available anymore on Windows.


2 Answers

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.

like image 153
Rex Avatar answered Sep 21 '22 08:09

Rex


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
like image 45
Ben Carey Avatar answered Sep 19 '22 08:09

Ben Carey