MySQL query variables in node
mysql, node.js
Solution
i search this post by google and i found the reason why variables not work try this it's work for me:
var connection = mysql.createConnection({multipleStatements: true});
by default node-mysql will only execute only one query on time if you've enabled the multipleStatements on create connect setting then your code should work. hope it work for you.
Problem
I'm having trouble with this query in NodeJS. ``` SET @i = 0; SELECT POSITION FROM ( SELECT name, @i:=@i+1 AS POSITION FROM database.table ti WHERE name='Johny' ORDER BY points ASC) t WHERE name='Johny' ``` Query works in Heidi SQL without a problem, but when i execute it in Node, i get callback is undefined. NodeJS code : ``` var query = "SET @i = 0;" + " SELECT POSITION FROM (" + " SELECT name, @i:=@i+1 AS POSITION" + " FROM database.table ti WHERE name='Johny' ORDER BY points ASC) t WHERE name='Johny'"; mySQLconnection.query(query,function(err,rows){ console.log(rows); }); ``` Thank You in advance,