mirror of
https://github.com/Steffo99/registro-fermi.git
synced 2024-11-21 23:54:28 +00:00
55 lines
943 B
JavaScript
55 lines
943 B
JavaScript
/* Copyright © 2016 Stefano Pigozzi, Emiliano Maccaferri
|
|
* Released under the GPL v3 license
|
|
*/
|
|
|
|
var mysql = require("mysql");
|
|
var fs = require("fs");
|
|
var config = JSON.parse(fs.readFileSync("config.json", "utf8"));
|
|
|
|
var connection = mysql.createConnection({
|
|
|
|
host: config.host,
|
|
password: config.db_pass,
|
|
user: config.db_user,
|
|
database: config.database
|
|
|
|
});
|
|
|
|
function connect(){
|
|
|
|
connection.connect(function(err){
|
|
|
|
if(!err){
|
|
|
|
console.log("API connessa al database MySQL!");
|
|
|
|
}else{
|
|
|
|
console.log("Errore durante la connessione!", err);
|
|
connection.end();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
connection.on('error', function(err) {
|
|
console.log('db error', err);
|
|
connection.end();
|
|
|
|
connection = mysql.createConnection({
|
|
|
|
host: config.host,
|
|
password: config.db_pass,
|
|
user: config.db_user,
|
|
database: config.database
|
|
|
|
});
|
|
|
|
connect();
|
|
});
|
|
|
|
}
|
|
|
|
connect();
|
|
|
|
module.exports = connection;
|