Note that there are some explanatory texts on larger screens.

plurals
  1. POZend_Db_Table_Row::save() doesn't update the table
    text
    copied!<p>I am working with Zend Framework 1.12.1 </p> <p>I am trying to use a "save" method on a row from Zend_Db_Table_Abstract. As I understand this method should automatically decide whether to save or update a row in a table. I created two forms, one is for creating a record in database, another is for updating. It works perfect with create a new record. Method uses INSERT MySQL command. When I am trying to update the row, instead of choosing MySQL command UPDATE, save() method still chooses INSERT and duplicates a record in the table.</p> <p>Here's a full error log:</p> <pre><code>Message: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'France' for key 'country' Stack trace: #0 C:\wamp\zf\library\Zend\Db\Statement.php(303): Zend_Db_Statement_Pdo-&gt;_execute(Array) #1 C:\wamp\zf\library\Zend\Db\Adapter\Abstract.php(480): Zend_Db_Statement-&gt;execute(Array) #2 C:\wamp\zf\library\Zend\Db\Adapter\Pdo\Abstract.php(238): Zend_Db_Adapter_Abstract-&gt;query('INSERT INTO `co...', Array) #3 C:\wamp\zf\library\Zend\Db\Adapter\Abstract.php(576): Zend_Db_Adapter_Pdo_Abstract-&gt;query('INSERT INTO `co...', Array) #4 C:\wamp\zf\library\Zend\Db\Table\Abstract.php(1076): Zend_Db_Adapter_Abstract-&gt;insert('countries', Array) #5 C:\wamp\zf\library\Zend\Db\Table\Row\Abstract.php(467): Zend_Db_Table_Abstract-&gt;insert(Array) #6 C:\wamp\zf\library\Zend\Db\Table\Row\Abstract.php(438): Zend_Db_Table_Row_Abstract-&gt;_doInsert() #7 C:\wamp\www\website\library\App\Data.php(34): Zend_Db_Table_Row_Abstract-&gt;save() #8 C:\wamp\www\website\application\controllers\CountryController.php(82): App_Data-&gt;save() #9 C:\wamp\zf\library\Zend\Controller\Action.php(516): CountryController-&gt;editAction() #10 C:\wamp\zf\library\Zend\Controller\Dispatcher\Standard.php(308): Zend_Controller_Action-&gt;dispatch('editAction') #11 C:\wamp\zf\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard-&gt;dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #12 C:\wamp\zf\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front-&gt;dispatch() #13 C:\wamp\zf\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap-&gt;run() #14 C:\wamp\www\website\public\index.php(26): Zend_Application-&gt;run() #15 {main} </code></pre> <p>I am trying to update a record in the table {'id'=>'1', 'country'=>'France', 'continent'=>'Europe', 'created'=>'2013-03-07 10:10', 'modified'=>''} </p> <p>Is there way to force method save() to choose Zend_Db_Table_Row_Abstract->_doUpdate() method instead of _doInsert()?</p> <p>Thak you very much.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload