ask about DAO update

hi, i am stucked using DAO to update my record. no row affected… and i follow the instruction from

http://www.yiiframework.com/doc/guide/1.1/en/database.query-builder

please help me to see if anything wrong in my code?




	Yii::app()->db->createCommand()

		->update('reference',array(

				'reference_status_id'=>':reference_status_id',

			),'id=:id',array(':id'=>$refid,':reference_status_id'=>'0')

		);



and here is the query show in firebug… it is not a query… but parameterized

UPDATE reference SET reference_status_id=:reference_status_id WHERE id=:id. Bound with :id=‘66’, :reference_status_id=‘0’

but after i check the db… no row affected…

i have no idea how to debug. please assist~

I haven’t done a lot of work with DAO but it looks ok to me. Check to see if your table is using ‘0’ as default. I.e. the value is already ‘0’ before the update. Change the value to 1 and try again.

Matt

thanks for reply Matt~

I tried using Active Record updateByPk is working to me,

and I try to optimize, so I try to update with DAO. same logic but not working

I tried to make the DAO sql output from firebug as same as the AR sql.

but the table still not updated~

:unsure:

You need to assign the value in the parameter list…




Yii::app()->db->createCommand()

      ->update('reference',array(

         'reference_status_id'=>'0',

      ),'id=:id',array(':id'=>$refid)

);

Hi,mdomba

I tried this too. that was my initial tried code :)