私はこれらの3つのクエリを持っています:
$sql1 = "INSERT INTO bag(bag_id, chara_id, item_id, item_qty)VALUES(NULL,:id,:item_id,'1')";
$sql2 = "UPDATE chara SET chara_gold = chara_gold - :gold WHERE chara_id = :id";
$sql3 = "UPDATE shop SET item_qty = :qty WHERE item_id = :item_id";
この3つのテーブルがあります:
キャラ
+----------+------------+----------------+-------------+------------+----------+----------+-----------+-----------+ | chara_id | chara_name | chara_class_id | chara_level | chara_gold | chara_hp | chara_mp | chara_atk | chara_def | +----------+------------+----------------+-------------+------------+----------+----------+-----------+-----------+ | 1 | LawrenceX | 1 | 1 | 1000 | 1000 | 1000 | 7 | 3 | | 3 | Viscocent | 2 | 1 | 1000 | 900 | 1100 | 5 | 5 | | 4 | Piatos | 1 | 1 | 1000 | 1000 | 1000 | 7 | 3 | | 5 | Hello | 1 | 1 | 1000 | 1000 | 1000 | 2 | 8 | | 6 | Sample | 3 | 1 | 1000 | 1100 | 900 | 9 | 1 | | 8 | Sampuro | 2 | 1 | 1000 | 1500 | 100 | 5 | 5 | | 12 | fail | 2 | 1 | 1000 | 900 | 100 | 5 | 5 | +----------+------------+----------------+-------------+------------+----------+----------+-----------+-----------+
バッグ
+---------+-----------------+------------+ | item_id | item_name | item_price | +---------+-----------------+------------+ | 0 | Halberd | 400 | | 1 | Axe | 200 | | 2 | Wooden Sword | 225 | | 3 | Dagger | 55 | | 4 | Bow | 120 | | 5 | Helmet | 155 | | 6 | Tunic | 50 | | 7 | Armour | 150 | | 8 | Necklace | 199 | | 9 | Studded Leather | 240 | +---------+-----------------+------------+
店
+---------+---------+------------+----------+ | shop_id | item_id | item_price | item_qty | +---------+---------+------------+----------+ | 1 | 1 | 200 | 99 | | 2 | 2 | 225 | 99 | | 3 | 3 | 55 | 99 | | 4 | 4 | 120 | 99 | | 5 | 5 | 155 | 99 | | 6 | 6 | 50 | 99 | | 7 | 7 | 150 | 99 | | 8 | 8 | 199 | 99 | +---------+---------+------------+----------+
シナリオ:
- バッグ
item_id
欄にアイテムを追加したいchara's id
- 次に、購入したアイテムの金額を差し引き
charas gold
ます(ショップに基づいてitem_price
)。 - そして
item_qty
、テーブルの上で、購入したアイテムの を 1差し引きshop
ます。
1つのクエリで実行できますか。私もtransactを使いたいです。