PHPLOVER PHPLOVER - 2 months ago 14
PHP Question

How to make sure two MySQL queries are successful?

I have two MySQL queries in my PHP code.

Basically I need the two queries to execute (they are two INSERT) queries and both must be successful. If for example query1 is successful but query2 is not successful; I need to rollback query1 as both queries must be successful.

I am using MyISAM and I know I cannot do rollbacks etc but is there any way I can overcome my problem (another solution) to do what I want?

They both depend on each other as query1 stores data from form and query2 inserts some other details into another table (it's basically a counter) that tracks total counts for a referral system.

Answer Source

Sounds to me like you need transactions.

http://www.techrepublic.com/article/implement-mysql-based-transactions-with-a-new-set-of-php-extensions/6085922

They allow you to rollback an entire series of database modifications within a single transaction.