mysql模块简单实用操作-----nodejs

 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;

 

posted @ 2016-03-03 11:33  zy_hrb  阅读(524)  评论(0编辑  收藏  举报