Phalcon支持事务处理, 因为它随PDO一起提供。为了提高数据库的性能, 我们可以执行数据操作。下面是应用事务的数据库结构:

文章图片
事务示例:
<
?phptry {
// Start a transaction
$connection->
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();
}
//数据库” 公司” 数据已删除。
嵌套事务示例:
<
?phptry {
// Start a transaction
$connection->
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();
}
【Phalcon事务和嵌套事务】//数据库” 公司” 数据已删除。
活动名称 | Triggered | Break Operation |
---|---|---|
afterConnect | 成功连接到数据库系统后 | No |
beforeQuery | 在将SQL语句发送到数据库系统之前 | Yes |
afterQuery | 将SQL语句发送到数据库系统后 | No |
beforeDisconnect | 关闭临时数据??库连接之前 | No |
beginTransaction | 在开始事务之前 | No |
rollbackTransaction | 回滚事务之前 | No |
commitTransaction | 提交事务之前 | No |
推荐阅读
- PHP echo和print语句
- VOLT(模板引擎)
- Phalcon视图如何使用()
- Phalcon教程介绍
- Phalcon HTTP相应
- 番茄花园XP系统设置防范他人更改工具栏的办法
- 大地XP系统pagefile.sys文件删除不了怎样办
- win xp系统电脑卡屏假死的处理办法
- 萝卜家园xp系统如何关闭扫描并修好提示框