yii\db\Connection::useMaster PHP Method

useMaster() public method

This method is provided so that you can temporarily force using the master connection to perform DB operations even if they are read queries. For example, php $result = $db->useMaster(function ($db) { return $db->createCommand('SELECT * FROM user LIMIT 1')->queryOne(); });
public useMaster ( callable $callback ) : mixed
$callback callable a PHP callable to be executed by this method. Its signature is `function (Connection $db)`. Its return value will be returned by this method.
return mixed the return value of the callback
    public function useMaster(callable $callback)
    {
        $enableSlave = $this->enableSlaves;
        $this->enableSlaves = false;
        $result = call_user_func($callback, $this);
        $this->enableSlaves = $enableSlave;
        return $result;
    }