I am doing an application with Node js, Express and MySQL. I am running on localhost with XAMPP, not sure if this information is important. I want to insert multiple rows in my database, so I did:
db.query('INSERT INTO tasks (done, user_id, task) VALUES ?', values, (err, result) => {
if(err) {
console.log(err);
}
console.log("done");
});
where values
is an array of arrays containing each a triplet (done, user_id, task), example [[0, 10, 'foo'], [1, 10, 'bar']]
. However, when this snippet runs with more than one array in values
it gives me an error like
Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '0, 10, 'test'' at line 1
What am I doing wrong? Is there another way to insert multiple rows?
** EDIT: ** My problem is multiple row insertion, I know that the generated query has the wrong syntax, but according to this accepted answer my Javascript syntax sould be correct