MySQL Forums
Forum List  »  PHP

Propper way of using transactions
Posted by: slowmo
Date: February 02, 2006 06:21PM

I would like to execute 3 insert queries, if one of them fails, there should be a rollback. What is the proper way of doing this? Must I execute each query separately using mysql_query() or I can execute whole script at a time like this:

START TRANSACTION;
INSERT INTO aaa......;
INSERT INTO bbb......;
INSERT INTO ccc.......;
COMMIT;

What if there is for example a sintax error in query 1? Will the transaction continue to be started and all the following mysql_query() calls won't just do anything until there is a COMMIT, or it will rollback automatically? If I am not mistaking, in MSSQL there is a way to use IF THEN ELSE within a script to check if execution of a single query has been completed with no errors. How is it in MySQL?

Options: ReplyQuote


Subject
Written By
Posted
Propper way of using transactions
February 02, 2006 06:21PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.