Answer the question
In order to leave comments, you need to log in
How to get variable outside mysql scope in node.js?
var line_last_id = "SELECT MAX(id) FROM table_name";
conn.query(line_last_id, function(err, result) {
var last_id = result[0]['MAX(id)']);
});
console.log(last_id);
Answer the question
In order to leave comments, you need to log in
Decided so
function getLastId(){
return new Promise(function(resolve, reject) {
var line_last_id = "SELECT MAX(id) FROM table_name";
conn.query(line_last_id, function(err, result){
resolve(result[0]['MAX(id)']);
})
})
}
getLastId().then((lastid) => console.log(lastid));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question