Give an example of Transaction with commit and rollback?

Last updated 5 years, 8 months ago | 754 views 75     5


PHP-MySQL | Transaction with commit and rollback

try {
    // First of all, let's begin a transaction

    // 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');
} catch (Exception $e) {
    // An exception has been thrown by try
    //This function have all the things which you want to rollback.