Car*_*itz 3 php postgresql pdo yii
我有一个非常广泛的基于PHP/Yii的PHP更新脚本,它可以更新不同数据库类型的数据库(MSSQL,Postgres和MySQL).
整个脚本在事务中运行.但是,有一些语句会导致查询错误(例如,如果表上已存在某个键).我用try/catch声明包围了这些- 到目前为止这在MySQL中运行良好
但是在Postgres上发出无效查询后,事务会自动失败.以下所有语句都显示以下错误消息:
CDbCommand failed to execute the SQL statement: SQLSTATE[25P02]: In failed sql transaction: ERROR: current transaction is aborted, commands ignored until end of transaction block
Run Code Online (Sandbox Code Playgroud)
但我需要的是Postgres继续交易,因为我想在应用程序中决定何时回滚 - 或者某种方式来清除错误并继续交易.
怎么做?
为此目的使用保存点:
BEGIN; -- transaction starts here
-- do things if you want
SAVEPOINT my_savepoint;
-- failing statement here
-- all other statements are ignored
ROLLBACK TO SAVEPOINT my_savepoint;
-- continue your transaction starting from my_savepoint
COMMIT;
Run Code Online (Sandbox Code Playgroud)