I’m working with a MySQL database that contains user information including usernames and pin codes. I need to locate a specific user by their username and then display their associated pin number. Right now I can check if the user exists but I’m not sure how to extract just the pin value from the query results.
Here’s my current approach for checking user existence:
dbConnection.query("SELECT * FROM users WHERE username = ?", ['user123456'], function(error, rows, fields){
if(rows.length === 0){
console.log("User not found");
} else {
console.log("User found");
// How do I get the pin value here?
}
});
What’s the best way to access the specific column data from the result set?