Jump to content

MySQL Transactions


[Coyot3]

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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...