cakephp中的'ON DUPLICATE KEY UPDATE'

时间:2012-09-17 08:49:20

标签: cakephp

INSERT INTO table1    ( 'ID', '姓名', 'CUST_ID', '添加')    价值观('5','RENJITH','5','2012-08-04 15:07:38')    ON DUPLICATE KEY UPDATE'cust_id'='5'WHER'table1.id'IN('1','2','3')

  

在cakephp中制作吗?

1 个答案:

答案 0 :(得分:0)

这样的东西应该在模型类中起作用:

//check if key duplikates
$duplicate = $this->find('first', array('conditions' => array('Model1.id' => 5)));

if($duplicate) {
  $this->updateALL(array('Model1.cust_id' =>5), array('Model1.id' => array(1,2,3)));
} else {
  $data['Model1'] = array('Model1.id' = 5, 'Model1.name' => 'RENJITH','Model1.cust_id' => 5, 'Model1.add' => strtotime('2012-08-04 15:07:38'));

  $this->create();
  $this->save($data);
}