Guest User

Untitled

a guest
Jul 16th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. var mysql = require('mysql');
  2. var config = require('./config.json');
  3.  
  4. function getConnection() {
  5. var params = {
  6. host : config.host,
  7. user : config.user,
  8. password : config.password,
  9. database : config.database
  10. };
  11.  
  12. return mysql.createConnection(params);
  13. };
  14.  
  15.  
  16. module.exports = {
  17. fetchUsers: function(callback) {
  18. var connection = getConnection();
  19.  
  20. connection.query('SELECT * FROM USER', function (error, results, fields) {
  21.  
  22. if (error) throw error;
  23. console.log('Query: ', results);
  24. callback(results);
  25. });
  26.  
  27. connection.end();
  28. }
  29. };
Add Comment
Please, Sign In to add comment