php mssql_connect(): 无法连接到服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17771922/
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
mssql_connect(): Unable to connect to server
提问by Ehphan
I have a Centos server with apache and PHP on it, and I have a SQL Server on another server, when I try to connect to MSSQL
with tsql -H
"sql server ip" -p1433 -U sa
, it works and connects OK, but when I try to run following PHP
code
我有一个装有 apache 和 PHP 的 Centos 服务器,我在另一台服务器上有一个 SQL Server,当我尝试MSSQL
使用tsql -H
“sql server ip”-p1433 -U sa
连接时,它可以正常工作并连接正常,但是当我尝试运行以下PHP
代码时
error_reporting(E_ALL);
ini_set('display_errors', '1');
$connection = mssql_connect('serverIP', 'username', 'password');
I get the error :
我收到错误:
Warning: mssql_connect(): Unable to connect to server: serverIP in /var/www/html/mssql.php on line 4
警告:mssql_connect():无法连接到服务器:第 4 行 /var/www/html/mssql.php 中的 serverIP
what should I do?
我该怎么办?
回答by Mihai
You have to specify the servername and the instance like in this example,I think: http://ca3.php.net/manual/en/function.mssql-connect.php
你必须像在这个例子中指定服务器名和实例,我认为:http: //ca3.php.net/manual/en/function.mssql-connect.php
EDIT: The following method: server\instance does'nt work on unix systems...
编辑:以下方法: server\instance 在 unix 系统上不起作用...
An instance is nothing more than specific port address different than 1433... so just discover the port on mssql server and then try to connect using:
一个实例只不过是与 1433 不同的特定端口地址......所以只需在 mssql 服务器上发现端口,然后尝试使用以下方法进行连接:
ip:port
ip:端口
In unix the port is specified by : not by ,
在 unix 中,端口由 : 指定,而不是由 ,
回答by Orab?g
In my case, I noticed that I coulnd't connect when I was giving the DB server name, but when I gave the IP adress directly, it worked !
就我而言,我注意到在提供数据库服务器名称时无法连接,但是当我直接提供 IP 地址时,它起作用了!
Maybe this information could be helpful to others...
也许这些信息对其他人有帮助......
Edit :after some research, I think this can be related to the freetds.conf file, which may contain server definitions. When using a name instead of an IP, I'm pretty sure that the driver is looking for a TDS definition of the same name...
编辑:经过一些研究,我认为这可能与 freetds.conf 文件有关,该文件可能包含服务器定义。当使用名称而不是 IP 时,我很确定驱动程序正在寻找同名的 TDS 定义......