php连接sqlserver上面的远程服务器连接出错

 

$mssql_server = 'xxx;//
$user         = 'xxx';
$password     = 'xxx';
$dbname  = 'xxx';
$mssql_link   = mssql_connect($mssql_server, $user, $password);
mssql_select_db($dbname, $mssql_link); 

因为一些需要php连接sqlserver上链接服务器里面的数据库 按照以前的连接方法如下:

$sql='select COUNT(*) as num from hisdb.xxx.dbo.xxx';

$res = mssql_query($sql);

但是并没有出现hisdb里面数据库数据表的数量,var_dump($res)一下查看返回的信息会发现报错如下:

eterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS options to be set for the connection. This ensures consistent query semantics. Enable these options and then reissue your query

后面几经修改发现要在sql前面加上如下俩句便可以正常查询:

$sql="SET ANSI_NULLS ON";
$res = mssql_query($sql);
$sql="SET ANSI_WARNINGS ON";
$res = mssql_query($sql);

你可能感兴趣的:(sqlserver)