title: Zend update/insert (Zend_Db_Table_Abstract) doesn't work
body: <p>I've got a problem with insert and update queries in Zend (Select is ok).</p>
  
  <p>Definition of table:</p>
  
  <pre><code>class Application_Model_DbTable_Kpr1Data extends Zend_Db_Table_Abstract
  {
      protected $_name = 'kpr_kpr1_data';
  }
  </code></pre>
  
  <p>Here is my data mapper (model)</p>
  
  <pre><code>class Application_Model_Kpr1DataMapper
  {
      protected $_dbTable;
  
      public function setdbTable($dbTable) {
          if(is_string($dbTable)){
              $dbTable = new $dbTable();
          }
          if(!$dbTable instanceof Zend_Db_Table_Abstract ){
              throw new Exception ('Invalid table data gateway provided.');
          }
          $this-&gt;_dbTable = $dbTable;
  
          return $this;
      }
  
      public function getdbTable() {
          if (null === $this-&gt;_dbTable){
              $this-&gt;setdbTable('Application_Model_DbTable_Kpr1Data');
          }
          return $this-&gt;_dbTable;
      }
  
      public function save(Application_Model_Kpr1Data $kpr1data){
          $data = array('id' =&gt; (int) $kpr1data-&gt;getId(),
                  'kpr1_plaza_id'   =&gt; (int) $kpr1data-&gt;getPlaza(),
                  'kpr1_data' =&gt;  new Zend_db_Expr("STR_TO_DATE('".$kpr1data-&gt;getDate()."', '%Y-%m-%d')"),
                  'kpr1_money_delivered' =&gt; (float) $kpr1data-&gt;getDelivered(),
                  'kpr1_money_transactions' =&gt; (float) $kpr1data-&gt;getTransactions(),
                  'kpr1_created' =&gt; new Zend_Db_Expr('CURDATE()')
                  );
          $id = (int) $kpr1data-&gt;getId();
          $table = $this-&gt;getdbTable();
          if (is_null($id) &amp;&amp; $id != 0) {
              unset($data['id']);
              $table-&gt;insert($data);
          } else {
              $table-&gt;update($data, array('id =&gt; ?', $id));
          }
      }
  </code></pre>
  
  <p>The last one is save function that should insert and update the data!</p>
  
  <p>And this save is called from save action:</p>
  
  <pre><code>public function saveAction()
  {
      $plazaid = (int) $this-&gt;getRequest()-&gt;getParam('plaza');
      $date = (string) $this-&gt;getRequest()-&gt;getParam('date');
      $delivered = (string) $this-&gt;getRequest()-&gt;getParam('delivered');
      $transactions = (string) $this-&gt;getRequest()-&gt;getParam('transactions');
      $kpr1data = new Application_Model_Kpr1Data();
      if ($plazaid &amp;&amp; $date) {
          $kpr1datamapper = new Application_Model_Kpr1DataMapper();
          if($kpr1datamapper-&gt;findDatePlaza($date, $plazaid, $kpr1data)){
              $kpr1data-&gt;setDelivered($delivered)
                      -&gt;setTransactions($transactions);
              $kpr1datamapper-&gt;save($kpr1data);
              $this-&gt;_helper-&gt;layout-&gt;disableLayout();
              $this-&gt;view-&gt;result = json_encode(array("success"=&gt;"true"));
          } else {
              $kpr1data-&gt;setDate($date);
              $kpr1data-&gt;setDelivered($delivered);
              $kpr1data-&gt;setTransactions($transactions);
              $kpr1data-&gt;setPlaza($plazaid);
              $kpr1datamapper-&gt;save($kpr1data);
              $this-&gt;_helper-&gt;layout-&gt;disableLayout();
              $this-&gt;view-&gt;result = json_encode(array("success"=&gt;"true"));
          }
          $this-&gt;_helper-&gt;layout-&gt;disableLayout();
          $this-&gt;view-&gt;result = json_encode(array(
                                  //"success"=&gt;"false", 
                                  "errorMsg"=&gt;"Saving error"
                                ));            
      } else {
          $this-&gt;_helper-&gt;layout-&gt;disableLayout();
          $this-&gt;view-&gt;result = json_encode(array(
                                  //"success"=&gt;"false", 
                                  "errorMsg"=&gt;"Saving error"
                                ));
      }
      return true;
  }
  </code></pre>
  
  <p>Save action is called via JS, but even called directly through webbrowser it fails.</p>
  
  <p>Behaviour: Application is running, and when debugger runs into update/insert line:</p>
  
  <pre><code>    if (is_null($id) &amp;&amp; $id != 0) {
          unset($data['id']);
          $table-&gt;insert($data);
      } else {
          $table-&gt;update($data, array('id =&gt; ?', $id));
      }
  </code></pre>
  
  <p>it's redirecting to ErrorController.</p>
  
  <p>I've check that:
  1. firePHP is not showing this statements
  2. MySQL database doesn't log this statement (I've checked via general_log feature).</p>
  
  <p>I'm stucked. Help me please.</p>
  
  <p>edit</p>
  
  <pre><code>$data=
  array(6) (
    [id] =&gt; (int) 0
    [kpr1_plaza_id] =&gt; (int) 116
    [kpr1_data] =&gt; Zend_Db_Expr object {
      _expression =&gt; (string) STR_TO_DATE('2013-03-01', '%Y-%m-%d')
    }
    [kpr1_money_delivered] =&gt; (float) 120
    [kpr1_money_transactions] =&gt; (float) 122
    [kpr1_created] =&gt; Zend_Db_Expr object...
  </code></pre>
  
  <p>$kpr1data=</p>
  
  <pre><code>Application_Model_Kpr1Data object {
    _plaza =&gt; (string) 116
    _date =&gt; (string) 2013-03-01
    _delivered =&gt; (string) 120.00
    _transactions =&gt; (string) 122.00
    _created =&gt; null
    _id =&gt; null
    _plazaname =&gt; null
  }
  </code></pre>
  
  <p>This one should do insert.
  And next one update:</p>
  
  <pre><code>Application_Model_Kpr1Data object {
    _plaza =&gt; (string) 117
    _date =&gt; (string) 2013-03-01
    _delivered =&gt; (string) 120.00
    _transactions =&gt; (string) 122.00
    _created =&gt; (string) 2013-03-06 12:42:13
    _id =&gt; (string) 79
    _plazaname =&gt; (string) SPO Kraj...
  </code></pre>