Select connection randomly accounting for weight.

@param array $connections

@return OptionsBag
435291
public function selectConnection(array $connections)
    {
        $weighted = [];

        foreach ($connections as $connection) {
            foreach (range(0, $connection['weight']) as $i) {
                $weighted[] = $connection;
            }
        }

        $index = mt_rand(0, count($weighted) - 1);

        return $weighted[$index];
    }
248358
public function select($columns = [])
    {
        parent::select($columns);
        $compiler = $this->connection->getCompiler();
        return $this->connection->query($compiler->select($this->sql), $compiler->getParams());
    }
475651
protected function checkConnections($connection)
    {
        $connections = $connection->getConnectionManager()->count();

        if ($connections > $this->options['connections']) {
            $this->limit($connection, 'Max connections');
        }
    }
893975
protected function parseConnectionsFromOptions(OptionsBag $options)
    {
        if ($options->has('connections')) {
            $connections = $options->get('connections');
        } elseif ($options->has('connection')) {
            $connections = [$options->get('connection')];
        } elseif ($options->has('host') || $options->has('port')) {
            Deprecated::warn('Specifying "host" and other options directly in session config', 1.0, 'Move them under the "connection" key.');

            $connections = [$options->all()];
        } else {
            $connections = [[]];
        }

        return array_map([$this, 'parseConnectionItemFromOptions'], $connections);
    }
1334619
public static function bulk($jobs, $data = '', $queue = null, $connection = null)
    {
        return static::$instance->connection($connection)->bulk($jobs, $data, $queue);
    }
216550
public function createConnection(?string $connection = null, array $options = []): AbstractDatabaseDriver
    {
        $config = $this->config->extract('database');

        // Check is new or legacy
        if ($config->get('connections')) {
            $connection = $connection ?: $config->get('default', 'local');
            $config     = $config->extract('connections.' . $connection);
        }

        $options = array_merge(
            [
                'driver' => $config->get('driver', 'mysql'),
                'host' => $config->get('host', 'localhost'),
                'user' => $config->get('user', 'root'),
                'password' => $config->get('password', ''),
                'database' => $config->get('name'),
                'prefix' => $config->get('prefix', 'wind_'),
            ],
            $options
        );

        $db = DatabaseFactory::getDbo($options['driver'], $options, true);

        $db->setDebug($this->config->get('system.debug', false));

        if ($db instanceof MysqlDriver && $config->get('strict', true)) {
            $this->strictMode($db);
        }

        return $db;
    }
1290096
public function loadCount($relations)
    {
        $relations = is_string($relations) ? func_get_args() : $relations;

        $this->newCollection([$this])->loadCount($relations);

        return $this;
    }
216398
public function connection(?string $connection = null)
	{
		$connection = $connection ?? $this->default;

		if(!isset($this->connections[$connection]))
		{
			$this->connections[$connection] = $this->connect($connection);
		}

		return $this->connections[$connection];
	}
361781
public function setCurrentConnection($connection = null, $server = null)
    {
        $connectionKey = $connection instanceof ConnectionKey ? $connection : $this->credentials->createConnectionKey($connection, $server);
        if ($this->current === $connectionKey->toHandle()) {
            return;
        }

        $this->current = $connectionKey->toHandle();
        $this->available = $this->getConnections()->map(function (ConnectionInterface $connection) use ($connectionKey) {
            $isCurrent = $connectionKey->is($connection->getConnectionKey());
            $connection->setCurrent($isCurrent);

            return $connection;
        });

        // Update events
        $this->bootstrapper->bootstrapUserCode();
    }
154419
public function select(array $keys)
    {
        $list = [];
        foreach ($keys as $key) {
            if ($this->containsKey($key)) {
                $list[$key] = $this->get($key);
            }
        }

        return $this->createFrom($list);
    }
1188232
public function select($fields)
    {
        if (!is_array($fields)) {
            $fields = func_get_args();
        }

        $fields = $this->addTablePrefix($fields);
        $this->addStatement('selects', $fields);
        return $this;
    }
1191645
public function getConnection()
    {
        if ($chosenConn = $this->connections->pop()) {
            $this->connections->push($chosenConn);

            return $chosenConn;
        }
    }
155771
public function select($fields)
    {
        foreach ($this->queries as $query) {
            $query->select($fields);
        }

        return $this;
    }
822812
public function getSortedServersArray()
    {
        $servers = empty($this->config->getServers()) ? $this->getServersFromDns() : $this->config->getServers();

        if (self::SELECT_RANDOM == $this->selectionMethod) {
            $servers = $this->shuffleServers($servers);
        }

        return $servers;
    }
788487
public function setConnection(Connection $connection)
    {
        $this->connection = $connection;
        $this->prefix     = $this->connection->getConfig('prefix');

        return $this;
    }
991553
public static function randomByWeight(array $values)
    {
        $maxRand = (int) array_sum($values);
        if (0 === $maxRand) {
            $rand = mt_rand(0, count($values) - 1);

            return array_keys($values)[$rand];
        } else {
            $rand = mt_rand(1, $maxRand);
            foreach ($values as $key => $value) {
                $rand -= $value;
                if ($rand <= 0) {
                    return $key;
                }
            }
            // Make PHP happy by return the first key.
            return array_keys($values)[0];
        }
    }
1183728
public function select($cols = array('*'))
    {
        if (!is_array($cols)) {
            $cols = func_get_args();
        }
        return new Query("SELECT", $cols, $this->connectionName);
    }