linkMysql.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. var mysql = require('mysql');
  2. var pool = mysql.createPool({
  3. host: '10.20.5.88',
  4. port: '14062',
  5. user: 'root',
  6. password: 'usestudio-1',
  7. database:'UseStudio_Upload'
  8. });
  9. // connection.connect();
  10. module.exports = {
  11. query: function(sql,callback){
  12. pool.getConnection(function(err,conn){
  13. if(err){
  14. console.log(err);
  15. return [];
  16. }else{
  17. conn.query(sql,function(qerr,vals,fields){
  18. //释放连接
  19. conn.release();
  20. //事件驱动回调
  21. callback(qerr,vals,fields);
  22. });
  23. }
  24. });
  25. },
  26. call: function(name, args, callback){
  27. var sql = 'CALL ' + name + '('+ (args.length>0? ("'"+ args.join("','") + "'"): '') + ')';
  28. pool.getConnection(function(err,conn){
  29. if(err){
  30. console.log(err);
  31. return [];
  32. }else{
  33. conn.query(sql,function(qerr,vals,fields){
  34. //释放连接
  35. conn.release();
  36. //事件驱动回调
  37. callback(qerr,vals,fields);
  38. });
  39. }
  40. });
  41. },
  42. end: function(){
  43. // connection.end();
  44. }
  45. };
  46. // var query=function(sql,callback){
  47. // };
  48. // module.exports=query;