gpt4 book ai didi

php - 我是否正确使用了 MySQL 事务?

转载 作者:行者123 更新时间:2023-11-29 06:48:47 25 4
gpt4 key购买 nike

<分区>

我想确认我正在正确使用 MySQL 事务来正确处理一些关键问题(没有竞争错误等)

$mysqli->autocommit(FALSE);
$mysqli->query("UPDATE users SET balance=balance-$amount, transactions=transactions+1, sent=sent+$amount WHERE email='$email'");
$mysqli->query("UPDATE users SET balance=balance+$amount, transactions=transactions+1, recv=recv+$amount WHERE email='$address'");
$newBalanceQ = $mysqli->query("SELECT balance FROM users WHERE email='$email'");
$newBalance = $newBalanceQ->fetch_row()[0];
if($newBalance < 0){
$mysqli->rollback();
} else {
$mysqli->commit();
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com