3

how can i write this command using Yii active record

 INSERT INTO table (a,b,c) VALUES (1,2,3)
ON DUPLICATE KEY UPDATE c=c+1;
bool.dev
  • 17,508
  • 5
  • 69
  • 93
safiot
  • 336
  • 1
  • 4
  • 10
  • 5
    You might find your answer [here](http://stackoverflow.com/questions/9004269/yii-insert-on-duplicate-update) – Grampa Aug 25 '12 at 15:37

1 Answers1

-3
  $model->Yourmodel::model()->findByPk($key);

  if($model){
      $model->value = $newvalue;

  }else{
      $model = new Yourmodel();
      $model->value = $newvalue;

   }

   if($model->save()){
     // do somethings
   }
Brian Webster
  • 30,033
  • 48
  • 152
  • 225
Denis Rudov
  • 833
  • 8
  • 16
  • This works only for indiscriminative create/update, not for handling duplicate entries for unique indexes. – Snivs Mar 14 '13 at 17:46