【问题标题】:PHP - mssql_connect(): Unable to connect to serverPHP - mssql_connect():无法连接到服务器
【发布时间】:2019-08-14 05:45:11
【问题描述】:

我在 Windows Server 2016 上使用 Apache/2.2.8 (Win32) PHP/5.2.6。

我有 2 个 SQL Server 实例:
1. 10.201.74.50
- 安装在上面的本地 Windows 服务器上。
- @@VERSION: Microsoft SQL Server 2016 (SP2-GDR) (KB4293802) - 13.0.5081.1 (X64) Jul 20 2018 22:12:40 版权所有 (c) Microsoft Corporation Standard Edition (64-bit) o​​n Windows Server 2016 Standard 10.0(内部版本 14393:)(管理程序)
2. 10.3.3.192\SQLEXPRESS,1433
- 安装在另一个 Windows 服务器上。
- @@VERSION = Microsoft SQL Server 2005 - 9.00.5000.00 (Intel X86) 2010 年 12 月 10 日 10:56:29 版权所有 (c) 1988-2005 Microsoft Corporation Express Edition with Advanced Services on Windows NT 6.1(Build 7601:Service Pack 1 )

我可以通过 Microsoft SQL Server Management Studio 和命令提示符连接到 2 个 SQL Server 实例,如下图所示。

如果是 PHP 代码,我可以连接到第一个服务器,但不能连接到第二个:

$link = mssql_connect("10.201.74.50","hoteldw","password");
// mssql_get_last_message(): Changed database context to 'HotelDW'.
// Work

$link = mssql_connect("10.3.3.192\SQLEXPRESS,1433","p","password");
// mssql_get_last_message():
// string(73) "mssql_connect(): Unable to connect to server:  10.3.3.192\SQLEXPRESS,1433"

$link = mssql_connect("10.3.3.192\SQLEXPRESS","p","password"); 
// mssql_get_last_message():
// string(68) "mssql_connect(): Unable to connect to server:  10.3.3.192\SQLEXPRESS"

$link = mssql_connect("10.3.3.192,1433","p","password");
// mssql_get_last_message():
// string(62) "mssql_connect(): Unable to connect to server:  10.3.3.192,1433"

【问题讨论】:

  • 从第二个连接字符串中删除端口号。您可以使用instance nameport no
  • 您的 PC 上的ntwdblib.dll 是什么版本,mssql_get_last_message() 输出什么?
  • @Squirrel,我试过了,也有同样的错误。请帮忙查看我上面更新的代码。
  • Update your PHP!!!!! 5.2.6 是古老的,缺少很多极其重要的补充
  • 天啊——你还在使用 sql server 2005!安全和支持重要吗?

标签: php sql-server


【解决方案1】:

将php安装文件夹中的ntwdblib.dll文件从7.00.839替换为8.00.2039或更高版本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多