节点:在mysql数据库中插入特殊字符字符串

pra*_*nde 2 mysql tcp node.js

我正在使用节点 tcp 服务器为我的角度应用程序实现指纹身份验证,在我的场景中,生物识别设备将特殊字符字符串返回到我的节点服务器,其中包括特殊字符,例如 single 和 double,就像@#$'%"我想用 single 将这个完整的字符串存储到数据库中一样。以及双引号。我有以下查询

var fingerPrint = '@#$'%"'
db.query("insert into tbl_name (id, tempalte) value ('"+fingerPrint+"','')", (err, result)=>{
console.log(result)
}) 
Run Code Online (Sandbox Code Playgroud)

但是当字符串包含双引号时,查询将终止,单引号也会出现问题。有没有什么办法可以实现这个机制。
提前致谢

JAY*_*TEL 5

这是一种方法,在 NodeJs 中使用 MySQL。您可以尝试以下方法:

let fingerPrint = `'@#$'%"'`;
let addQuery = "INSERT INTO tbl_name (id, template) VALUES (?,?)";
let values = [1, fingerPrint];

db.query(addQuery, values, function (err, result) {
   if (err) {
      return console.error(err.message);
   }
   console.log("Number of records inserted: " + result.affectedRows);
})
Run Code Online (Sandbox Code Playgroud)