yii\db\Connection::useMaster PHP 메소드

useMaster() 공개 메소드

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.
리턴 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;
    }