<?
// beginTranse(开启事务)
try{
select count from s_store where postID = 12345;
if(count > 0){
update s_store set count = count - 1 where postID = 12345;
insert into buy_log (userID, postID) VALUES (22, 12345);
}
}catch($e Exception){
// rollBack(回滚)
}
// commit(提交事务)
//beginTranse(开启事务)
try{
affect_rows = update s_store set count = count - 1 where count>=1 and postID = 12345;
if (affect_rows === 1) {
insert into buy_log (userID, postID) VALUES (22, 12345);
}
}catch($e Exception){
rollBack(回滚)
}
// commit(提交事务)
<?
//beginTranse(开启事务)
try{
count = select count from s_store where postID = 12345;
if (count > 0) {
affect_rows = update s_store set count = count - 1 where count=count and postID = 12345;
if (affect_rows === 1) {
insert into buy_log (userID, postID) VALUES (22, 12345);
}
}
}catch($e Exception){
rollBack(回滚)
}
// commit(提交事务)
BEGIN;
count = SELECT count FROM s_store WHERE postID = 12345 AND count>0 FOR UPDATE;
if (count > 0) {
affect_rows = UPDATE s_store SET count=count-1 WHERE postID = 12345 AND count> 0;
if (affect_rows === 1) {
insert into buy_log (userID, postID) VALUES (22, 12345);
}
}
COMMIT;
成为你想看到的世界变革力量