const periode = _.get(row, "periode", new Date());
const prediction =
b0 +
b1 * Number.parseFloat(_.get(row, "x1", 0)) +
b2 * Number.parseFloat(_.get(row, "x2", 0));
const sql = `UPDATE performance SET prediction_result="${prediction}" WHERE periode="${periode}"`;
db.query(sql, (error, results, fields) => {
if (error) {
console.error('An error occurred while executing the query')
throw error
}
})
我遇到这样的错误:
throw err; // Rethrow non-MySQL errors
ReferenceError: connection is not defined
您能帮我解决这个问题吗?
答案 0 :(得分:0)
您的代码中应该有类似的内容。
var mysql = require('mysql');
var db= mysql.createConnection({
host: "localhost",
user: "yourusername",
password: "yourpassword"
});
db.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});