Alright, let me get this out of the way first. My question is similar to this: Cannot rollback transaction in Zend Framework
My tables are always innoDB, always. I've checked the table in question and it is indeed innoDB. On to the problem..
I have a database instance, and model instances running through this transaction hitting the same database:
$db->beginTransaction();
try {
// Run an insert
$model_record->insert(array('single_item' => 'its value'));
// More logic, and run an update.
$model_record->this_value = 'that';
// Save it
$model_record->save();
//Commit the transaction
$db->commit();
} catch (Exception $e) {
// It finds the rollback, yet does nothing.
$db->rollBack();
}
Now, the reason I found this to not be working is I exceeded the character limit on a row during a test to make sure all the logic in place was correct.
It did not rollback. On top of that the record with 'single_item', was in the database. But the updated values, were not.
Am I completely missing something small, I've never had transaction issues with MySQL & innoDB. Could this be MySQL related or ZF related? Any insight is helpful, thanks.
Update:
I've been conducting a few more tests and here are a few results that might help:
$this->_db->beginTransaction();
// This works
$this->_db->insert('table_a',
array(
'a_field' => 'transaction test',
)
);
// This does not work, at all. It inserts and does not rollback. There is no commit.
$_table_a_model->insert(
array(
'a_field' => 'transaction test',
)
);
$this->_db->rollback();
Additional Update You need to get the instance of the model, and call a transaction on that.
$the_model = $this->_model->getAdapter();
$the_model->beginTransaction();
This leaves no room for transactions for multiple tables, without doing multiple transactions for each model instance. Any ideas out there without reverting to the base database instance?
I figured it out. I have to use $db = Zend_Db_Table_Abstract::getDefaultAdapter();
and then run my transactions off that so all operations in multiple models work together under a single transaction. If anyone has a fix for that, feel free to comment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With