我正在使用Phalcon,并且在 MySql 中有一个数据库。我在数据库中有三个表:
- 用户:id,姓名,已售出
- 公司:身份证、姓名、费用
- 交易:id_company、id_user、成本
如果有足够的钱(已售出),用户必须进行交易。所以我必须这样做:
Step 1:
retrieve the sold of the user:
select sold
from user
where id='Charlie'
Step 2:
retrive the cost from the company:
select cost
from company
where id='Tango'
Step 3:
to check if the user has enough money:
if (sold-cost >= 0)
create the transaction
else
do not create the transaction.
我的问题是:有没有办法阻止数据库以便在没有数据库的情况下执行三个步骤可以改变?
我想这样做:
lock db
step 1
step 2
step 3
unlock db
但我还没有找到解决方案。