【发布时间】:2015-07-31 02:49:49
【问题描述】:
我目前在这方面遇到了麻烦......
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 中有效,则不会拼写错误)?前段时间我遇到了类似的问题,直到我意识到我连接到了一个较旧的开发数据库副本......
标签: php sql-server laravel pdo