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 */ } 
}



-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/50ef3634-6e9d-4a36-9f55-121cc22427c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to