Stromgren Stromgren - 4 years ago 103
MySQL Question

Executing 'where in' statement with Mysqljs\mysql

I'm using mysqljs\mysql in a Node application and I've run into some trouble performing statements with 'in' clauses.

Under paramater escaping, the documentation states that:

Arrays are turned into list, e.g. ['a', 'b'] turns into 'a', 'b'

Escaping query values

But when i try something like this:

var sql = "SELET * FROM table WHERE name IN (?)";
var params = ['a', 'b', 'c'];
console.log(mysql.format(sql, params));

I get a query containing only the first value of the array:

"SELET * FROM table WHERE name IN ('a')"

Answer Source

Try this :

var params = [['a', 'b', 'c']];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download