Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SqlConnection.js
- var mysql = require("mysql");
- var ptype = Connection.prototype;
- function Connection(host, port, user, password, database) {
- this.getHost = function () {
- return host;
- }
- this.getPort = function () {
- return port;
- }
- this.getUser = function () {
- return user;
- }
- this.getPassword = function () {
- return password;
- }
- this.getDatabase = function () {
- return database;
- }
- this.createNewConnection = function () {
- return mysql.createConnection({
- host: this.getHost(),
- user: this.getUser(),
- password: this.getPassword(),
- port: this.getPort(),
- database: this.getDatabase()
- });
- }
- this.openConnection = function () {
- var varr = this.createNewConnection();
- return varr.connect(function (err) {
- if (err) {
- console.log("There was an error with connecting" + err);
- } else {
- console.log("No error, connected successfully" /*WHY CANT I ACCESS this.getHost() here*/);
- }
- });
- }
- }
- module.exports.Connection = Connection;
Add Comment
Please, Sign In to add comment