Imagine the following code:
class foo {
public function bar() {
// Start the transaction
$transaction = $this->db->beginTransaction();
try {
// Get our member data
$member_data = $this->getMemberData();
// Update users details
$sql = $this->db->createCommand("UPDATE users SET......");
$sql->execute();
// Now let's commit our data
$transaction->commit();
} catch (\Exception $e) {
// Let's rollback the transaction
$transaction->rollBack();
}
}
public function getMemberData() {
$sql = $this->db->createCommand("SELECT * FROM users WHERE id=123 LIMIT 1 FOR UPDATE");
$member_data = $sql->queryOne();
return $member_data;
}
}
Now, does the query within the getMemberData
method act as part of the transaction since it is being called within the transaction and it doesn't matter to the database how it is being called since we have a transaction open or am I required to move the query inside the transaction code block?