mysqldb.js 834 B

123456789101112131415161718192021222324252627282930313233343536
  1. var db = {};
  2. var mysql = require('mysql');
  3. // var pool = mysql.createPool({
  4. // connectionLimit : 10,
  5. // host : '115.231.62.138',
  6. // user : 'vehicle',
  7. // password : 'vehicle',
  8. // database : 'guncontrol'
  9. // });
  10. var pool = mysql.createPool({
  11. connectionLimit : 10,
  12. host : '192.168.8.90',
  13. user : 'zwsy',
  14. password : 'zwsy@123',
  15. database : 'zwsy',
  16. supportBigNumbers: true//处理BigInt
  17. });
  18. db.query = function(sql, callback){
  19. if (!sql) {
  20. callback();
  21. return;
  22. }
  23. pool.query(sql, function(err, rows, fields) {
  24. if (err) {
  25. console.log(err);
  26. callback(err, null);
  27. return;
  28. };
  29. callback(null, rows, fields);
  30. });
  31. }
  32. module.exports = db;