title: Catching exceptions for "INSERT … ON DUPLICATE KEY UPDATE" workaround in ZF
body: <p><code>ZF 1.9.5</code> here. Someone suggested catching exceptions to emulate <code>ON DUPLICATE KEY UPDATE</code> when using Zend_Db_Table.</p>
  
  <p>Currently, I'm getting  </p>
  
  <p><code>SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'i7dd30253497cfc0539d7c5830a926f7d' for key 'ukey'</code>  </p>
  
  <p>..when using  </p>
  
  <pre><code>$orderRow = $this-&gt;createRow();
  $orderRow-&gt;ukey = $ukey;
  $orderRow-&gt;save();
  </code></pre>
  
  <p>So, I want to catch that bugger with <code>try / catch</code>. On exception <code>update</code> , else <code>insert</code>.<br>
  But I don't know what to catch. <code>Zend_Db_Exception</code>? <code>PDOException</code>? <code>Zend_Db_Adapter_Exception</code>? I've tried several, but I don't think I got it.</p>
  
  <hr>
  
  <p>Later edit.
  This worked for me:</p>
  
  <pre><code>        try {
              $orderRow = $this-&gt;createRow();
              $orderRow-&gt;ukey = $ukey;
              $orderRow-&gt;$stepCol = time();
              $orderRow-&gt;save();
          } catch (Zend_Db_Statement_Exception $e) {
              // on UNIQUE error, update
              if ($e-&gt;getCode() == 23000) {
                  $orderRow = $this-&gt;fetchRow($this-&gt;select()-&gt;where('ukey = ?', $ukey));
                  $orderRow-&gt;$stepCol = time();
                  $orderRow-&gt;save();
              }
          }
  </code></pre>