CDbTransaction is inactive and cannot perform commit or roll back operations.

Does anyone have a solution to this problem - my code is exactly as in the transaction example.

Do you need any additional libraries to run Yii e.g. pdo_mysql?

Thanks for your help.

MySQL only support transactions with certain DB formats (Innodb if I remember correctly, and not MyISAM). It will just act as a dummy when transactions are not supported by the DB. Are you sure you have the correct DB format?

If you use Yii’s DAO or AR functionalities you do need pdo_mysql for a MySQL database, but if you get no obvious connection errors, you probably have those installed already ;)

Wow thanks for your quick response - I’ve checked and the table is definitely InnoDB. As far as I can see I’ve used the same code for Yii framework 1.0.11 where it worked and 1.1 which I’m currently using and where it fails.

Is there anything within the framework that would affect transactions?

Thanks again for your speed!

It turns out using something like findByPK on a table where a primary key isn’t defined causes an error.

This is picked up in the catch block of the transaction so it’s always worth checking the message of the exception raised.

For future researchers of this error message:

I got this exception upon calling rollback after my code had already erroneously called commit. It was obvious once I found it, the transaction was inactive because it had been committed already. I imagine the same thing would happen on the 2nd call of any combination of commit() and rollback(). :rolleyes:

After 2 year I found this problem :). I have used rollback() in a catch(CException $ce) block and was executing for another CExeption after commit. So I think best practice is to do is use rollback() within catch(CDbException $ce) block. Thanks

Thank a lot for an invaluable answer. :) thump up !