【发布时间】:2015-09-07 11:51:58
【问题描述】:
当SQL语句出现错误系统会自动回滚更改时,如何启动事务?
PHP + MySQL transactions examples
在 PHP 中
try {
// First of all, let's begin a transaction
$db->beginTransaction();
// A set of queries; if one fails, an exception should be thrown
$db->query('first query');
$db->query('second query');
$db->query('third query');
// If we arrive here, it means that no exception was thrown
// i.e. no query has failed, and we can commit the transaction
$db->commit();
} catch (Exception $e) {
// An exception has been thrown
// We must rollback the transaction
$db->rollback();
}
如何在没有PHP,只有MYSQL的情况下重复逻辑
【问题讨论】: