Configure parameters.

@param        $table
@param string $connection

@return QueryBuilder
553517
public function setup($table, $connection = 'default')
    {
        $query = $this->query();
        $this->setDatabase($connection == 'default' ? $query->getDefaultConnection() : $connection);
        $this->setTableName($table);
        $query->setActiveRecord($this);

        return $query;
    }
647398
private static function setConnectionCollation(Connection $connection, array $options = array())
    {
        if (isset($options['collation'])) {
            try {
                if ('pdo_mysql' === $connection->getDriver()->getName()) {
                    $connection->executeQuery('SET SESSION collation_connection = "'.addslashes($options['collation']).'";');
                }
            } catch (\Exception $e) {
                throw new InvalidArgumentException(
                    sprintf('Invalid database collation `%s`', $options['collation']),
                    InvalidArgumentException::INVALID_ARGUMENT,
                    $e
                );
            }
        }
    }
765430
protected function configureEncoding($connection, array $config)
    {
        if (! isset($config['charset'])) {
            return $connection;
        }

        $connection->prepare(
            "set names '{$config['charset']}'".$this->getCollation($config)
        )->execute();
    }
920651
public static function createInsert(Connection $connection, $table, $values){
		if(!($values instanceof Traversable || (is_array($values) && !empty($values))))
			throw new InvalidArgumentException('Argument 3 must be a non-empty array or Traversable.');

		$obj = new self($connection);
		$obj->type = Manager::STMT_INSERT;
		$obj->source = $table;
		$obj->values = $values instanceof Traversable ? iterator_to_array($values) : $values;
		return $obj;
	}
848671
public static function createFromConnection(Connection $connection)
    {
        $driver = $connection->getDriver()->getName();

        if ($driver === 'pdo_sqlite') {
            return new ConnectionHandler\SqliteConnectionHandler($connection);
        }

        if ($driver === 'pdo_pgsql') {
            return new ConnectionHandler\PostgresConnectionHandler($connection);
        }

        return new self($connection);
    }
548189
protected function prepareConnection(NodeConnectionInterface $connection)
    {
        $parameters = $connection->getParameters();

        if (isset($parameters->password)) {
            $connection->addConnectCommand(
                new RawCommand(array('AUTH', $parameters->password))
            );
        }

        if (isset($parameters->database)) {
            $connection->addConnectCommand(
                new RawCommand(array('SELECT', $parameters->database))
            );
        }
    }
379586
protected function handle(Connection $connection, $request)
    {
        $this->loadSession($connection);
        
        return $this->Kernel->handle($request);
    }
212497
protected function setModes(PDO $connection, array $config)
    {
        if (isset($config['modes'])) {
            $this->setCustomModes($connection, $config);
        } elseif (isset($config['strict'])) {
            if ($config['strict']) {
                $connection->prepare($this->strictMode($connection))->execute();
            } else {
                $connection->prepare("set session sql_mode='NO_ENGINE_SUBSTITUTION'")->execute();
            }
        }
    }
189972
protected function configure(Connection $connection, $type)
	{
		$connection = $this->setPdoForType($connection, $type);

		// First we'll set the fetch mode and a few other dependencies of the database
		// connection. This method basically just configures and prepares it to get
		// used by the application. Once we're finished we'll return it back out.
		if ($this->prop->getIs('events'))
		{
			$connection->setEventDispatcher($this->prop['events']);
		}

		// Here we'll set a reconnector callback. This reconnector can be any callable
		// so we will set a Closure to reconnect from this manager with the name of
		// the connection, which will allow us to reconnect from the connections.
		$connection->setReconnector(function ($connection) {
			$this->reconnect($connection->getName());
		});

		return $connection;
	}
801604
public function delete(string $table) : QueryBuilder
    {
        $this->_query[] = "DELETE FROM";
        $this->_query[] = "`". $this->sanitize($table) ."`";

        return $this;
    }
236889
protected function updateConnection($connection)
    {
        if ($this->connection !== $connection) {
            $this->connection  = $connection;
            $this->schemaSetUp = false;
        }

        return $this;
    }
799555
public function on($connection = null)
    {
        $this->schemas = new SchemaManager($this->db->connection($connection));

        return $this;
    }
701254
public function queryBuilder(ConnectionInterface $connection, String $connectionId=null) : QueryBuilderProvider
	{
		return new PdoQueryBuilder($connection, $connectionId);
	}
1072711
public static function getConnections($connection, $table)
    {
        $connections = DB::connection($connection)->table($table)->get();

        if(!empty($connections)) {
            /**
             * Create an empty array which will get populated with the data from
             * $connections in the correct format within the foreach statement
             * below file generation.
             */
            $config = array();
            /**
             * Generate a random string for the filename as it is temporary
             * and more secure.
             */
            $random_string = ConnectionLoader::random_string(35);
            /**
             * Append the .php extension to the file name and store here
             * storage_path/app/$tempFile with some starting content.
             */
            $tempFileName = $random_string . '.php';
            $tempFile = Storage::disk('local')->put($tempFileName, '<?php return ');

            if ($tempFile === true) {
                /**
                 * Loops through the connections checking the driver and pushes
                 * correctly formatted array into the $config array.
                 */
                foreach ($connections as $connection) {
                    $name = $connection->name;
                    $driver = $connection->driver;

                    if ($driver == 'sqlite') {

                        $connection_config = array(
                            'driver' => $driver,
                            'database' => database_path($connection->database),
                            'prefix' => $connection->prefix,
                        );

                        $config[$name] = $connection_config;

                    } elseif ($driver == 'mysql') {

                        $strict = $connection->strict;
                        if ($strict == 1) {
                            $strict = true;
                        } else {
                            $strict = false;
                        }
                        $password = $connection->password;

                        if(empty($password)) {
                            $connection_config = array(
                                'driver' => $driver,
                                'host' => $connection->host,
                                'database' => $connection->database,
                                'username' => $connection->username,
                                'password' => $password,
                                'charset' => $connection->charset,
                                'collation' => $connection->collation,
                                'prefix' => $connection->prefix,
                                'strict' => $strict,
                            );
                        }
                        else {
                            $connection_config = array(
                                'driver' => $driver,
                                'host' => $connection->host,
                                'database' => $connection->database,
                                'username' => $connection->username,
                                'password' => Crypt::decrypt($password),
                                'charset' => $connection->charset,
                                'collation' => $connection->collation,
                                'prefix' => $connection->prefix,
                                'strict' => $strict,
                            );
                        }

                        $config[$name] = $connection_config;

                    } elseif ($driver == 'pgsql') {

                        $password = $connection->password;

                        if(empty($password)) {
                            $connection_config = array(
                                'driver' => $driver,
                                'host' => $connection->host,
                                'port' => $connection->port,
                                'database' => $connection->database,
                                'username' => $connection->username,
                                'password' => $password,
                                'charset' => $connection->charset,
                                'prefix' => $connection->prefix,
                                'schema' => $connection->schema,
                            );
                        }
                        else {
                            $connection_config = array(
                                'driver' => $driver,
                                'host' => $connection->host,
                                'port' => $connection->port,
                                'database' => $connection->database,
                                'username' => $connection->username,
                                'password' => Crypt::decrypt($password),
                                'charset' => $connection->charset,
                                'prefix' => $connection->prefix,
                                'schema' => $connection->schema,
                            );
                        }

                        $config[$name] = $connection_config;
                    }
                }

                /**
                 * Append a var_export of $config to the temporary file and
                 * append the semicolon.
                 *
                 * Returns the temporary filename.
                 */
                $endFile = ';';
                Storage::append($tempFileName, var_export($config, true));
                Storage::append($tempFileName, $endFile);

                return $tempFileName;

            } else {
                \error_log('Unable to create temporary file');
            }
        } else {
            \error_log('Configuration File Connection Invalid.');
            return null;
        }
    }
1244482
private static function expandSqlite(Connection $connection)
    {
        // add support for REGEXP operator
        $connection->getWrappedConnection()->sqliteCreateFunction(
            'regexp',
            function ($pattern, $data, $delimiter = '~', $modifiers = 'isuS') {
                if (isset($pattern, $data)) {
                    return (preg_match(sprintf('%1$s%2$s%1$s%3$s', $delimiter, $pattern, $modifiers), $data) > 0);
                }

                return;
            }
        );
    }
361024
protected function compileCreateEncoding($sql, Connection $connection)
    {
        if (! is_null($charset = $connection->getConfig('charset'))) {
            $sql .= ' default character set '.$charset;
        }

        if (! is_null($collation = $connection->getConfig('collation'))) {
            $sql .= ' collate '.$collation;
        }

        return $sql;
    }
529643
private function buildBaseQuery(
        Connection $connection,
        TableMetadata $tableMetadata,
        string $searchTerm
    ): QueryBuilder {

        // Build query except WHERE clause
        $queryBuilder = $connection
            ->createQueryBuilder()
            ->select('COUNT(*) AS count')
            ->from('`' . $tableMetadata->getDatabaseName() . '`.`' . $tableMetadata->getTableName() . '`')
            ->setParameter('search_term', '%' . $searchTerm . '%');

        foreach ($this->getSearchableColumnNames($tableMetadata) as $index => $columnName) {
            $clause = '`' . $columnName . '` LIKE :search_term';
            if (0 === $index) {
                $queryBuilder->where($clause);
            } else {
                $queryBuilder->orWhere($clause);
            }
        }

        return $queryBuilder;
    }