Hi friends of the group!
I am mad with this issue.
I cant save in DB with connection.query() if I set a while with a pause.
Its very strange.
Any idea?
Thanks !
___________________________________________________
//npm install mysql
var mysql = require('mysql');
var connection = mysql.createConnection({
host: 'localhost',
user: 'myUser',
password: '******',
database: 'myDB',
port: 3306
});
connection.connect(function(error){
if(error){throw error;}else{console.log('Conected to mySQL');}
});
//LOOP//
while(true){
console.log("Loop!");
save_bd();
sleepFor(1000); //<------------- If remove this line the data is saved in the DB each while loop ¿¿??////////////////
}
//FUNCTIONS//
function save_bd(){
connection.query("UPDATE myTable SET myTime='"+new Date().getTime()+"' WHERE Id='1'", function(errors, rowss){
if(errors){ throw errors;}else{
console.log("Why not Saved?");
}});//END query_read_data
}
function sleepFor( sleepDuration ){
var now = new Date().getTime();
while(new Date().getTime() < now + sleepDuration){ /* do nothing */ }
}