I need to make a query every X amount of time.
I am running node version 0.8.12 and the latest node mysql
When running the following code
function testmysql()
{
mysqlCon.connect();
mysqlCon.query('SELECT 1 + 1 AS solution', function(err, rows, fields) {
if (err) throw err;
console.log('The solution is: ', rows[0].solution);
});
mysqlCon.end();
}
var period = 2000;
var interval = setInterval(function(){
testmysql();
}, period);
I get the following error.
\nodetest\node_modules\mysql\lib\protocol\Protocol.js:95
.on('packet', function(packet) {
^
TypeError: Cannot call method 'on' of undefined
at Protocol._enqueue (\nodetest\node_modules\mysql\lib\protocol\Protocol.j
s:95:6)
at Protocol.handshake (\nodetest\node_modules\mysql\lib\protocol\Protocol.
js:37:41)
at Connection.connect (\nodetest\node_modules\mysql\lib\Connection.js:37:1
8)
at testmysql (\nodetest\index.js:1112:10)
at Timer.<anonymous> (\nodetest\index.js:1143:1)
at Timer.exports.setInterval.timer.ontimeout (timers.js:234:14)
Though when testmysql() is not in another function it runs correctly.
What am I doing incorrectly?
or rather how would I perform this loop query?
Thanks
ok… I deconstructed the project line by line… and the code that was causing it was this –
I was using this snippet because node_redis was throwing an error or warning of a memory leak due to the max listeners limit every time someone would join as I am using redisstore with socket.io. I Removed the code and I am no longer getting the memory leak errors perhaps because I took the latest node_redis version.
So sorry for the trouble and thanks for the help.