简体   繁体   English

在php / mysql中更新多个行/列

[英]Update multiple rows/columns in php/mysql

I have the following line: 我有以下几行:

$reset = "UPDATE pidgeon SET obt='" . $hour . "' WHERE tag='" . $tag . "'";

Which updates just fine. 哪个更新就好了。 However I need to update an additional row (kill) and I keep getting syntax errors. 但是,我需要更新其他行(kill),并且不断收到语法错误。 I've tried the following: 我尝试了以下方法:

$reset = "UPDATE pidgeon SET obt='" . $hour . "', kill='1' WHERE tag='" . $tag . "'";

$reset = "UPDATE pidgeon SET kill='1', obt='" . $hour . "' WHERE tag='" . $tag . "'";

$reset = "UPDATE pidgeon SET obt='" . $hour . "', kill='" . $num . "' WHERE tag='" . $tag . "'";

I've even done 2 separate UPDATE queries and I get the same syntax error message. 我什至完成了2个单独的UPDATE查询,并且得到了相同的语法错误消息。 I've narrowed it down to the system having issue with the kill row but I'm not sure what's the issue. 我已将其范围缩小到kill列出现问题的系统,但是我不确定是什么问题。 I've tried setting kill as INT, SMALLINT, BOOL, even CHAR and trying to use 't/f' as values for it. 我尝试将kill设置为INT,SMALLINT,BOOL甚至CHAR,并尝试使用“ t / f”作为其值。 I still get a syntax error. 我仍然收到语法错误。 Any suggestions? 有什么建议么?

KILL is a reserved keyword , so you'll have to enclose it in backticks, like so: KILL保留关键字 ,因此您必须将其括在反引号中,如下所示:

$reset = sprintf("UPDATE pidgeon SET `kill`='1', obt='%s' 
WHERE tag='%s'", $hour, $tag);

Kill is actually a syntax, you can't use them directly. Kill实际上是一种语法,您不能直接使用它们。

Just replace kill with another name. 只需用另一个名称替换kill

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM