Search code examples
phpzend-frameworkzend-db

DBTable creates new row instead off updating the existing


I try to update an DB entry with now data, but i am just creating an new entry:

$client =$this->clientTable->find($id);
$client->CompanyName = $request->getPost('CompanyName');
$this->clientTable->update();
$this->_redirect('client/index');

Solution

  • Zend_Db_Table_Abstract::find() method returns Zend_Db_Table_Rowset object. You should use method which will return you Zend_Db_Table_Row object and use it.

    For example:

    $clientRow = $this->clientTable->fetchRow(array('id' => $id));
    $clientRow->CompanyName = $request->getPost('CompanyName');
    $clientRow->save();
    

    If your's table primary key name is not 'id', change it to suitable value in the first line of code above.