title: Error on inserting Yii ActiveRecord model to mysql table
body: <p>I have the following kind of error that happens on my website from time to time.</p>
  
  <pre><code>2012/07/12 21:21:48 [error] [system.db.CDbCommand] Error in executing
  SQL: INSERT INTO `seo_page` (`grouped`, `results_count`, `page`, `operation`, `subtype`, `type`, `state`, `zone`, `city`, `district`, `custom`, `property`, `date_add`, `date_upd`) VALUES (:yp0, :yp1, :yp2, :yp3, :yp4, :yp5, :yp6, :yp7, :yp8, :yp9, :yp10, :yp11, :yp12, :yp13)
  </code></pre>
  
  <p>Basically the code works, and it saves the model correctly, I think I only get this kind of errors when it is trying to do two inserts at the same time with the same primary key, or maybe it doesn't ensure the uniqueness of the keyword field before inserting.</p>
  
  <p>The script it is soposed to insert or update a keyword in the database, the code is like this:</p>
  
  <pre><code>static public function quickAdd($keyword) {
    if (strlen($keyword['name'])==0)
      return;
    $seo_keyword = SeoKeyword::model()-&gt;find("keyword=:keyword", array("keyword"=&gt;$keyword['name']));
    if ($seo_keyword) {
  //        return;
    } else {
      $seo_keyword=new SeoKeyword();
    }
    $seo_keyword-&gt;keyword=$keyword['name'];
    if (is_numeric($keyword['position'])) {
      $seo_keyword-&gt;position=$keyword['position'];
    }
    try {
      $seo_keyword-&gt;save();
    } catch (Exception $e) {
  
    }
    return $seo_keyword;
  }
  </code></pre>
  
  <p>The mysql table looks like this:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `seo_keyword` (
  `id_seo_keyword` int(11) NOT NULL AUTO_INCREMENT,
  `keyword` varchar(255) NOT NULL,
  `position` int(11) DEFAULT NULL,
  `date_add` datetime NOT NULL,
  `date_upd` datetime NOT NULL,
  PRIMARY KEY (`id_seo_keyword`),
  UNIQUE KEY `keyword` (`keyword`)
  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
  </code></pre>
  
  <p>I am also getting this kind of error with other tables, all of them are tables that have many rows and are mostly used for stathistical data.</p>
  
  <p>The fact is that I can only see that it could not insert, but there's no error like: primary key problem, servery busy or anything.</p>