Reputation: 119856
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?
Upvotes: 1
Views: 9326
Reputation: 1
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
All works like a charm ... no additional steps needed.
Upvotes: -1
Reputation: 166
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.
Upvotes: 2
Reputation: 119856
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.
Upvotes: 5