var express = require('express'); //引入express模块
var mysql = require('mysql'); //引入mysql模块
var app = express(); //创建express的实例
var connection = mysql.createConnection({ //创建mysql实例
host: 'localhost',
user: 'root',
password: '123456',
port: '3306',
database: 'littledream',
useConnectionPooling: true
});
connection.connect(function (err) {
if (err) {
console.error('连接失败: ' + err.stack);
return;
}
console.log('连接成功 id ' + connection.threadId);
});
app.get('/list', function (req, res) {
var selectSQL = "SELECT * FROM websites";
connection.query(selectSQL,function (err, results) {
if (err) {
console.log(err);
}
res.send(results);
})
});
// connection.end();
app.listen(3000, function () { ////监听3000端口
console.log('Server running at 3000 port');
});
网友评论