MySQL Transactions

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");

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.

About Scott Allen

Scott Allen is from Indianapolis, Indiana. He has been working with HTML, CSS, PHP, & MySQL since the late 1990s, and has extensive experience in database design and development, server-side scripting, content management, and front-end user experience in both client services and in-house settings. You can connect with Scott on Twitter or via email.
This entry was posted in Code, Tech and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *