我尝试访问results[0].guess
,将其返回给调用者。 console.log(getGuess(12,4)
(参数不重要)只返回undefined。我如何访问结果?
注意:我正在使用带有mysql的Node.js.
var getGuess = function(userId, gameId) {
var query = 'SELECT * FROM guesses WHERE user_id = ' + connection.escape(userId) + ' AND game_id = ' + connection.escape(gameId);
connection.query(query, function(err, results) {
if (err) {
console.log(err);
return;
}
var guess = results[0].guess;
return;
});
return guess;
};