Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
183 views
in Technique[技术] by (71.8m points)

php - Do I need to rollback/commit if my lockForUpdate returned an empty set?

My code:

$connection->beginTransaction();

$row = $this->newQuery()->where(['someField' => 'someValue'])->lockForUpdate()->get()->first();

if (is_null($row)) {
    $connection->rollBack();

    return null;
}
          
//do some stuff with that row

$connection->commit();

My question: The result is empty, so do I need that rollback? Should I commit? Is transaction still opened by that point?

question from:https://stackoverflow.com/questions/65830352/do-i-need-to-rollback-commit-if-my-lockforupdate-returned-an-empty-set

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...