var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
var kk ='The solution is:';
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
port : '3306',
user : 'root',
password : '123456',
database: 'django'
});
//res.write("hello");
connection.connect();
connection.query('SELECT * FROM app1_person order by id desc limit 1', function(err, rs, fields) {
if (err) throw err;
console.log(rs);
//console.log(fields);
kk+=rs[0].name;
console.log('The solution is: ', rs[0].name);
res.send(200,rs); //直接发api
res.render('index', { title: 'Hello Express '+kk });
});
connection.end();
});
module.exports = router;