關於nodejs中的增刪改查

1.增長sql

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

2.刪除spa

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

3.修改io

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

 

4.查詢date

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

相關文章
相關標籤/搜索