Two phase commit takes place when the transaction spread across more than one transaction manager.
The primary transaction manager who wants to do the COMMIT inquires to other transaction managers about their status ,i.e - whether ready to COMMIT or not. This is "Preparation phase" (First phase). If any of the other tarnsaction manager replies about its inability , the primary transaction manager issues a ROLLBACK command.
In the next step, when all the transaction managers are ready to COMMIT, the primary transaction manager issues the actual COMMIT statement. This is called "Commit PHase" (Second Phase).