Studyon Minte9.com
ZF 1.0




Insert on duplicate update



$sql = "INSERT INTO sometable (id, col2, col3) VALUES (:id, :col2, :col3)
  ON DUPLICATE KEY UPDATE col2 = VALUES(col2), col3 = VALUES(col3)";

$values = array("id"=>1, "col2"=>327, "col3"=>"active");

-----------------------


There is no API support in Zend for the ON DUPLICATE KEY UPDATE syntax:
INSERT INTO sometable (...) VALUES (...) ON DUPLICATE KEY UPDATE ...

Solution: 

Set unique index on your id, and in model (extends Zend_Db_Table) do this:

try {
    $this->insert($params);
} catch (Zend_Db_Exception $e) {			
    $this->update($params, "user_id = 1");
}


http://stackoverflow.com/questions/302544/is-there-a-way-to-do-an-insert-on-duplicate-key-udpate-in-zend-framework