mysqler.js 653 B

123456789101112131415161718192021222324252627
  1. const mysql=require("mysql");
  2. const pool = mysql.createPool({
  3. host: 'db.1473.cn',
  4. user: 'root',
  5. password: 'usestudio-1',
  6. database: 'weibo'
  7. });
  8. const query=function(sql,options,callback){
  9. pool.getConnection(function(err,conn){
  10. if(err){
  11. console.log(err)
  12. callback(err,null,null);
  13. }else{
  14. conn.query(sql,options,function(err,results,fields){
  15. //释放连接
  16. conn.release();
  17. //事件驱动回调
  18. callback(err,results,fields);
  19. });
  20. }
  21. });
  22. };
  23. module.exports = query;