Transactions

The ability to group SQL statements into groups that can be committed or rolled back en masse is only available in the InnoDB table handler in MySQL - MyISAM does not support transactions, and will silently ignore any transaction-control statements. To get started with a transaction, send the "BEGIN" SQL statement through mysqli_query(), followed by as many statements as you want, then either "COMMIT" or "ROLLBACK" to save or abort your changes.

Changed made inside transactions are, by default, visible only to yourself - once you use COMMIT, the changes are made permanent, and everyone can see them. Once you use COMMIT or ROLLBACK, you need to use another BEGIN to start a new transaction.

 

Want to learn PHP 7?

Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!

If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!

Next chapter: MySQL Improved >>

Previous chapter: Choosing a table type

Jump to:

 

Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.