We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

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.

How Phalcon handles nested transactions in MySQL?

How nested transactions are handled by Phalcon in MySQL?

As far as I know MySQL don't support nested transactions. However MySQL 5.0.3 and up provides server-side support for XA transactions when using InnoDB engine.

I have MySQL 5.5 and am using InnoDB engine. Does Phalcon in such situation automatically use XA transactions?

If not, how nested transactions are handled then? By save points?

I believe Phalcon supports anything PDO supports. I don't know the answer - but you may be able to find information on whether or not PDO supports nested transactions.


I have analyzed the code of the following Phalcon 2.0 classes:


I wanted to find out how transactions works.

My founds:

(1) Phalcon supports nested transactions via savepoints only. It does not matter which database (dialect) we are using.

(2) In order the nesting works properly without any errors we need to switch the nesting ON in the bootstrap file in the following way:

$di->set('db', function () {

    $connection = new DbAdapter([
        //array with params here

    //switch the nesting ON

    return $connection;

If you don't do this, then nesting will not work. I think this is very important issue and it should be highlighted in the docs.


So the answer to my question is: the only way Phalcon supports nested transactions is via savepoint only (for all adapters). Phalcon don't support XA transactions in MySQL.