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

wnvonmuf  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(251)

为什么我不能把回拨作为记录?必须作为字段('id')ss:https://prnt.sc/ju4xb2
从dao读取结果作为数据行[0]
如何从记录ex:'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);
      });
    },

我总是得到error='er\u bad\u field\u error:'where子句'中的未知列'0001'

hc8w905p

hc8w905p1#

我想查询语句出错了,请试试这个。

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

相关问题