Jump to content

php and mysql transaction issue


ajoo

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
https://forums.phpfreaks.com/topic/286950-php-and-mysql-transaction-issue/
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).

Archived

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

×
×
  • 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.