我正在尝试从函数获取值,但未定义为返回值...
function get_data(id){
var name;
ibmdb.open(dbcon.con, function (err,conn) {
conn.query("select name from users where id='"+id+"'", function (err, data) {
name = data[0].NAME;
console.log(name) // there is the name is correct
conn.close(function () {});
});
});
return name; // there getting undefined
};
router.get('/:id', function(req, res, next) {
res.render('u', { name: get_data(req.params.id) });
});