gpt4 book ai didi

mysql - 从另一个文件调用回调? Node js表达

转载 作者:行者123 更新时间:2023-11-29 17:28:18 25 4
gpt4 key购买 nike

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

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

我如何从记录 ex: '0001' 获取数据?请帮忙谢谢

DAO



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);
});
}
}

Controller

 

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);
});
}
}

关于mysql - 从另一个文件调用回调? Node js表达,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50838879/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com