I am trying to write a transaction with two INSERT INTOs that looks like this:
BEGIN;
INSERT INTO users VALUES('123', 0, 0, 0);
INSERT INTO inventory VALUES('123', 0, 0, 0, 0, 0);
COMMIT;
This Query works fine in the MySQL Workbench but not in my Code that I wrote in JavaScript:
app.post("/", (req, res) => {
db.query(`BEGIN;
INSERT INTO users VALUES('123', 0, 0, 0);
INSERT INTO inventory VALUES('123', 0, 0, 0, 0, 0);
COMMIT;`, (err, result) => {
if (err) throw err
res.status(200).send(result)
})
})
I am getting the Error: 1064, You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
I'm using the mysql2 Package in my JavaScript Backend.
Does anybody know why this problem occurs?
EDIT: I even tried START TRANSACTION instead of BEGIN