PHP上的SQL链接服务器查询错误

时间:2012-11-13 02:07:50

标签: php sql-server linked-server

我使用链接服务器进行MSSQL查询。该查询适用于MSSMS。

但我不能让它适用于PHP。

SELECT 
l.USER_KEY as id, 
l.USER_ID as username, 
CASE WHEN l.PASSWORD = 'x' THEN 'blaze' WHEN l.PASSWORD = 'b' THEN 'xtreme' END AS server, 
CASE WHEN l.CHECKLOGIN = 0 THEN 'offline' WHEN l.CHECKLOGIN = 1 THEN 'online' WHEN l.CHECKLOGIN = 2 THEN 'banned' END AS status,
l.LOGINIP AS ip_address,
CASE WHEN l.PASSWORD = 'x' THEN g.CHARID0 WHEN l.PASSWORD = 'b' THEN xg.CHARID0 END AS slot1,
CASE WHEN l.PASSWORD = 'x' THEN g.CHARID1 WHEN l.PASSWORD = 'b' THEN xg.CHARID1 END AS slot2,
CASE WHEN l.PASSWORD = 'x' THEN g.CHARID2 WHEN l.PASSWORD = 'b' THEN xg.CHARID2 END AS slot3,
Convert(varchar, LOGINTIME,111) AS last_login
FROM game.dbo.CHAR_INFOR AS g
    JOIN login.dbo.USER_CHECK_LOGIN AS l 
    ON g.USER_KEY = l.USER_KEY
    JOIN XTREME.game.dbo.CHAR_INFOR AS xg --this is a linked server
    ON xg.USER_KEY = l.USER_KEY
    WHERE PASSWORD LIKE 'sbhacker0%'
ORDER BY last_login

这个查询在PHP上返回时:(错误)

 Heterogeneous 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. (severity 16) 
 General SQL Server error: Check messages from the SQL Server (severity 16)
 Query failed

这是我的PHP脚本,请查看。

$con = mssql_connect('host\INST','user','pass') 
    or die('Could not connect to the server!');

// Select a database:
mssql_select_db('login') 
    or die('Could not select a database.');

// Example query: (TOP 10 equal LIMIT 0,10 in MySQL)
$SQL = "SELECT 
l.USER_KEY as id, 
l.USER_ID as username, 
CASE WHEN l.PASSWORD = 'x' THEN 'blaze' WHEN l.PASSWORD = 'b' THEN 'xtreme' END AS server, 
CASE WHEN l.CHECKLOGIN = 0 THEN 'offline' WHEN l.CHECKLOGIN = 1 THEN 'online' WHEN l.CHECKLOGIN = 2 THEN 'banned' END AS status,
l.LOGINIP AS ip_address,
CASE WHEN l.PASSWORD = 'x' THEN g.CHARID0 WHEN l.PASSWORD = 'b' THEN xg.CHARID0 END AS slot1,
CASE WHEN l.PASSWORD = 'x' THEN g.CHARID1 WHEN l.PASSWORD = 'b' THEN xg.CHARID1 END AS slot2,
CASE WHEN l.PASSWORD = 'x' THEN g.CHARID2 WHEN l.PASSWORD = 'b' THEN xg.CHARID2 END AS slot3,
Convert(varchar, LOGINTIME,111) AS last_login
FROM game.dbo.CHAR_INFOR AS g
    JOIN login.dbo.USER_CHECK_LOGIN AS l 
    ON g.USER_KEY = l.USER_KEY
    JOIN XTREME.game.dbo.CHAR_INFOR AS xg
    ON xg.USER_KEY = l.USER_KEY
    WHERE PASSWORD LIKE 'sbhacker0%'
ORDER BY last_login";

// Execute query:
$result = mssql_query($SQL) 

请指教,谢谢。

0 个答案:

没有答案