var mysql=require("mysql"); var pool = mysql.createPool({ host: 'localhost', user: 'root', password: '123456', database: 'test1', port: 3306 }); var query = function(sql,callback){ pool.getConnection(function(err,connection){ if(err){ callback(err,null,null); }else{ connection.query(sql, function (error, results, fields) { //执行查询语句 connection.release(); // callback(err,results,fields); }); } }); // conn.end(); }; module.exports = query;