从另一个文件调用回调? 节点 js express



为什么我不能将回调作为记录? 必须作为字段('id'( SS : https://prnt.sc/ju4xb2

从 DAO 读取结果作为数据行[0]

我如何从记录中获取数据,例如:"0001"? 请帮助感恩


var executeQuery = function(query,callback) {    
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '',
database: 'testt'
});
connection.connect();
connection.query(query, function(err, rows, fields) {
if (err) throw err;
connection.end();
console.log("Here in Dao: " + rows[0].mobile_phone);
callback(rows[0].mobile_phone);
});
};
module.exports = {
executeQuery: executeQuery
};


var DAO = require('../lib/database.js');
module.exports = {
getuser : function(id,callback){
var User =  DAO.executeQuery("select mobile_phone from ms_customer WHERE id = " + id, function(mobile_phone){
// var json = JSON.stringify(User);
console.log("Return from Dao = " +User);   
callback(mobile_phone);
});
}
}

控制器


test : function(req,res){
var customerModel = require('../model/customer');
customerModel.getuser('0001', function(mobile_phone){
console.log("return from model_user = " + mobile_phone);
});
},

我总是得到错误='ER_BAD_FIELD_ERROR:'where子句'中的未知列'0001'

我认为查询语句出错,请尝试此操作。

getuser : function(id,callback){
var User =  DAO.executeQuery("select mobile_phone from ms_customer WHERE id = '" + id + "';", function(mobile_phone){
// var json = JSON.stringify(User);
console.log("Return from Dao = " +User);   
callback(mobile_phone);
});
}
}

最新更新