MissFuTT 2020-06-16
const mysql=require(`mysql`)module.exports.sqlpoll=function () {let pool={config:{host:`localhost`, user:`root`, password:`123`, port:3306, database:`userinfo`, multipleStatements:true }, connection:function (sql,params,cb) {let db=mysql.createPool(this.config) db.getConnection(function (err,conn) {if(err){ console.log(err); } conn.query(sql,params,cb) db.releaseConnection(conn) //释放连接 //conn.release() 关闭连接 }) } }return pool}/*调用* var cd=require(``)* var db=cd.sqlpool() //要加(),得到返回值* db.connect(sql,params,cb)* */