Quick Question About Transactions... I Hope.

I was curious. Since you use transactions when doing model()->save(s). Could you do the same thing with command.

Examples of what I mean:

Example with ActiveRecord:




if ($someModel->save()) {

    $transaction->commit();

}



Example with Command:




if ($command->query()) {

    $transaction->commit();

}



Will it essentially perform the same way or will it not work at all? I couldn’t find anything on this specifically without seeing the one type of usage. Thanks in advance.

Yes, it will behave the same because the save() method just calls an insert/update statement. Remember that if using MySQL your tables should be using the InnoDB engine which is default. MyISAM does not support transactions.