var mysql = require('mysql'); var pool = mysql.createPool({ host: '10.20.5.88', port: '14062', user: 'root', password: 'usestudio-1', database:'UseStudio_Upload' }); // connection.connect(); module.exports = { query: function(sql,callback){ pool.getConnection(function(err,conn){ if(err){ console.log(err); return []; }else{ conn.query(sql,function(qerr,vals,fields){ //释放连接 conn.release(); //事件驱动回调 callback(qerr,vals,fields); }); } }); }, call: function(name, args, callback){ var sql = 'CALL ' + name + '('+ (args.length>0? ("'"+ args.join("','") + "'"): '') + ')'; pool.getConnection(function(err,conn){ if(err){ console.log(err); return []; }else{ conn.query(sql,function(qerr,vals,fields){ //释放连接 conn.release(); //事件驱动回调 callback(qerr,vals,fields); }); } }); }, end: function(){ // connection.end(); } }; // var query=function(sql,callback){ // }; // module.exports=query;