Node.js 和 mysql 未定义函数

Posted

技术标签:

【中文标题】Node.js 和 mysql 未定义函数【英文标题】:Node.js and mysql undefined function 【发布时间】: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;
 );
 

【问题讨论】:

这能回答你的问题吗? How to return the response from an asynchronous call 【参考方案1】:

你可以试试这个

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

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

【讨论】:

以上是关于Node.js 和 mysql 未定义函数的主要内容,如果未能解决你的问题,请参考以下文章