php连接sqlserver需要有mssql这个扩展(centos)。mssql的扩展安装很简单这里就不说了。主要说下我连接遇到的问题:

mssql_connect ("192.168.0.152", "uername", "paswd") or die ("Could not connect to database: ".mssql_get_last_message());

显示错误信息:Warning: mssql_connect(): Unable to connect to server: 192.168.0.152

在网上查找一番发现自己没有配置freetds.conf:

[myserver] host = 192.168.0.152 port = 1433 tds version = 7.2 client charset = utf8

../freetds/bin/tsql -S SQLSERVER -U username -P passwd

还是报错误:

Error 20013 (severity 2):Unknown host machine name. 怎么回事呢,原来是源引用错了

../freetds/bin/tsql -S myserver -U username -P passwd

执行php程序的时候发现还是报“Unable to connect to server”错误,加上端口号就ok了

mssql_connect ("192.168.0.152:1433", "uername", "paswd")