Search code examples
phpzend-frameworkzend-db

How to use Zend DB to add value to existing value in table


I would like to do the follow query in Zend DB style. Basically i want to add 1000 to the value in my table where id = 1.

mysql_query("UPDATE `some_table` SET `value` = `value` + 1000 WHERE `id` = 1");

This is my Zend query, but it does not work

$data= array('value' => 'value'+1000);
$this->dbo->update('some_table', $data, $this->dbo->quoteInto('id = ?','1'));   

Advice appreciated.


Solution

  • Try this:

    $data = array('value' => new Zend_Db_Expr('value + 1000'));
    $this->dbo->update('some_table', $data, $this->dbo->quoteInto('id = ?', 1);
    

    You need to use Zend_Db_Expr so that Zend_Db doesn't try to quote that value or apply any transformations to it.