mysqlcn.js 586 B

123456789101112131415161718192021222324252627
  1. var mysql=require("mysql");
  2. var pool = mysql.createPool({
  3. host: '127.0.0.1',
  4. user: 'lee',
  5. password: 'xiaohei!b22',
  6. database: 'ser_list',
  7. port: 3888,
  8. charset:'utf8mb4'
  9. });
  10. exports.query = function(sql,callback){
  11. pool.getConnection(function(err,conn){
  12. if(err){
  13. callback(err,null,null);
  14. }else{
  15. conn.query(sql,function(qerr,vals,fields){
  16. //释放连接
  17. conn.release();
  18. //事件驱动回调
  19. callback(qerr,vals,fields);
  20. });
  21. }
  22. });
  23. };