目前我有这个问题,问题是表名得到一组引号(ad它是一个字符串),这会使服务器崩溃。
const update = 'the name of my column';
const UpdateQuery = `UPDATE scores
SET ${mysql.escape(update)} = ${mysql.escape(newValue)}
WHERE score_id = ${mysql.escape(singleScore.score_id)}`;mysql.escape()对除列名以外的所有内容都工作得很好。
如果我在注入变量后对查询执行console.log,则会得到以下结果:
UPDATE scores
SET 'the name of my column' = 1
WHERE score_id = 1发布于 2018-09-20 23:38:18
检查下面的代码。或许能行得通,
con.query(
'UPDATE scores SET '+update+' = ? Where score_id = ?',
// Old - [${mysql.escape(newValue)}, ${mysql.escape(singleScore.score_id)}],
/* Update - */ [newValue,singleScore.score_id],
(err, result) => {
if (err) throw err;
console.log(`Changed ${result.changedRows} row(s)`);
}
);根据您的查询,${mysql.escape(update)}包含值中的单引号。
https://stackoverflow.com/questions/52428398
复制相似问题