文件名称:node.js mysql
文件大小:1KB
文件格式:JS
更新时间:2021-09-09 09:29:14
node.js
var express = require('express'); var router = express.Router(); var app = require('../app.js'); var mysql = require('mysql'); var connection = mysql.createConnection({ host:'localhost', user:'root', password:'kalo376365', database:'test' }); var sql = 'SELECT * FROM user'; var addSql = 'INSERT INTO user(id,name,age,gender) VALUES(?,?,?,?)'; connection.connect(); /* GET users listing. */ router.get('/getSecret/:id',function(req,res,next){ console.log('function 1') next() }, function(req, res, next) { res.send('respond with a secret'+req.params.id); console.log('function 2') connection.query(sql, function(err, result){ if (err) { console.log(err.message); app.writeLog('error','query database', {message: err.message}); return; } app.writeLog('info', 'query database', {result:result}); }); });