windows 连接到 MS SQL 2000/2005 的正确 PHP 配置是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/747477/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:18:06  来源:igfitidea点击:

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

phpsql-serverwindowsiis-6

提问by Kev

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

我有许多使用 FastCGI 在 Windows 2003/IIS6 上运行PHP 5.2.6(非线程安全构建)的服务器。

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 solutionsuggests copying the SQL Client Tools ntwdblib.dllfile to the PHP extensions folder or installing all of the SQL Client Tools on the web server (which I'm reluctant to do).

我在连接到 MS SQL 2000/2005 时遇到了一些问题(MySQL 连接工作正常,ASP/ASP.NET 脚本也可以成功连接到 MS SQL)。一种解决方案建议将 SQL 客户端工具ntwdblib.dll文件复制到 PHP 扩展文件夹或在 Web 服务器上安装所有 SQL 客户端工具(我不愿意这样做)。

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.

建议的另一个解决方案是使用Microsoft SQL Server 2005 Driver for PHP。这对于编写全新的应用程序看起来不错,但对于 phpBBS 或 WordPress 等应用程序,这似乎不起作用。

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

PHP 警告:mssql_connect() [function.mssql-connect]:无法连接到服务器:第 6 行 E:\AppsDev.NET_UK_Minds\phpSqlNC\www\test.php 中的 mssqlhost

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.

目标是允许 PHP 脚本连接到运行在不同服务器上的 SQL 2000 和 SQL 2005。我还应该补充一点,此时升级到更高版本的 PHP 不是一种选择。

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

在 Windows 2003/IIS6 上配置 PHP 以连接到 SQL 2000/2005 的正确方法是什么?

回答by Kev

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

在尝试了各种“解决方案”后,结果发现问题仅通过替换ntwdblib.dllPHP 可执行文件文件夹中的文件即可解决。

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

无需安装任何:SQL Native ClientSQL Client ToolsMicrosoft SQL Server 2005 Driver for PHP,正如许多死胡同所建议的那样。

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

所需要做的就是确保将ntwdblib.dll版本 2000.80.2039.0 放入c:\php文件夹(或您安装/解压缩 PHP 的任何位置),然后重置 IIS。PHP 文档建议复制ntwdblib.dll到 %SYSTEMROOT%\System32 这不起作用,他们还建议这将只支持命名管道,这也是错误的。

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

我还没有尝试查看更高版本是否ntwdblib.dll有效,但 2000.80.2039.0 对我有用。

回答by LLBBL

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.

最新 php 5.2.X 附带的 ntwdblib.dll (2000.2.8.0) 版本非常适合 Apache 和 MSSQL (2008)。我有一份 2000.80.XX 版本的 DLL 副本,它比 PHP 附带的要新。不知道这样会不会好点。

The "mssql_" functions are not included in the official msft php mssqldriver. 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.

“mssql_”函数不包含在官方 msft php mssql驱动程序中。他们已将它们更改为不同的命名约定。("sqlsrv_") 你发布的那个链接是 1.0 版,但它们已经是 1.1 版了。“mssql_”函数要求存在 ntwdblib.dll。

回答by SKIMAN

Apache 2.2.14 /PHP 5.2.12/MS-SQL 2008 integration

Apache 2.2.14 /PHP 5.2.12/MS-SQL 2008 集成

  • 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).

  • 下载 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
  • 安装Apache时遵循默认值
  • 停止 Apache 2.2 服务

  • 下载适用于 Windows 2008 32 位的 PHP 5.2.12 Windows Zip 包;(用作 Apache 模块的 PHP 需要 VC6 线程安全版本)。

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:

windows DOT php DOT net/download/ --> php-5.2.12-Win32-VC6-x86.zip - 将存档解压到 C:\PHP - 验证安装:C:\PHP>php -v
- 设置环境变量 PHPRC=C:\PHP - 将 'C:\PHP\php.ini-recommended' 重命名为 'C:\PHP\php.ini' - 编辑 C:\PHP\php,ini 文件:

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
  • 将以下几行添加到“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
    
  • 将以下行添加到“C:\Program Files\Apache Software Foundation\Apache2.2\conf\mime.types”

    application/x-httpd-php php
    application/x-httpd-php-source  phps
    
  • 确保包含内容的 phpinfo.php 文件位于文件夹 C:\Program Files\Apache Software Foundation\Apache2.2\htdocs

  • 启动 Apache 2.2 服务

  • Apache/PHP 集成验证:http://localhost/phpinfo.php--> 'PHP Version 5.2.12' 信息出现
  • 验证mssql'模块是否加载:c:\php\php -m

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

一切都像魅力一样......不需要额外的步骤。