有没有一种方法可以将查询结果存储到全局变量?

时间:2020-07-30 07:01:59

标签: javascript mysql node.js

  let person_id = "";

  connection.query(
    `SELECT max(person_id) as person_id FROM persons WHERE phone_num = '${req.body.phone_num}'`,
    (err, result) => {
       person_id = result[0].person_id;
       console.log(person_id) // has an output
    }
  );

  console.log(person_id); //no output

0 个答案:

没有答案