Jump to content

MySQL Transactions

Recommended Posts

Hi all,I'm trying to execute the following query from PHP

SET AUTOCOMMIT=0;START TRANSACTION;	INSERT INTO `viagens` (origem, destino, matricula, dataPartida, dataChegada, descricao, iva, preco) VALUES (1, 2, '123456',  DATE_FORMAT('2008/02/24 10:40','%Y/%m/%d %H:%i'), DATE_FORMAT('2008/02/28 12:00','%Y/%m/%d %H:%i'), 'excelente viagem :)', 21, 16);	SELECT @last:=max(idViagem) FROM viagens;INSERT INTO `viagensLocaisTuristicos` (idViagem, codigoLocal, dataPassagem) VALUES (@last,2,DATE_FORMAT('2008/02/26 15:15','%Y/%m/%d %H:%i'));	INSERT INTO `viagensLocaisTuristicos` (idViagem, codigoLocal, dataPassagem) VALUES (@last,1,DATE_FORMAT('2008/02/24 13:00','%Y/%m/%d %H:%i'));COMMIT;

and I'm always receiving the 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 ';START TRANSACTION;	INSERT INTO `viagens` (origem, destino, matricula, dataPar' at line 1

I'm not sure if I can execute all query at the same time or if I must execute each instruction separatly: something like

mysql_query("SET AUTOCOMMIT=0;", $Rcon);mysql_qeury("START TRANSACTION;", $Rcon);//insert operationsmysql_query("COMMIT;", $Rcon);

This way seems stupid because I will need a loop to execute all insert operations when I could send one query with all script.Thanks in advance.

Share this post

Link to post
Share on other sites

The error message is indicating that there is a problem with the first line, with the autocommit line. Check the documentation for MySQL to see what syntax you need to use there.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...