gpt4 book ai didi

javascript - Node js mysql 语法错误

转载 作者:行者123 更新时间:2023-11-29 17:51:50 26 4
gpt4 key购买 nike

我在服务器端的 Node js 中编写了一些代码来更新 MySQL 数据库。

这是我的代码:

exports.addPlayerToMatch = function(uid,matchId){
return new Promise(function(resolve,reject){
dbFunctions.getPlayerUids(matchId).then(function(rows){
playerUids = JSON.parse(rows[0].uids_of_players);
playerUids.push(uid);
console.log("new player uids: " +playerUids);
numberOfPlayers = playerUids.length;
db.query('UPDATE current_matches SET number_of_players = ?,
uids_of_players = ? WHERE id = ?' ,[numberOfPlayers,playerUids,matchId],
function (err, rows) {
if (err){ console.log("ErrorForAddPlayerToMatch: "+err);}
});
resolve(numberOfPlayers);
});
});
};

这是错误:

ErrorForAddPlayerToMatch: Error: ER_PARSE_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 ''3d8b7210fc1999bf191b0e1f7d744269' WHERE id = 29' at line 1

我不知道!!

请帮忙。

最佳答案

问题是我忘记在查询中使用数组之前再次将其转换为 JSON 对象。

它会解决这样的问题:

var playerUids = JSON.stringify(playerUids);

然后在查询中使用它。

关于javascript - Node js mysql 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49254966/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com