Answer the question
In order to leave comments, you need to log in
[Node.JS] [node-mysql] How to return a function value?
There is a function:
function check_session(id, sess, callback) {
pool.getConnection(function(err, connection) {
mysqlUtilities.upgrade(connection);
mysqlUtilities.introspection(connection);
connection.queryRow("select * from `users` where `id`="+id+" AND `session`='"+sess+"'", [], function(err, row) {
if(row==false) callback(0);
else callback(1);
});
});
}
io.on('connection', function(socket){
console.log('connected');
check_session(19,'1e7d10bb50278502f530d8ca3cc47071', function(result){
console.log(result); // я могу только так принимать и обрабатывать, а return result показывает undefined
});
});
if(check_session(19,'1e7d10bb50278502f530d8ca3cc47071')) {
...
} else {
....
}
Answer the question
In order to leave comments, you need to log in
Don't worry, just accept the fact that in node.js it is customary to do all the functions that work with the network, files and databases in an asynchronous style, i.e. they return values not through return, but through callback. Move your if to a callback, or rather, declare a function and pass it as a callback parameter so that the nesting does not grow. Get used to...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question