董雅真好看

关于nodejs中的增删改查

1.增加

router.post('/insert',function(req,res){
  var name = req.body.name;
  var num = req.body.num;
  var job = req.body.job;
  var sql = `insert into user (name,num,job) values ("${name}","${num}","${job}")`
  mc.query(sql,function(err,data){
    res.send(data);
  })
})

2.删除

router.post('/delete',function(req,res){
  var id = req.body.id;
  var sql = `delete from user where id = ${id}`;
  mc.query(sql,function(err,data){
    res.send(data);
  })
})

3.修改

router.post('/update',function(req,res){
 var id = req.body.id;
 var num = req.body.num;
 var name = req.body.name;
 var job = req.body.job;
 var sql = `update user set name="${name}",num="${num}",job="${job}" where id=${id}`;
  mc.query(sql,function(err,data){
  res.send(data);
 })
})

 

4.查询

router.post('/main',function(req,res){
  var sql = `select * from user where name like “%name%“`;
  mc.query(sql,function(err,data){
    res.send(data);
 })
})

 

posted on 2019-06-09 12:01  董雅真好看  阅读(2255)  评论(0编辑  收藏  举报

导航