views:

1083

answers:

3

I have a number of servers running PHP 5.2.6 (non-thread-safe build) on Windows 2003/IIS6 utilising FastCGI.

I'm having some issues connecting to MS SQL 2000/2005 (MySQL connectivity is working fine, ASP/ASP.NET scripts can connect to MS SQL successfully as well). One solution suggests copying the SQL Client Tools ntwdblib.dll file to the PHP extensions folder or installing all of the SQL Client Tools on the web server (which I'm reluctant to do).

Another solution suggested is to use the Microsoft SQL Server 2005 Driver for PHP. This looks fine for writing greenfield apps but for applications such as phpBBS or WordPress this doesn't appear to work.

For example, the following script:

<?php 
$host = "mssqlhost"; 
$user = "phpbb2"; 
$password = "phpbb2"; 

$connect_sql_server = mssql_connect($host, $user, $password); 
?>

Fails with:

PHP Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: mssqlhost in E:\AppsDev.NET_UK_Minds\phpSqlNC\www\test.php on line 6

The goal is to allow PHP scripts to connect to both SQL 2000 and SQL 2005 which are running on different servers. I should also add that upgrading to a later version of PHP isn't an option at this time.

What is the correct way to configure PHP on Windows 2003/IIS6 to connect to SQL 2000/2005?

+4  A: 

After trying various 'solutions' it turns out that the problem was solved simply by replacing the ntwdblib.dll file in the PHP executables folder.

There is no need to install any of: SQL Native Client, SQL Client Tools or Microsoft SQL Server 2005 Driver for PHP, as many dead ends have suggested.

All that needs done is to ensure that ntwdblib.dll version 2000.80.2039.0 is dropped into the c:\php folder (or wherever you've installed/uncompressed PHP to) and then reset IIS. The PHP docs suggest copying ntwdblib.dll to %SYSTEMROOT%\System32 which doesn't work and they also suggest that this will only support named pipes which is also wrong.

I haven't tried to see if a later version of ntwdblib.dll works or not, but 2000.80.2039.0 works for me.

Kev
The PHP docs would suggest system32 because this can be the default PHP location.Do you know of the official site to get the ntwdblib.dll from? I googled and found one but would like to know where to get the latest version.I had enabled MSSQL.dll in php.ini but when going to cmd and doing php -m to list all modules, an error box appeared saying I was missing ntwdblib.dll which led me here :D
KevinUK
We have lots SQL 2000 SP4 on site so I basically grabbed it from one of the servers and copied to the web server.
Kev
+1  A: 

Not really an answer, but more helpful information...

The version of ntwdblib.dll (2000.2.8.0) that comes with latest php 5.2.X works great with Apache and MSSQL (2008). I have a copy of the DLL from the 2000.80.X.X versions and it is newer than what comes with PHP. I don't know if this makes it better.

The "mssql_" functions are not included in the official msft php mssql driver. They have changed them to a different naming convention. ("sqlsrv_") That link you posted is version 1.0 but they are already on version 1.1. The "mssql_" functions require that the ntwdblib.dll be present.

LLBBL
I got my issues resolved and have been following developments regarding MS SQL and the official drivers. Thanks for the info.
Kev
No problem. Just FYI, it appears that all the "mssql_" functions have been dropped in 5.3 because this file is not included currently.
LLBBL
A: 

Apache 2.2.14 /PHP 5.2.12/MS-SQL 2008 integration

  • Download Apache 2.2.14 for Windows Installer package 2008 32 bit httpd DOT apache DOT org/download.cgi --> apache_2.2.14-win32-x86-no_ssl
  • follow the defaults when installing Apache
  • stop Apache 2.2 service

  • Download PHP 5.2.12 Windows Zip package for Windows 2008 32 bit; (VC6 Thread Safe version needed for PHP used as an Apache module).

windows DOT php DOT net/download/ --> php-5.2.12-Win32-VC6-x86.zip - Extract the archive to C:\PHP - Verify the installation: C:\PHP>php -v
- set the Environment Variable PHPRC=C:\PHP - Rename 'C:\PHP\php.ini-recommended' to 'C:\PHP\php.ini' - Edit C:\PHP\php,ini file:

modify:     extension_dir = "C:\PHP\ext"
uncomment:  extension=php_mssql.dll
  • Add the lines below to "C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf"

    PHPIniDir "C:/PHP/"
    LoadModule php5_module "C:/PHP/php5apache2_2.dll"
    AddHandler application/x-httpd-php .php
    
  • Add the lines below to "C:\Program Files\Apache Software Foundation\Apache2.2\conf\mime.types"

    application/x-httpd-php php
    application/x-httpd-php-source  phps
    
  • Ensure that phpinfo.php file with the content: is in the folder C:\Program Files\Apache Software Foundation\Apache2.2\htdocs

  • Start Apache 2.2 service

  • Verification of Apache/PHP integration: http://localhost/phpinfo.php --> 'PHP Version 5.2.12' info shows up
  • Verification whether mssql' module is loaded: c:\php\php -m

All works like a charm ... no additional steps needed.

SKIMAN