INSERT INTO table1 ('id','name','cust_id','add') 值 ('5','RENJITH','5','2012-08-04 15:07:38') ON DUPLICATE KEY UPDATE 'cust_id'='5' WHERE 'table1.id' IN ('1','2','3')
在 cakephp 中制作?
INSERT INTO table1 ('id','name','cust_id','add') 值 ('5','RENJITH','5','2012-08-04 15:07:38') ON DUPLICATE KEY UPDATE 'cust_id'='5' WHERE 'table1.id' IN ('1','2','3')
在 cakephp 中制作?
像这样的东西应该在模型类中工作:
//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);
}