📅  最后修改于: 2021-01-07 09:26:22             🧑  作者: Mango
Phalcon支持事务处理,因为它与PDO关联。为了提高数据库的性能,我们可以执行数据操作。下面是应用事务的数据库结构:
begin();
// Execute some SQL statements
$connection->execute('DELETE 'company' WHERE 'id' = 101');
$connection->execute('DELETE 'company' WHERE 'id' = 102');
$connection->execute('DELETE 'company' WHERE 'id' = 103');
// Commit if everything goes well
$connection->commit();
} catch (Exception $e) {
// An exception has occurred rollback the transaction
$connection->rollback();
}
//数据库“公司”数据已删除。
begin();
// Execute some SQL statements
$connection->execute('DELETE 'company' WHERE 'id' = 101');
try {
// Start a nested transaction
$connection->begin();
// Execute these SQL statements into the nested transaction
$connection->execute('DELETE 'company' WHERE 'id' = 102');
$connection->execute('DELETE 'company' WHERE 'id' = 103');
// Create a save point
$connection->commit();
} catch (Exception $e) {
// An error has occurred, release the nested transaction
$connection->rollback();
}
// Continue, executing more SQL statements
$connection->execute('DELETE 'company' WHERE 'id' = 104');
// Commit if everything goes well
$connection->commit();
} catch (Exception $e) {
// An exception has occurred rollback the transaction
$connection->rollback();
}
//数据库“公司”数据已删除。
Event Name | Triggered | Break Operation |
---|---|---|
afterConnect | After a successfully connection to a database system | No |
beforeQuery | Before send a SQL statement to the database system | Yes |
afterQuery | After send a SQL statement to database system | No |
beforeDisconnect | Before close a temporal database connection | No |
beginTransaction | Before a transaction is going to be started | No |
rollbackTransaction | Before a transaction is rollbacked | No |
commitTransaction | Before a transaction is committed | No |