NodeJS - how can get mysql result with executed query?

霸气de小男生 提交于 2021-02-08 07:47:03

问题


I am new in NodeJS with mysql (npm install mysql).

When I try to execute query like

connection.query("select ?? from users where id = ?",[["id","fname","lname"],req.body.userid],function (err, rows) {
     **here I want query which above executed**
});

I want query in callback function which executed.

How can I get it??.


回答1:


var c = connection.query("select ?? from users where id = ?",[["id","fname","lname"],req.body.userid],function (err, rows) {
     console.log(c.sql)
});



回答2:


connection.query("select ?? from users where id = ?",[["id","fname","lname"],req.body.userid],function (err, rows) {
     res.send(rows);
});

also in preference swith the string query to :

"select id,fname,lname from users where id = '"+req.body.userid+"'" 


来源:https://stackoverflow.com/questions/34064721/nodejs-how-can-get-mysql-result-with-executed-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!