What is the correct PHP configuration to connect to MS SQL 2000/2005?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 03:36:47

问题


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?


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/747477/what-is-the-correct-php-configuration-to-connect-to-ms-sql-2000-2005

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!