I'm trying to use a mysql transaction query over php mysqli query like this:
$sql = "START TRANSACTION;
INSERT INTO songs (title, disco, deleted) VALUES ('".$titol."', '".$codi."', '0');
SET @last_id = LAST_INSERT_ID();
INSERT INTO lyrics (`lyricsOri`, `lyricsTra`, `song`, `deleted`) VALUES ('".$lyricsO."', '".$lyricsT."', @last_id, 0);
COMMIT;";
connection()->query($sql);
If I get the $sql
value after it and copy-paste as sql command into php my admin, it runs nice and it does what it's supposed to do but, when I run this through php it does not work and I can't figure out why.
I know I could use php native transaction, setting it auto_commit(FALSE) and adding the different queries on it to finaly commit it, but in this case I would like to use a mysql command "as is" and I can't find why it's not working properly.
Anyone see the fault or can tell me why it does not work?
Thanks!