var query = "select * from ? where info = 1;"
var params = [table]; //table = 'light'
connection.query(query, params, function(err, rows) { //this rows returns 'undefined'
console.log(rows);
var sql = "UPDATE ? SET info = ?,off_time = '?',run_time = '?' WHERE info = '1'";
var run_time = time_cal(formatted, rows);
var params = [table, data, formatted, run_time];
connection.query(sql, params, function(err, rows) {
if (err) {
console.log(err);
} else {
console.log("update success!");
}
});
});
mysql表如下
栏目|类型
--------------------------------------+
信息| tinyint(1) ......//1
--------------------------------------+
准时 |时间........//10:00:00
--------------------------------------+
关闭时间 |时间........//11:00:00
--------------------------------------+
运行时|时间........//01:00:00
--------------------------------------+
通过nodejs选择时间变量时,行返回“未定义”
如何接收正确的数据?
最佳答案
可能是因为参数绑定(bind)中表名和列名不能被参数替换。
关于mysql - Node.js mysql 选择时间变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52217789/