Complete the code to start a transaction in PHP PDO.
<?php
$pdo->[1]();
?>The beginTransaction() method starts a new transaction.
Complete the code to commit a transaction in PHP PDO.
<?php
$pdo->[1]();
?>The commit() method saves all changes made during the transaction.
Fix the error in the code to rollback a transaction in PHP PDO.
<?php
$pdo->[1]();
?>The rollback() method cancels all changes made during the transaction.
Fill both blanks to correctly handle a transaction with error catching.
<?php try { $pdo->[1](); // some database operations $pdo->[2](); } catch (Exception $e) { $pdo->rollback(); } ?>
Start the transaction with beginTransaction() and save changes with commit(). If an error occurs, rollback cancels changes.
Fill all three blanks to handle a transaction with error catching and rollback.
<?php try { $pdo->[1](); $stmt = $pdo->[2]("INSERT INTO users (name) VALUES ('John')"); $stmt->execute(); $pdo->[3](); } catch (Exception $e) { $pdo->rollback(); } ?>
Start the transaction with beginTransaction(), prepare the SQL statement with prepare(), and commit changes with commit(). If an error occurs, rollback cancels changes.