MeekroDB Quick Start Docs FAQ
Download GitHub


DB::startTransaction(), DB::commit(), and DB::rollback()

Normally, these three commands are just shortcuts for START TRANSACTION, COMMIT, and ROLLBACK.

// only keep the password change if >3 people were affected
DB::query("UPDATE accounts SET password=%s WHERE password=%s", 'sdfwsert4rt', 'hello');
$counter = DB::affectedRows();
if ($counter > 3) {
  echo "$counter people just got their password changed!!\n";
} else {
  echo "Too few people got their password changed!\n";

When you enable DB::$nested_transactions, the transaction commands take on a special meaning. You can now use DB::startTransaction() within a transaction to "nest" transactions. This is accomplished internally with the SAVEPOINT feature in MySQL 5.5+.

DB::$nested_transactions = true;
// .. some queries..
$depth = DB::startTransaction(); // start nested transaction
echo "We are currently $depth transactions deep"; // 2

// .. some queries..
DB::commit(); // commit inner transaction
// .. some queries..
DB::commit(); // commit outer transaction