原本的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();