Mysql Transaction有可能删除文件php吗?

时间:2016-04-15 22:58:18

标签: php mysql transactions try-catch unlink

On Yii1这是数据库事务假设我有$ model1和$ model2对象要保存。

$transaction = Yii::app()->db->beginTransaction();
try{

    if(!$model1->save()) throw new CDbException("Error: fail to save model1"); // successfuly save
    if(!$model2->save()) throw new CDbException("Error: fail to save model2"); // If this one throws an error it will go to catch then roll back the previous one w/c the $model1 

    $transaction->commit();

}catch(Exception $ex){

    $transaction->rollback();
}

我的问题是关于删除PHP中的文件是否有可能适应SQL事务的想法?

try{

    unlink("file1.txt"); //this is successfully deleted
    unlink("file2.txt"); //failed to delete this one how can I rollback the file1?

}catch(Exception $ex) {

    //need to rollback the file1 or any file has been deleted or modify on try{}
}

这可能吗?

0 个答案:

没有答案