Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在查询中附加单引号(“”)_Javascript_Mysql_Node.js - Fatal编程技术网

Javascript 在查询中附加单引号(“”)

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

我对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 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+"'")