MySQL has the ability to handle what are known as transactions: a series of queries that must be executed in an all-or-none fashion. As a bonus, it’s super easy to use.
Using PHP, you can do the following:
mysql_query("START TRANSACTION"); mysql_query("CREATE TABLE table"); mysql_query("CREATE TABLE table"); mysql_query("COMMIT");
When MySQL receives the START TRANSACTION query, it won’t execute anything else until it receives a COMMIT query. Upon receiving the COMMIT query, everything in the transaction is executed, and if anything fails, it all fails.