PHPLOVER PHPLOVER - 4 months ago 27
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.

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