【发布时间】:2019-02-24 23:00:38
【问题描述】:
目前我有这个问题,问题是表名得到了一组引号(它是一个字符串),这导致服务器崩溃。
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
【问题讨论】:
-
我只是在我在这里写的例子中,而不是在我的实际代码中
-
您是否在使用控制台日志或要打印的内容应用 const 后检查了 UpdateQuery?
-
是的,我现在添加了它
-
那么,问题出在单引号上!?
-
是的,这就是导致问题的原因
标签: javascript mysql node.js express