0
我可以用PHP通過pdo_dblib這樣的查詢伊斯利執行:腓pdo_db LIB綁定錯誤
$stmt = $pdo->prepare("
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 * 2
");
$stmt->bindValue('page', 2);
$stmt->bindValue('rows', 2);
$stmt->execute();
print_r($stmt->fetchAll(PDO::FETCH_ASSOC));
結果:
Array
(
[0] => Array
(
[ID] => 4608
[StartTime] => Apr 15 2014 06:00:00:000PM
[EndTime] => Apr 16 2014 09:30:00:000AM
[ComputeTime] => May 29 2014 04:33:35:743PM
[ComputeSettlementTime] => May 29 2014 04:34:49:063PM
[_NO] => 3
)
[1] => Array
(
[ID] => 4609
[StartTime] => Apr 16 2014 09:30:00:000AM
[EndTime] => Apr 16 2014 10:00:00:000AM
[ComputeTime] => May 29 2014 04:34:05:927PM
[ComputeSettlementTime] => May 29 2014 04:34:49:297PM
[_NO] => 4
)
)
,但如果我嘗試設置參數「頁」在地方第二次在同一查詢已經使用了兩次「2」在此查詢等參數「行」的,我有結果:
$stmt = $pdo->prepare("
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
");
$stmt->bindValue('page', 2);
$stmt->bindValue('rows', 2);
$stmt->execute();
print_r($stmt->fetchAll(PDO::FETCH_ASSOC));
結果是:
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 8117 General SQL Server error: Check messages from the SQL Server [8117] (severity 16) [(null)]'
,併爲此錯誤代碼我cant'find誤差表:8117 有誰知道這是怎麼回事?
缺少':''試$ stmt-> bindValue( ':頁面',2);' –
@JitendraYadav這樣也不管用。 – hjpotter92