I want to execute multiple insert queries with LAST_INSERT_ID() My table1 have AUTO_INCREMENT on id_column:
var valueTable1 = {value1: 'foo'};
var valueTable2 = {value2: 'bar'};
connection.query('INSERT INTO table1 SET ?; ' +
'INSERT INTO table2 SET ?, `id_table_1`=LAST_INSERT_ID();',
[valueTable1, valueTable2]});
I have error : ER_PARSE_ERROR: You have an error in your SQL syntax;
What might be the problem here?
EDIT: I finally succeeded:
var valueTable1 = {value1: 'foo'};
var valueTable2 = {value2: 'bar'};
connection.query('INSERT INTO table1 SET ?', valueTable1, function(err,sqlInfo){
if(err){
console.error(err);
}else{
valueTable2.id_value = sqlInfo.insertId;
connection.query('INSERT INTO table2 SET ?', valueTable2,function(err){
if(err){
console.error(err);
}
}
}
});