我如何使用IP地址将PHP连接到SQL Server


How i can connect PHP to SQL Server with IP Address

我无法使用我的 PC IP 地址连接到数据库,但我可以使用我的 PC 名称连接到数据库。我如何修复它或在SQL服务器中配置它?

那么,PC名称和127.0.0.1之间有什么区别来连接SQL Server?

这是我的代码不同:

mssql_connect("MYPCNAME","sa","solution") or die('Connection Failed'); //this is OK
mssql_connect("127.0.0.1","sa","solution") or die('Connection Failed'); // this is failed

我需要你的专业知识;)

如果您使用端口号,它可能会起作用,例如:

mssql_connect("127.0.0.1:1433","sa","solution") or die('Connection Failed'); 

如果您在 Windows 上使用 PHP,请尝试:

 mssql_connect("127.0.0.1,1433","sa","solution") or die('Connection Failed'); 

使用主机名时,它通常会解析为计算机的非环回地址。使用 localhost127.0.0.1 将始终使用环回接口。

SQL Server 很可能不绑定到环回接口,而只绑定到实际接口(具有解析MYPCNAME时获得的 IP 的接口)。您可以继续使用 PC 名称或其 IP,也可以将 SQL Server 配置为侦听环回接口。