Zend Framework SQL update query

14,836

Solution 1

acording to zend framwork documentation

use this

$data = array(
    'balance'      => 'balance + 10'
);

$n = $db->update('register ', $data, 'added_date > 1259944184');

Solution 2

This worked for me:

$data = array(balance => new Zend_DB_Expr('balance + 10'));

$db->update('register ', $data, 'added_date > 1259944184');

Solution 3

Try this... make sure your model is ready.

$table = new register();

This is the model class

balance=balance+10;

$data = array( 'balance' => 'balance' );

$where = $table->getAdapter()->quoteInto('added_date > '. 1259944184 );

You can use $where[] for multiple conditions

$table->update($data, $where);

For more details follow link

Share:
14,836
EricP
Author by

EricP

Updated on June 04, 2022

Comments

  • EricP
    EricP almost 2 years

    How would I write this SQL the Zend Framework way?

    UPDATE register 
    SET balance = (balance + 10) 
    WHERE added_date > 1259944184 ;
    

    I can't find any examples of this on Zend's website or the web.

    Do I need to use "Zend_Db_Expr"?

  • EricP
    EricP over 14 years
    That didn't work for me. I got it working using an sql query like this: $stmt=$this->_db->query(' UPDATE '.$this->_name.' SET balance = (balance + \''.$difference.'\') WHERE added_date > \''.$addedDate.'\' '); $numAdded=$stmt->rowCount(); echo '<br>'.$numAdded.' Rows Affected'; But I really want to use the fluid method of ZF.