var mysql = require("mysql");
var connection = mysql.createConnection({
host: '127.0.0.1',
user: 'root',
password: '123456',
database: 'userDB'
})
connection.connect();
module.exports.getdata = function(callfun) {
var sql = "select * from user";
connection.query(sql, function(err, data) {
console.log(err, data, "数据库返回的数据");
callfun(data);
})
}
module.exports.getone = function(id, callfun) {
var sql = "select * from user where id=" + id;
connection.query(sql, function(err, data) {
console.log(err, data, "查询单条数据");
callfun(data);
})
}
05-12
7671
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
10-30
207
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-15
2324
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)