How can I put the row number of a database in a variable

Omaewa Mu :

there is my problem :

{
const row_nb = con.query("SELECT COUNT(*) FROM Users WHERE username = '"+username_ins+"'");
console.log(""+row_nb);
}

but I dont have the row number why ? it return [Object object] And it's in javaScript

Sohail :

con.query is an async method you have to pass the callback to get the result.

var sql = "SELECT COUNT(*) as usersCount FROM Users WHERE username = ?"
con.query(sql, [username_ins], function(err, rows, fields) {
  if (err) throw err;
  console.log('Query result: ', rows[0].usersCount);
});

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=31699&siteId=1