我在服务器端编写了一些代码,在节点 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:错误:ER_PARSE_ERROR:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“3d8b7210fc1999bf191b0e1f7d744269”WHERE id = 29'附近使用正确的语法
我不知道 !!
请帮助。
问题是我忘记在查询中使用数组之前再次将其转换为 JSON 对象。
它会解决这样的事情:
var playerUids = JSON.stringify(playerUids);
然后在查询中使用它。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句