Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Does Phalcon do implicit commints when saving Models?

I'm (trying to) wrap the saving of a model in a transaction, but even after a rollback, the new record still gets committed.

In my model, I begin a transaction in beforeSave(). Then in afterSave() I do some other stuff, then commit or rollback. The begin and rollback are being executed, but the query isn't rolled back.

My query log:

22933 Query     INSERT INTO `interaction` (`id_person`, `date_created`, `date_edited`, `id_created`, `id_edited`, `int_type`, `status`) VALUES ('myUsername', DEFAULT, '2018-03-15 15:10:17', 'myUsername', 'myUsername', 7, DEFAULT)
22933 Query     SELECT IF(COUNT(*) > 0, 1, 0) FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_NAME` = 'interaction_corepie' AND `TABLE_SCHEMA` = DATABASE()
22933 Query     DESCRIBE `interaction_corepie`
22934 Query     ROLLBACK

The record created by that INSERT statement doesn't get rolled back.

edited Mar '18

Yes, PDO use autocommit by default.
You can try to disable autocommit in the PDO instance


It looks like that worked. Thanks.

[Removed my initial reply because the cause of the problem stated in that reply was unrelated]