Guest User

Untitled

a guest
Dec 24th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. SqlConnection.js
  2. var mysql = require("mysql");
  3. var ptype = Connection.prototype;
  4.  
  5. function Connection(host, port, user, password, database) {
  6. this.getHost = function () {
  7. return host;
  8. }
  9. this.getPort = function () {
  10. return port;
  11. }
  12. this.getUser = function () {
  13. return user;
  14. }
  15. this.getPassword = function () {
  16. return password;
  17. }
  18. this.getDatabase = function () {
  19. return database;
  20. }
  21. this.createNewConnection = function () {
  22. return mysql.createConnection({
  23. host: this.getHost(),
  24. user: this.getUser(),
  25. password: this.getPassword(),
  26. port: this.getPort(),
  27. database: this.getDatabase()
  28. });
  29. }
  30.  
  31. this.openConnection = function () {
  32. var varr = this.createNewConnection();
  33.  
  34. return varr.connect(function (err) {
  35. if (err) {
  36. console.log("There was an error with connecting" + err);
  37. } else {
  38. console.log("No error, connected successfully" /*WHY CANT I ACCESS this.getHost() here*/);
  39. }
  40. });
  41. }
  42. }
  43.  
  44. module.exports.Connection = Connection;
Add Comment
Please, Sign In to add comment