0

I have this code

$db = Zend_Db_Table_Abstract::getDefaultAdapter();
$users_table = new Application_Model_UserModel();
$result = $users_table->update(array(
    "confirmed" => 1,
    "key" => null
), array(
    $db->quoteInto("'type' = ?", Application_Model_UserModel::TYPE_AWATAG),
    "'confirmed' = 0",
    $db->quoteInto("'id' = ?", $id),
    $db->quoteInto("'key' = ?", $key)
));

// no record updated
if ($result == 0) {

    throw new Zend_Exception("User not found.");

}

that throws the exception (ie: the user record has not been updated), even that all the where conditions are correct.

Is a bug? Do you see any error?

Solution

I unquoted all columns name and added table reference in this way:

tablename.columnname = newvalue

Thanks for watching :)

Egidio Caprino
  • 553
  • 10
  • 18
  • can you show me the model code also ? I feel you are doing this from controller . You don't need to call `$db = Zend_Db_Table_Abstract::getDefaultAdapter();` from the controller. Pass it like the one below. – Hari K T Aug 15 '11 at 11:53

1 Answers1

0

What are you trying to do ?

Your Application_Model_UserModel must extend Zend_Db_Table_Abstract .

See http://framework.zend.com/manual/en/zend.db.table.html#zend.db.table.defining

Please remember to add the table name in the $_name .

A bit of code from quick start

class Application_Model_DbTable_Guestbook extends Zend_Db_Table_Abstract
{
    /** Table name */
    protected $_name    = 'guestbook';

    //Now add you method and save from here
     public function updateGuest( $post, $id )
     {
         $data = array(
              'updated_on'      => '2007-03-23',
              'bug_status'      => 'FIXED'
         );

         $where = $this->getAdapter()->quoteInto('bug_id = ?', 1234);

         $this->update($data, $where);
     }
}

Now when you are updating pass $data which is an associative array with the key as the fields in the table, and second the where clause.

This is not a bug with zend-framework.

Hari K T
  • 4,174
  • 3
  • 32
  • 51
  • Thanks for the answer :) I'm sorry but I don't understand where is the error :( Quoting from the [manual](http://framework.zend.com/manual/en/zend.db.table.html): _[...]the second argument can be an array of SQL expressions. The expressions are combined as Boolean terms using an AND operator._ – Egidio Caprino Aug 15 '11 at 11:50