我有一个使用链接服务器的 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)
请指教,谢谢。