[英]How to update values in mongoDB using Express.js and axios
[英]How do I update a table in MySQL using an array of values and a prepared statement in Express.js?
我的数据库中有一个名为“排名”的表,我想在提交信息时进行更新。 发送到服务器的数据采用二维数组的形式,其结构如下:
[ [1, 78],
[2, 77],
[3, 76]]
左边的数字是ID,右边的数字是位置/分数。 这两个值在我的表中都已定义为“ ID”和“分数”,而我想做的就是用新数字覆盖原始数字。 我正在尝试使用准备好的语句来执行此操作,但是执行此查询时出现错误。
db.query('UPDATE rankings SET ID=?, score=?', [scoreTable], function(err, result) {
if(err) throw err;
console.log(result);
});
错误是这样的:
Error: ER_PARSE_ERROR: 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 '(2, 78), (4, 77), (3, 76), (5, 75), (6, 74), (7, 73), (8, 72), (9, 71), (10, 70)' at line 1
错误末尾的值来自我尝试使用的数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.