Phalcon事务和嵌套事务

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

Phalcon事务和嵌套事务

文章图片
事务示例:
< ?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

    推荐阅读