...automatically rollback? I'm writing an application that moves data from one MySQL database to another. I need to ensure that either all of the statements in this php block occur, or that none of them do, so that I am not left with a half-copied database and no idea where to fix it.

The problem is that a LOT of stuff can happen during this process, and depending on how much data is in the table, PHP can timeout.

I can, and will, increase the timeout on PHP, but in the future if this ever occurs again, I need to make certain that it doesn't leave me with half of a database.

If I use a START TRANSACTION; statement at the beginning of my PHP block, and a COMMIT; at the end, and PHP times out in the middle, will it automatically rollback all of the actions since the start of the transaction?

I'm new to "transactions" with databases, but this looks like the fix I need, I'm just not sure how much is handled automatically, or how much I need to worry about myself.