0

So bare with me, I'm trying to create a function that checks if a user exists in a mysql database, and if it exists it would return true, else return false. However, I've run into a problem due to the fact that I'm using ANOTHER function to get the result of the mysql query to which the return is using that function instead of the main function that I need. So heres a snippet of the function that I am currently using.

let connection = mysql.createConnection(db_config);
connection.connect()
let query = connection.query('SELECT * FROM users WHERE usid = "' + token + '"', function (err, result, fields) {
 if (Object.keys(result).length != 0){
    return true
     } else {
          return false;
     }
})
connection.end();
 
}

So is there some way that I could get the return value from that inner function and then return that same value to where I am originally calling the function or would I need to completely rewrite how I am currently doing this?

The way I am calling it is just putting it as a variable and determining the values and what to do with each of them.

let usercheck = checkClient(userid);

Moon Wolf
  • 13
  • 3

0 Answers0