php pdo_dblib sql server分页

时间:2014-06-12 12:48:56

标签: php sql-server pagination declare

我可以针对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

我得到了结果:

result of executing query

但如果我尝试通过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'.

0 个答案:

没有答案