Im working on a project with Nuxt.Js, Express and MySQL.
Im trying to insert data to two tables using MySQL transactions, explained here.
Here is an example of my code:
app.post('/temp', function (req, res) {
var sql = "BEGIN; INSERT INTO temp (number) VALUES (2); INSERT INTO project (name) VALUES ('test'); COMMIT;";
connection.query(sql, function (err, rows) {
if (err) throw err
res.send(rows)
})
})
The
INSERT INTO temp (number) VALUES (2)
and
INSERT INTO project (name) VALUES ('test')
work fine on their own so it seems there is a problem with the transaction syntax?
I'm getting an "ER_PARSE_ERROR" error which to my understanding means that there is simply and error with MySQL syntax.
And why I need to do it in one sql query is because I have a situation similiar to this.
EDIT -------------------------------------------------------------------------------------------------------
The query works fine in localhost/phpmyadmin so the problem might actually not be in the sql query.