update db record and file name

Hi all,

I want to create/update… both file name and correspoding record in DB. can I use transaction? I tried this:


$transaction=$model->dbConnection->beginTransaction();

try{

	//create a row entry

	$model->save();

	//create a pysical folder

	mkdir(Yii::app()->params['fileRoot'].$model->name);

	$transaction->commit();

	echo $model->id;

}

catch(Exception $e){

	$transaction->rollBack();

	echo '-1';

}

but it seems no effect, because when the fileRoot was incorrect, it still prints out $model->id.

thanks for reading this.

mkdir() doesn’t throw an Exception on failure. You have to check its return value and rollback if it’s false.

ok, I kind of see the point. thanks for your pointer, phtamas.