开发者

Zend Framework: How to subtract amount from database table field?

开发者 https://www.devze.com 2022-12-30 19:29 出处:网络
I want to subtract a amount from a t开发者_JAVA百科able\'s field in Zend Framework. I can run it with SQL using following query:

I want to subtract a amount from a t开发者_JAVA百科able'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?


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


Use Zend_Db_Expr

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

精彩评论

暂无评论...
验证码 换一张
取 消