使用 where 子句时更新中的语法错误

Syntax error in update when using where clause

我被困在 update 查询中。我正在处理注册表单,如果确认邮件 link 被重定向到站点,则更新查询传递并使用确认值更新行。

错误信息如下:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''users' SET 'confirm'='1' WHERE 'com_code'='732aabcb4ad6a03b51e0a55aab998726'' at line 1

请检查我的语法错误:

UPDATE 'users' 
SET 'confirm'='1' 
WHERE 'com_code'='732aabcb4ad6a03b51e0a55aab998726';

谢谢!

引用标识符使用反引号`Identifier Names

Identifiers may be quoted using the backtick character - `. Quoting is optional for identifiers that don't contain special characters, or is a reserved word. If the ANSI_QUOTES SQL_MODE flag is set, double quotes (") can also be used to quote identifiers.

UPDATE `users` 
SET `confirm`='1' 
WHERE `com_code`='732aabcb4ad6a03b51e0a55aab998726';

如果您的标识符不是关键字或不包含空格等,则根本不要使用它们:

UPDATE users 
SET confirm ='1' 
WHERE com_code='732aabcb4ad6a03b51e0a55aab998726';

您不需要将 confirmuserscom_code 放在引号内, 使用这个:

UPDATE users 
SET confirm ='1' 
WHERE com_code='732aabcb4ad6a03b51e0a55aab998726';