1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| var express = require('express'); var router = express.Router(); var URL = require('url');
var mysql = require('mysql');
var connection = mysql.createConnection({ host:'localhost', user:'root', password:'123456', database:'jj' })
connection.connect();
var sql = "SELECT * FROM name"; var addSql = "INSERT INTO name(id,name,sex) VALUES(0,gary,man)";
router.get('/',function(req,res,next){ var params = URL.parse(req.url,true).query; var addSqlParams = [params.id,params.name,params.sex]; connection.query(addSql,addSqlParams,function(err,result){ if(err){ console.log("[INSERT ERROR] - ",err.message); return false; } }) connection.query(sql,function(err,result){ if(err){ console.log("[INSERT ERROR] -",err.message); return false; } console.log(params.id); res.send(result); }) }) module.export = router;
|