Save only works if no processing is done

I have a mysterious situation with Save to the database (Yii 1.1.8 SQL Server 2008).

This is a console application, first i create a model and save() which creates a new record, then i process a data file - and within that function i use a different model and save() which also works fine. At the end i update some variables of the first model and call save(), and this is where the surprise happens:

  • if i run the data processing, the last save() does not write to the database. NOTE: the model is updated correctly, the save() return true, and even the trace shows the correct query which should have resulted in an update to the record in the database.

  • if i comment out the file processing loop, the final save() actually shows up in the database.

i also tried using ‘update()’ instead of save() (as you can see in the code snippet) but it behaves the same.

ANY ideas will be greatly welcome. this has been under investigation for days.

	public function run($args) {



		//write processing to import log

		$importLog = new ImportLog();

		$importLog->var1 = $value1;

		$importLog->var2 = $value2;

		$importLog->var3 = $value3;


		// now do some processing


		// update import table 

		$importLog->var1 = $newValue1;

		$importLog->var2 = $newValue2;




	private function createDBImport() {

		$output = $filename.'.TXT';

		if (($outh = fopen(Yii::app()->params->dbInputDir.$output, "w")) == FALSE) { 

			echo "unable to create output file\n";



		$rowNum = 0;

		if (($handle = fopen(Yii::app()->params->currentDir.$input, "r")) !== FALSE) {

			// --- this is the section i comment out to make the second model->save work /*

			while (($data = fgetcsv($handle, 1000, $dlmtr)) !== FALSE) {



				$row = $rowNum . $delim 

					. $data[1] . $delim

					. $data[2] . $delim

					. $data[3] . $delim

					. $data[4] . $delim

					. $data[5] . $delim

					. $data[6] . $delim

					. $data[7] . $delim

					. "\n"; 

				fwrite($outh, $row);


			// --- this is the end of the commented out section */



		else {

			echo "failed to open file $input\n";



		fclose ($outh);

		// write stats with rowNum into import stats


		$importStats = new ImportStats();

		$importStats->var1 = $value1;

		$importStats->var2 = $value2;

		$importStats->var3 = $value3;

		$importStats->item_count = $rowNum;



Can someone please throw some ideas, what you would look at to try and identify this issue, i am out of ideas and this is clearly a processing issue having the command sent correctly and the database not executing it - NOT because of an error but something else.

I thought maybe its the console app that ends immediately after, so it might be cutting off the connection to the db before the query is sent, so i tried adding Yii::App()->end(); but the same results.