MYSQL 使用变量更新多列
我使用此查询将所有值插入到此数据库中:
INSERT INTO products ($fields) VALUES ($values)
但是,我尝试使用相同的格式进行更新:
UPDATE products SET ($fields) VALUES ($values) WHERE sku = '$checksku'
...并且抛出语法错误:
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 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
UPDATE 语法与 INSERT 语法不同。更新的一个例子是:
尽管这可能不安全。您应该查看参数化查询。
UPDATE syntax is different than INSERT syntax. An example of UPDATE would be:
Though this may be insecure. You should look into parameterized queries.
不要忘记唯一键或主键
Don't forgot about unique or primary key
你需要一个=
you need an =