Give an example of Transaction with commit and rollback?
PHP-MySQL | Transaction with commit and rollback
try {
// First of all, let's begin a transaction
$db->beginTransaction();
// A set of queries; if one fails, an exception should be thrown which we are handling at bottom
$db->query('1 query exe');
$db->query('2 query exe');
$db->query('3 query exe');
$db->commit();
} catch (Exception $e) {
// An exception has been thrown by try
//This function have all the things which you want to rollback.
$db->rollback();
}