在express框架中使用连接池连接mysql
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)* */
相关推荐
huacuilaifa 2020-10-29
CoderToy 2020-11-16
emmm00 2020-11-17
王艺强 2020-11-17
ribavnu 2020-11-16
bianruifeng 2020-11-16
wangshuangbao 2020-11-13
苏康申 2020-11-13
vivenwan 2020-11-13
moyekongling 2020-11-13
云中舞步 2020-11-12
要啥自行车一把梭 2020-11-12
aydh 2020-11-12
kuwoyinlehe 2020-11-12
minerk 2020-11-12
vitasfly 2020-11-12
jazywoo在路上 2020-11-11
敏敏张 2020-11-11