Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
<?php $pdo->beginTransaction(); try { // Debit account A $pdo->prepare("UPDATE accounts SET balance = balance - :amount WHERE id = :id") ->execute(["amount" => $amount, "id" => $fromId]); // Credit account B $pdo->prepare("UPDATE accounts SET balance = balance + :amount WHERE id = :id") ->execute(["amount" => $amount, "id" => $toId]); $pdo->commit(); echo "Transfer complete"; } catch (PDOException $e) { $pdo->rollBack(); throw new RuntimeException("Transfer failed: " . $e->getMessage(), 0, $e); }
Result
Open