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

时间:2018-06-13 13:47:01

标签: mysql node.js express

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

从DAO

读取数据行[0]的结果

我如何从记录ex:'0001'获取数据?请帮助感恩

DAO

var license = db.Licenses.Where(l => l.ID == LicenseId).FirstOrDefault();
var users = license.Users.ToList();


if (users != null)
{
    foreach (var user in users)
    {
         license.Users.Remove(user);
    }                   
}

模型



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

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

1 个答案:

答案 0 :(得分:0)

我认为查询语句中的错误,请尝试这个。

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