Javascript 在查询中附加单引号(“”)
我对mysql查询有一个小问题。通过node.js发送Javascript 在查询中附加单引号(“”),javascript,mysql,node.js,Javascript,Mysql,Node.js,我对mysql查询有一个小问题。通过node.js发送 res.send(SELECT `id` FROM table where `id` ='+id) 给出id为4的结果 select id from table where id=4 但我需要在查询中插入单引号。双引号: 'SELECT id FROM table where id ='''+id+'''' e、 g 将选择列值包含te'st的所有行,假设需要引用id值: res.send("SELECT id FROM table
res.send(SELECT `id` FROM table where `id` ='+id)
给出id为4的结果
select id from table where id=4
但我需要在查询中插入单引号。双引号:
'SELECT id FROM table where id ='''+id+''''
e、 g
将选择列值包含te'st的所有行,假设需要引用id值:
res.send("SELECT id FROM table where id ='"+id + "'")
我个人对来自Javascript的直接SQL查询表示怀疑——这通常意味着你的应用程序容易受到淘气的人的攻击。以下是你需要的:
res.send("SELECT id FROM table where id ='"+id+"'")
小心,这会让你暴露在危险中。阅读如何避免这种安全风险。使用reg表达式退出“by\”替换
res.send("SELECT id FROM table where id ='"+id + "'")
res.send("SELECT id FROM table where id ='"+id+"'")