如何使用 MySQL 在 Silverstripe 3.3 中使用交易?

How to use transactions in Silverstripe 3.3 with MySQL?

Silverstripe 3.3 是否支持 MySQL 交易?如果是这样,它可以与 ORM 一起使用吗?

我找不到关于此主题的任何文档。举个例子就好了。

正如 Shadow 提到的,您不必担心事务,因为 SilverStripe 会在内部处理它们。

也就是说,如果您需要明确地做某事,您可以这样做:

try {
    DB::getConn()->transactionStart();

    // do stuff...

    DB::getConn()->transactionEnd();
} catch (Exception $e) {
    DB::getConn()->transactionRollback();
}

参见 SS_Database - API documentation here