我目前有這個麻煩的數...綁定變量的Laravel 5 PDO數量不符令牌
if (Input::has('numenr') and Input::has('table') and Input::has('type') and Input::has('st')) {
$sql_up = "UPDATE [wds].[dbo].[?] SET [f_nonvint] = ? WHERE [numenr] = '?' AND [f_type] = ?";
DB::connection('sqlsrv')->update($sql_up, [Input::get('table'), Input::get('st'), Input::get('numenr'), Input::get('type')]);
}
錯誤輸出是:
SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens (SQL: UPDATE [wds].[dbo].[f_files_wines] SET [f_nonvint] = 1 WHERE [numenr] = '091DFF89-EB1B-4B81-9BF0-4AB36F65529E' AND [f_type] = 1)
查詢給出看起來不錯,我不明白這是從哪裏來的。
謝謝你的幫助! :)
更新:
上一個錯誤是用一個小技巧修復的。問題在於唯一標識符。我無法在sql中添加引號...不知道爲什麼。 有修復:
if (Input::has('numenr') and Input::has('table') and Input::has('type') and Input::has('st')) {
$sql_up = "UPDATE [wds].[dbo].[?] SET [f_nonvint] = ? WHERE [numenr] = ? AND [f_type] = ?";
DB::connection('sqlsrv')->update($sql_up, [Input::get('table'), Input::get('st'), "'".Input::get('numenr')."'", Input::get('type')]);
}
但現在我發現了一個更奇怪的問題。
SQLSTATE[HY000]: General error: 208 General SQL Server error: Check messages from the SQL Server [208] (severity 16) [(null)] (SQL: UPDATE [wds].[dbo].[t_files_wines] SET [f_nonvint] = 1 WHERE [numenr] = '7AEDE4A0-0109-4729-8AFE-D4A55A0A5893' AND [f_type] = 2)
但事實是,當我將查詢複製到SqlServer,我沒有錯! :(
錯誤208意味着'無效對象' - 你檢查你是否連接到正確的服務器(如果該語句在SSMS中工作,它不能拼錯)?前些時候,我有一個類似的問題,直到我意識到我已連接到開發數據庫的舊版本... –