CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2009
    Posts
    160

    excute all queries else roll back php/mysql

    i had a question in mind like how the banking roll back works.... Lets say i am executing 4 queries one after the other, how can i do it in a way that either all queries get executed or none..... do i automatically have the functionality to rollback the changes made by query 1 and 2 incase 3 and 4 were not execute?

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: excute all queries else roll back php/mysql

    There's nothing directly built into MySQL. But, here's what I'd do...it requires using a primary key. But, every table you create should have some sort of key for faster indexing!

    • Before executing the queries, create a temp table.
    • As you perform each query, insert the backup data into the temp table.
    • If a query errors out, update each of the rows using the temp table.


    Code:
    CREATE TEMPORARY TABLE tmp_tbl LIKE test_tbl;
    INSERT INTO tmp_tbl SELECT * FROM test_tbl WHERE id = 4;
    DELETE FROM test_tbl WHERE id = 4;
    INSERT INTO test_tbl SELECT * FROM tmp_tbl WHERE id = 4;
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured