繁体   English   中英

PHP远程访问MSSQL Server

[英]PHP remote access MSSQL Server

我试图使用php远程连接到其他服务器中的MSSQL数据库。 但最后显示错误

Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: xxx.xxx.xxx.xxx in xxxxxxx 

这是我的代码

    <?php
$myServer = "xxx.xxx.xxx.xxx";
$myUser = "user";
$myPass = "password";
$myDB = "database";

//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
  or die("Couldn't connect to SQL Server on $myServer");

//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
  or die("Couldn't open database $myDB");
  ?>

我尝试使用Microsoft SQL Server Management Studio登录,它可以正常工作并登录,所以我对允许远程连接访问没有问题。

顺便说一句。我只是从XAMPP Localhost访问它。 我不确定是不是这种效果。

在此先感谢您的帮助。

首先猜测:您的SQL Server没有监听TCP / IP。 在配置管理器中启用该协议。 重新启动服务器进程。

第二个猜测:防火墙阻止了访问。 启用对TCP端口1433的访问。

第三个猜测:驱动程序问题mssql驱动程序需要特殊版本的ntwdblib.dll。 根据您的php版本,它不存在。

最好切换到新的驱动程序“ sqlsrv”。 https://www.microsoft.com/en-us/download/details.aspx?id=20098

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM