/**
 * Remember change filename into connectdb.js
 * database login data is sensitive remember add into .gitignore
 */

/** mysql **/

var mysql = require('mysql');
var log4js = require('log4js');
var logger = log4js.getLogger('SYSTEM');

var localdebug = {
  host      : 'XXXX',
  port      : 'XXXX',
  user      : 'XXXX',
  password  : 'XXXX',
  database  : 'XXXX',
  charset   : 'utf8_unicode_ci'
};
var online = {
  host      : 'XXXX',
  port      : 'XXXX',
  user      : 'XXXX',
  password  : 'XXXX',
  database  : 'XXXX',
  charset   : 'utf8_unicode_ci'
};
var connect = mysql.createConnection(online);

//mysql- establishing connection
connect.connect(function(err){
    if(err){
      //console.error('error connect database: ' + err.stack);
      logger.error('error connect database! ');
      return;
    }
    else{
      //console.log('Sucessful establishing connection to database.');
      logger.info('Sucessful establishing connection to database.');
    }
});

function end(){
  connect.end( function(err) {
      if(err) throw console.error(err);
      else console.log("Successful disconnect from database");
  });
};

module.exports ={connect, end};
