Mysql 我的Sql查询在nodejs中返回一个带有req.params.id的空数组

Mysql 我的Sql查询在nodejs中返回一个带有req.params.id的空数组,mysql,node.js,express,Mysql,Node.js,Express,我使用nodejs进行Mysql查询,如下所示: application.get('/Modification/:idt',function(req,res){ connection.query("SELECT * FROM memos WHERE idMemo = 'req.params.idt'",function (error, rows){ if (error) { console.log("error ocurred",erro

我使用nodejs进行Mysql查询,如下所示:

  application.get('/Modification/:idt',function(req,res){


        connection.query("SELECT * FROM memos WHERE idMemo = 'req.params.idt'",function (error, rows){
         if (error) {
        console.log("error ocurred",error);
        }
        else {
            console.log(req.params.idt);
            console.log(rows);
            var no = rows;
            res.render('memosModif.ejs', {no});
        } 

    });

    });
我的查询返回一个空数组,即使req.params.idt返回一个int值,如1或2,但当我用1或2之类的int替换req.params.id时。。。查询返回正确的结果
我不明白为什么以及如何解决这个问题。

您正在将
idMemo
列与字符串文本进行比较
。相反,您应该绑定此变量的值:

connection.query("SELECT * FROM memos WHERE idMemo = ?", req.params.idt, function (error, rows) {

我用你的查询修改了它,效果很好,我花了几个小时试图解决这个问题,谢谢!MKHYRMD,如果这解决了你的问题,请考虑将它标记为接受的答案,给予@ MuriNik信用并让其他人知道你已经找到了解决方案。欢迎,祝你好运!