【问题标题】:Node.js and mysql undefined functionNode.js 和 mysql 未定义函数
【发布时间】:2021-11-23 01:11:12
【问题描述】:

我正在用 node.js 编写这个函数,在函数内部它给了我正确的输出,但是当我尝试从外部调用它时它给了我未定义的。 你知道为什么它不起作用吗?

 var inquinamento=function(){
 connection.query('select livelloInquinamento from livInquinamento;',function(err,rows,fields){
 console.log(rows);
 return rows.livelloInquinamento;
 });
 }

【问题讨论】:

标签: mysql node.js database function return


【解决方案1】:

你可以试试这个

const data = await connection.query('select livelloInquinamento from livInquinamento');

数据将包含行和字段,并将这一行包装在异步函数中

【讨论】:

    猜你喜欢
    • 2015-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-18
    • 2017-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多