I am trying to do a bulk insert, and even followed the code found here: Stackoverflow Question
it only inserts the first row not sure why? Using nodejs with mysql.
var ethnicity_interested = [1, 2, 3];
var newEthArr = [];
ethnicity_interested.forEach(function(i) {
newEthArr.push([i, userObj.id])
})
var fields = "INSERT INTO User_Pref_Ethnicity (ethnicity_id, user_id) VALUES (?)";
var inserts = [
newEthArr
];
var sqlNewUser = mysql.format(fields, newEthArr);
connection.query(sqlNewUser, function(
error,
results,
fields
) {
if (error) {
console.log("insert User_Pref_Ethnicity err: " + error);
res.json({
http_code: 500,
error_message: 'Server Error: Please Try Again.'
});
} else {
storeUserPrefReligion();
}
});
I even tried to use the version in the example like so:
var fields = "INSERT INTO User_Pref_Ethnicity (ethnicity_id, user_id) VALUES ?";
var inserts = [
newEthArr
];
///var sqlNewUser = mysql.format(fields, newEthArr);
connection.query(fields, newEthArr, function(
and I get this error:
insert User_Pref_Ethnicity err: Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '2, 2' at line 1