phppdotransactionsrollbackautocommit

Autocommit with PDO


The rollback of my transaction doesn't work. How do I set autocommit to false (or 0) in the php script using PDO (I have InnoDB 5.7.18) ?

Here is my code:

     global $bdd;  //defined with PDO

       try {                             
            $bdd->beginTransaction();
            /* my requests */
            $bdd->commit();
        } catch (Exception $e) {
            $bdd->rollBack();
            return $e->getMessage();
        }

        return true;
    }

Solution

  • I solved my problem myself: a few of my tables were in MyISAM (whereas the majority are in InnoDB -> I work with an old database system...); so the rollback didn't work for these tables. Once I changed them into InnoDB, it worked. Thanks to everybody for the help !