Yii Framework Forum: Help for updateByPk() - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Help for updateByPk() Rate Topic: -----

#1 User is offline   Andreas123 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 89
  • Joined: 11-March 11
  • Location:$3RdF

Posted 04 April 2011 - 10:55 AM

hey guys,
I'm trying to fit the follwing SQL Query in ->updateByPk()
UPDATE `tb_image` SET `views` = `views` + '1' WHERE `idImage` =  1;


For some reason I can't get it to work with updateByPk()..
Can anybody help?
0

#2 User is offline   Haensel 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 444
  • Joined: 14-January 11
  • Location:Vienna (Austria)

Posted 04 April 2011 - 11:05 AM

Maybe you could use the updateCounters() method of your AR class:

http://www.yiiframew...Counters-detail

In your case something like this:

Image::model()->updateCounters(array('views'=>+1), 'idImage=1');

0

#3 User is offline   Steve Friedl 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 27-September 10
  • Location:Orange County, California USA

Posted 04 April 2011 - 01:12 PM

View PostAndreas123, on 04 April 2011 - 10:55 AM, said:

For some reason I can't get it to work with updateByPk()..

What does "can't get it work" mean?
Can you show the code you've tried?
Steve Friedl * UNIX Wizard * Microsoft Security MVP * Find me in #yii
0

#4 User is offline   Andreas123 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 89
  • Joined: 11-March 11
  • Location:$3RdF

Posted 04 April 2011 - 03:20 PM

Ok Thx guys.
updateCounters() what exactly what I was looking for..
0

#5 User is offline   andybegin 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 18-April 13

Posted 04 October 2013 - 12:23 PM

Thanks . AR updateCounters() is really good for frequently update count.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users