Jump to content

php and mysql transaction issue


ajoo
 Share

Recommended Posts

Hi, 

 

I am using transactions on a piece of code whose structure is somewhat like this 

 

if ( condition  )

{

   mysqli_autocommit($fcon, false);

   

    if ( condition  )

       { $query "   ";

 

          if ( condition  )

         { $query "     ";

 

             if ( condition )

              {  $make = makeTable();   // where this is a function which creates a table and uses a query like INSERT into ... to create an entry in a table

                  

                  if ( $make == true)

                    { $query "   ";

                            

                                if ( condition  )

                                    { $query "     ";

 
 
                                    }   

                              else 

                     else

 

and so on ending all else.

 

The problem is that the function call to makeTable prevents the roll back beyond that point. Please can someone tell me if  and how it would be possible to roll back all the way to the defined starting point at the very beginning of the code block.

 

Thanks all for any help, comments, suggestions.

 

  

 

  

 
 

    

 

 

Link to comment
Share on other sites

  • 2 weeks later...

If the makeTable() function is actually making a Table (i.e. CREATE TABLE), then it can NOT be rolled back. In fact ...

The statements listed in this section (and any synonyms for them) implicitly end any transaction active in the current session, as if you had done a COMMIT before executing the statement. As of MySQL 5.5.3, most of these statements also cause an implicit commit after executing; for additional details, see the end of this section.

(emphasis added -- see http://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html)

 

Why are you creating a table in the middle of a transaction. Either create the table before you start the transaction, or redesign your application and database so you don't have to create tables on the fly. (Personally, I highly recommend the second option).

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.