PHP

php db transaction

🩷 슈 🧑 2014. 9. 29. 14:24
728x90
SMALL

μ•„~ μ–Όλ₯Έ μ μš©ν•΄μ•Όκ² λ‹€.


νŠΈλžœμž­μ…˜ μ½”λ“œ μ μš©ν•˜κ³  μ˜ˆμ™Έμ²˜λ¦¬ν•˜κ³  λ‘œκ·Έλ„ μŒ“κ³ 


μ•ˆμ •ν™”λͺ¨λ“œμ— λ“€μ–΄κ°€μ•Ό ν•œλ‹€.


μ•„λž˜λŠ” db transaction μƒ˜ν”Œμ΄λ‹€.


try {
    // First of all, let's begin a transaction
    $db->beginTransaction();

    // A set of queries; if one fails, an exception should be thrown
    $db->query('first query');
    $db->query('second query');
    $db->query('third query');

    // If we arrive here, it means that no exception was thrown
    // i.e. no query has failed, and we can commit the transaction
    $db->commit();
} catch (Exception $e) {
    // An exception has been thrown
    // We must rollback the transaction
    $db->rollback(); 

} 

728x90
LIST