I’m trying to get transactions to work properly without success.
The following is the code, one of the sql-statements is broken on purpose($sql2)
but why does $sql1 still insert?
$conn = yii::app()->db;
$transaction = $conn->beginTransaction();
try
{
$sql1 = "INSERT INTO tbl_test (Author, Comment)VALUES('TestAuthor','testComment')";
$sql2 = "INSERT INTO tbl_test Comment VALUES('Comment')";
$conn->createCommand($sql1)->execute();
$conn->createCommand($sql2)->execute();
$transaction->commit();
}
catch(Exception $e)
{
$transaction->rollBack();
}