Symfony PDO MySQL事务
作者QQ:67065435 QQ群:821635552
本站内容全部为作者原创,转载请注明出处!
参考代码
<?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');