title: How do I properly save data to the database?
body: <p>I normally save new data to the database like this:</p>
  
  <pre><code>$this-&gt;MyTable-&gt;set(array(
   'id' =&gt; $id,
   'code' =&gt; $temp_code,
   'status' =&gt; $status,
   'age' =&gt; $age,
   'location' =&gt; $location,
   'money' =&gt; $money
  ));
  
  $this-&gt;MyTable-&gt;save();
  </code></pre>
  
  <p>If the ID already exists in the database I update its corresponding fields like this:</p>
  
  <pre><code>$this-&gt;Adtweet-&gt;id = $id;
  $this-&gt;Adtweet-&gt;saveField('code', $temp_code);
  $this-&gt;Adtweet-&gt;saveField('status', $status);
  </code></pre>
  
  <p>Is there a better or 'proper' way to do this?</p>
  
  <p>When I attempt to enter an ID that already exists and I use the <code>set</code> function, I get the following SQL integrity error:</p>
  
  <blockquote>
    <p>(Error: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '150245925' for key 'PRIMARY')</p>
  </blockquote>
  
  <p>How can I write a function that cleanly handles duplicate entries without returning an error?</p>