0

Im trying to get values from function but getting undefined as return...

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) });
});
Geri
  • 1

0 Answers0