[英]nodejs how to retrieve variable value from mysql
I have a piece of code where I want to get the value of a variable from mysql database. 我有一段代码,我想从mysql数据库中获取变量的值。
var PNOP;
connection.query('SELECT pnop FROM MASTER1', [PNOP], function(err, results) {
console.log(results);
});
The connection query is working fine but the var PNOP is not getting updated. 连接查询工作正常,但是var PNOP没有得到更新。
The log file is showing the following entry: 日志文件显示以下条目:
[ { pnop: 7915.2 } ]
The value that I need to set as PNOP is 7915.2 which is what is in the mysql database. 我需要设置为PNOP的值是7915.2,这是mysql数据库中的值。
What should I do to get the variable value? 我应该怎么做才能得到可变值?
The way nodejs-mysql works, the second parameter for the query contains the values of the fields you want to escape, and not the output parameters. nodejs-mysql的工作方式,查询的第二个参数包含要转义的字段的值,而不包含输出参数。 The result of the query is in "results", as your log shows.
查询结果显示在“结果”中,如日志所示。 what your code should be is:
您的代码应该是:
var PNOP;
connection.query('SELECT pnop FROM MASTER1', [], function(err, results) {
PNOP = results[0].pnop;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.