トランザクションpublic function transferMoney($fromAccountNumber, $toAccountNumber, $amount) { // get the PDO connection object from Propel $con = Propel::getConnection(AccountPeer::DATABASE_NAME); $fromAccount = AccountPeer::retrieveByPk($fromAccountNumber, $con); $toAccount = AccountPeer::retrieveByPk($toAccountNumber, $con); $con->beginTransaction(); try { // remove the amount from $fromAccount $fromAccount->setValue($fromAccount->getValue() - $amount); $fromAccount->save($con); // add the amount to $toAccount $toAccount->setValue($toAccount->getValue() + $amount); $toAccount->save($con) $con->commit(); } catch (Exception $e) { $con->rollback(); throw $e; } } http://www.propelorm.org/wiki/Documentation/1.4/Transactions |
|