drupal7 带表达式条件的update

原本的mysql语句是这样的:

set @price=91;

update drupal754.my_payment_card  set balance = balance - @price  where  card_no=1 and balance - @price>=0

转化成drupal的api是这样的

$total_amount=1;
$rows= db_update('my_payment_card')
        ->expression('balance',  'balance - :price',array('price' => $total_amount))
        ->condition('card_no',1)
        ->where('balance - :price >= 0', array('price' =>$total_amount))
        ->execute();

 

posted @ 2017-09-07 16:57  jiafeng  阅读(337)  评论(0编辑  收藏  举报