我有以下更新查询。 shots_limit
需要是数据库中的当前值PLUS我的新值$add_shots
。使用绑定时有没有办法做到这一点?
//figure out how many screenshots to add
$add_shots = $_POST['Quantity'] * 500;
$stmt = $db->prepare("
UPDATE accounts
SET orders = :orders,
shots_limit = :shots_limit
WHERE account_id = :account_id
");
//bindings
$binding = array(
'orders' => $orders_str,
'shots_limit' => $add_shots + ORIGINAL VALUE
'account_id' => $result['account_id']
);
$status = $stmt->execute($binding);
答案 0 :(得分:0)
我认为这就是你要找的东西。只需在更新中使用当前值
$stmt = $db->prepare("
UPDATE accounts
SET orders = :orders,
shots_limit = shots_limit + :shots_limit
WHERE account_id = :account_id
");
//bindings
$binding = array(
'orders' => $orders_str,
'shots_limit' => $add_shots,
'account_id' => $result['account_id']
);