Symfony PDO MySQL事务

  1. 参考代码
    <?php
    $dbh = new DoctrineDbalDefaultConnection();
    $colume = 0;
    $colume1 = 1;
    try {
     $dbh->beginTransaction();
     $sql = <<<SQL
    INSERT INTO table(
     colume
    ) VALUES (
     :colume
    )
    SQL;
     $sth = $dbh->prepare($sql);
     $sth->bindParam('colume', $colume);
     $sth->execute();
     $id = $dbh->lastInsertId();
     unset($sth);
     $sql = <<<SQL
    INSERT INTO table1(
     colume1
    ) VALUES (
     :colume1
    )
    SQL;
     $sth = $dbh->prepare($sql);
     $sth->bindParam('colume1', $colume1);
     $sth->execute();
     unset($sth);
     $dbh->commit();
    } catch (\Exception $e) {
     die($e->getMessage());
    }
    die('Success');
    

results matching ""

    No results matching ""