title: Zend Framework 1.12, execution of raw SQL inserts the same record twice
body: <p>I know there´s a similar <a href="https://stackoverflow.com/questions/8561392/zend-framework-dbtable-insert-inserting-records-twice">situation</a> in stack, and I´ve already checked it out and the answers have not guided me to mine. </p>
  
  <p>Here´s the deal:</p>
  
  <p>I need to execute raw SQL, an INSERT to be precise. I have multiple values to insert as well. No problem since Zend let´s you use "query" from Zend_Db_Table (I use my default adapter, initialized in my application.ini file). </p>
  
  <pre><code> $db_adapter = Zend_Db_Table::getDefaultAdapter();
   ....query gets built...
   $stmt = $db_adapter-&gt;query($query);
   $stmt-&gt;execute();
  </code></pre>
  
  <p>When doing <code>var_dump($query);</code> this is what I see:</p>
  
  <pre><code>INSERT INTO tableName (col1,col2,col3) VALUES ('value1', 'value2', 'value3')
  </code></pre>
  
  <p>I have already tried the following:</p>
  
  <ol>
  <li>I have no "manifesto" attribute on the html page rendered</li>
  <li>I have looked at the network both with Chrome and Firefox to see the POSTS/GETS getting sent, and the controller whose actions does
  this INSERT gets called <strong>once</strong> with a POST.</li>
  <li><p>It is true that I call a viewscript from another action to be rendered, like so: </p>
  
  <p>$this->renderScript('rough-draft/edit.phtml');</p>
  
  <p>I don´t see how that could affect the statement getting executed twice.</p></li>
  </ol>
  
  <p>I know it gets executed twice:</p>
  
  <ol>
  <li>Before the POST is sent, the data base has nothing, clean as a whistle</li>
  <li>POST gets sent, logic happens, from is rendered again</li>
  <li>Data base now has the same record twice (with the name that has been inserted from the POST), so it´s not a rendering problem</li>
  </ol>
  
  <p>It has to do with the way I am executing raw SQL, because if I use <code>-&gt;insert($data)</code> method that comes with Zend_Db_Table_Abstract (obviously I declare a class that extends from this abstract one and bind it to the appropriate table) it does not insert the record twice. Thing is, I want to use raw SQL.</p>
  
  <p>I really appreciate your help!</p>
  
  <p><strong>Expanded as requested:</strong> </p>
  
  <p>Controller code:</p>
  
  <pre><code> public function saveAction()
  {
      $request = $this-&gt;getRequest();
  
      if (!$request-&gt;isPost())
          $this-&gt;_sendToErrorPage();
  
  
      $this-&gt;_edit_roughdraft-&gt;saveForm($request-&gt;getPost());
      $this-&gt;view-&gt;form = $this-&gt;_edit_roughdraft-&gt;getForm();
      $this-&gt;renderScript('rough-draft/edit.phtml');
  }
  </code></pre>
  
  <p>Code from model class (in charge of saving the form from the data in POST):</p>
  
  <pre><code>public function saveForm($form_data) {           
       $db = new Application_Model_DbTable_RoughDrafts();
       $id = $form_data['id'];
  
       $db-&gt;update($this-&gt;_get_main_data($form_data), array('id=?' =&gt; $id));
       /* Main data pertains to getting an array with the data that belongs to yes/no buttons
       *  and text input. I need to do it as so because the other data belongs to a dynamically 
       * built (by the user) multi_select where the options need to be deleted or inserted, that
       *  happens below
       */
  
       $multi_selects = array('responsables', 'tareas', 'idiomas', 'habilidades', 'perfiles');
       foreach($multi_selects as $multi_select){
           if(isset($form_data[$multi_select]) &amp;&amp; !empty($form_data[$multi_select])){
               $function_name = '_save_'.$multi_select;
               $this-&gt;$function_name($form_data[$multi_select], $id);
           }
       }
  
       $this-&gt;_form = $this-&gt;createNewForm($id, true);
       //The createNewForm(..) simply loads data from data_base and populates form
  }
  </code></pre>
  
  <p>I do want to make clear though that I have also used <code>$db-&gt;insert($data)</code>, where $db is a class that extends from Zend_Db_Table_Abstract (associated to a table). In this case, the record is inserted once and only once. That´s what leads me to believe that the problem lies within the execution of my raw sql, I just don´t know what is wrong with it.</p>