MYSQL使用变量更新多个列

时间:2022-09-15 09:31:45

I used this query to insert all my values into this database:

我使用此查询将所有值插入此数据库:

INSERT INTO products ($fields) VALUES ($values)

However, I try to use the same format for UPDATE:

但是,我尝试使用相同的格式进行更新:

UPDATE products SET ($fields) VALUES ($values) WHERE sku = '$checksku'

...and am getting thrown a syntax error:

...而且我遇到了语法错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('product,make,model,' at line 1

I can't figure it out. Would appreciate any help. Thanks.

我无法弄明白。非常感谢任何帮助。谢谢。

3 个解决方案

#1


26  

UPDATE syntax is different than INSERT syntax. An example of UPDATE would be:

UPDATE语法与INSERT语法不同。 UPDATE的一个例子是:

"UPDATE products SET field1 = 'value1', field2 = '$val2', field3 = 5 WHERE sku = '$checksku'"

#2


0  

INSERT INTO products ($fields) VALUES ($values) ON DUPLICATE KEY UPDATE field = VALUES(field), ...

Don't forgot about unique or primary key

不要忘记唯一或主键

#3


-4  

you need an =

你需要一个=

UPDATE products SET ($fields) = $values WHERE sku = '$checksku'

#1


26  

UPDATE syntax is different than INSERT syntax. An example of UPDATE would be:

UPDATE语法与INSERT语法不同。 UPDATE的一个例子是:

"UPDATE products SET field1 = 'value1', field2 = '$val2', field3 = 5 WHERE sku = '$checksku'"

#2


0  

INSERT INTO products ($fields) VALUES ($values) ON DUPLICATE KEY UPDATE field = VALUES(field), ...

Don't forgot about unique or primary key

不要忘记唯一或主键

#3


-4  

you need an =

你需要一个=

UPDATE products SET ($fields) = $values WHERE sku = '$checksku'