views:

105

answers:

2

I want to subtract a amount from a table's field in Zend Framework. I can run it with SQL using following query:

UPDATE `Person` SET credit=credit-50 where id=1

But how to write above SQL query in Zend Framework?

+3  A: 
$row = array('credit' => new Zend_Db_Expr('credit - 50'));
$where = "id = 1";
$nRowsAffected = $db->update('Person', $row, $where);
karim79
+1  A: 

Use Zend_Db_Expr

  $data = array(
      'credit'      => new Zend_Db_Expr('credit - 50'),
  );
  $n = $db->update('Person', $data, 'id=1');
Boris Guéry