Ankur Loriya
Ankur Loriya

Reputation: 3534

NodeJS - how can get mysql result with executed query?

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??.

Upvotes: 1

Views: 4096

Answers (2)

yosiweinreb
yosiweinreb

Reputation: 485

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

Upvotes: 8

Akram Saouri
Akram Saouri

Reputation: 1169

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+"'" 

Upvotes: 0

Related Questions