1

INSERT INTO table1 ('id','name','cust_id','add') VALUES ('5','RENJITH','5','2012-08-04 15:07:38') ON DUPLICATE KEY UPDATE 'cust_id'='5' WHERE 'table1.id' IN ('1','2','3')

Cakephpで作る?

4

1 に答える 1

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);
}
于 2012-09-17T11:00:14.037 に答える