1 //mysql模块简单实用操作 2 3 var mysql = require('mysql'); 4 5 mc = {}; 6 7 8 var dbconfig = { 9 host : 'xxxxxxxxxx', 10 user : 'xxx', 11 password : 'xxx', 12 database : 'xxxxx' 13 }; 14 15 16 17 mc.sqlExc = function (sql, next) { 18 var db = mysql.createConnection(dbconfig); 19 db.connect(); 20 db.query(sql, function (err, rows) { 21 if (err) { 22 return next(err) 23 } 24 db.end(); 25 next(null, rows); 26 }); 27 28 } 29 module.exports = mc;