如何使用mysql-crud将此对象插入nodejs中的mysql数据库

时间:2017-04-27 07:44:48

标签: mysql sql node.js insert

我是 nodejs mysql 的新手。我想使用 nodejs 将一些数据插入 mysql 数据库。我曾尝试使用和不使用 mysql-crud 模块进行此操作,但我失败了。任何人都可以帮助我吗?

exports.insertquotereq = function(req, res){

        var chat_data = {
            to_country: req.whereto,
            to_airport: req.toairport,
            from_country: req.fromwhere,
            from_airport: req.fromairport,
            planetype: req.planetype,
            startdate: req.startdate,
            starttime: req.starttime,
            returndate: req.returndate,
            returntime: req.returndate,
            email: req.email,
            distance: req.distance,
            estimatedhrs: req.estimatedhrs,
            planecostperhr: req.planecostperhr,
            estimatedcost: req.estimatedcost,
            estimated_time: req.estimated_time
        };
        //console.log('chat_data',chat_data);
        var insert = connection.query("INSERT INTO chat SET ?", chat_data, function(err, result){
            if(err) throw err;
            console.log('data inserted'+insert);
        });

};

0 个答案:

没有答案