Do queries called from within a transaction but found within another method act the same? Imagine the following code:

class foo {

    public function bar() {

        // Start the transaction
        $transaction = $this-&gt;db-&gt;beginTransaction();       

        try {

            // Get our member data
            $member_data = $this-&gt;getMemberData();

            // Update users details
            $sql = $this-&gt;db-&gt;createCommand("UPDATE users SET......");
            $sql-&gt;execute();

            // Now let's commit our data
            $transaction-&gt;commit();

        } catch (\Exception $e) {

            // Let's rollback the transaction
            $transaction-&gt;rollBack();           

        }       

    }

    public function getMemberData() {

        $sql = $this-&gt;db-&gt;createCommand("SELECT * FROM users WHERE id=123 LIMIT 1 FOR UPDATE");
        $member_data = $sql-&gt;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?
MySQL does not care about your PHP code structure. One transaction is what is between start and commit/rollback, sent over one connection - thats important, if your $this-&gt;db-&gt;createCommand()-&gt;execute/query creates a separate connection for some reason then it won't work but that should not be the usual case, just mentioning it because it sometimes happen so better to check.

You can have multiple transaction "open" using multiple connections but then you can deadlock yourself so beware (MySQL can automatically resolve deadlocks on the DB layer but not if you lock a record from one connection and then try to access it from some other, because your app is single-threaded (probably) and the deadlock detection expects parallel clients.