PHP | MYSQL | Nested PDO::beginTransition() and PDO::commit() on different DBs

Im facing up a doubt: what happen if i disable autocommit for 2 different connections to 2 different databases, in a nested way?

Example code:

 $conn = new MainDB(); // DB class
 $conn_second = new NotMainDB(); // another DB class

try {

    $conn->dbh->beginTransaction(); // disable autocommit
    $conn_second->dbh->beginTransaction(); // disable autocommit on 2nd DB

    $run = $conn->dbh->prepare(/* UPDATE STATEMENT */);
    $run->execute();

    $run = $conn->dbh->prepare(/* ANOTHER UPDATE STATEMENT */);
    $run->execute();

    $ssp = $conn_second->dbh->prepare(/* AN INSERT STATEMENT ON ANOTHER DB */);
    $ssp->execute();

    $conn_second->dbh->commit();
    $conn->dbh->commit();
} catch (Exception $ex) {

    $conn->dbh->rollBack();
    $conn_second->dbh->rollBack();
}

is there anything i have to take care of? anyone already experienced such a case?

thanks


Source: mysql

Leave a Reply