我可以针对sql server执行这样的查询:
DECLARE @ROWS INT = 2, @PAGE INT = 2
SELECT *
FROM (
SELECT *,
ROW_NUMBER() OVER (ORDER BY ID) AS _NO
FROM [Reports].[dbo].[Cycle]
) AS SOD
WHERE SOD._NO BETWEEN ((@PAGE-1)*@ROWS)+1
AND @ROWS*(@PAGE)
GO
我得到了结果:
但如果我尝试通过dblib在pdo中这样做,它就不起作用了:
$stmt = $pdo->query("
DECLARE @ROWS INT = 2, @PAGE INT = 2
SELECT *
FROM (
SELECT *,
ROW_NUMBER() OVER (ORDER BY ID) AS _NO
FROM [Reports].[dbo].[Cycle]
) AS SOD
WHERE SOD._NO BETWEEN ((@PAGE-1)*@ROWS)+1
AND @ROWS*(@PAGE)
GO
");
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
错误代码:
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 102 General SQL Server error: Check messages from the SQL Server [102] (severity 15)
根据错误消息描述错误:http://www.sql-server-helper.com/error-messages/msg-1-500.aspx
是:
Incorrect syntax near '%.*ls'.