This manual has been archived. Visit the new manual here.
RedBeanPHP
 

Transactions

RedBeanPHP offers three simple methods to use database transactions: begin(), commit() and rollback(). A transaction is a unit of work performed within a database management system (or similar system) against a database, and treated in a coherent and reliable way independent of other transactions. To begin a transaction use R::begin(), to commit all changes to the database use R::commit() and finally to rollback all pending changes and make sure the database is left untouched use R::rollback(). Usage:


    R
::begin();
    try{
        
R::store($page);
        
R::commit();
    }
    catch(
Exception $e) {
        
R::rollback();
    }

The RedBeanPHP transactional system works exactly like conventional database transactions. Because RedBeanPHP throws exceptions, you can catch the exceptions thrown by methods like R::store(), R::trash(), R::associate() etc, and perform a rollback(). The rollback() will completely undo all the pending database changes.

If you are new to transactions, consider reading about database transactions first.

Note about auto-commits

Many databases automatically commit after changing schemas, so make sure you test your transactions after R::freeze(true); !


 
 

RedBeanPHP Easy ORM for PHP © 2013 Gabor de Mooij and the RedBeanPHP community - Licensed New BSD/GPLv2