$Model = M(); $Model->startTrans(); $userRes = $Model->table('test_user')->add(['name'=>'admin']); $keyRes = $Model->table('test_key')->add(['key'=>'test']); $taskRes = $Model->table('test_task')->add(['task'=>'test']); if (userRes && $keyRes && $taskRes) $Model->commit(); else $Model->rollback();
ENGINE=MyISAM 会导致回滚失败
需要修改成 InnoDB 引擎:
mysql> alter table `test_user` engine=innodb;