Sets the database connection.

@param \PDO $connection Connection

@return AdapterInterface
331203
public function setConnection(\PDO $connection)
    {
        $this->connection = $connection;

        // Create the schema table if it doesn't already exist
        if (!$this->hasSchemaTable()) {
            $this->createSchemaTable();
        } else {
            $table = new Table($this->getSchemaTableName(), [], $this);
            if (!$table->hasColumn('migration_name')) {
                $table
                    ->addColumn('migration_name', 'string',
                        ['limit' => 100, 'after' => 'version', 'default' => null, 'null' => true]
                    )
                    ->save();
            }
            if (!$table->hasColumn('breakpoint')) {
                $table
                    ->addColumn('breakpoint', 'boolean', ['default' => false])
                    ->save();
            }
        }

        return $this;
    }
122759
public function addConnection(LdapConnectionInterface ...$connections)
    {
        foreach ($connections as $connection) {
            $this->domains[$connection->getConfig()->getDomainName()] = $connection->getConfig();
            $this->connections[$connection->getConfig()->getDomainName()] = $connection;
        }

        return $this;
    }
576037
private function getDatabasePlatform(Connection $connection)
    {
        try {
            return $connection->getDatabasePlatform();
        } catch (DriverException $driverException) {
            throw new DBALException(
                'An exception occured while establishing a connection to figure out your platform version.' . PHP_EOL .
                "You can circumvent this by setting a 'server_version' configuration value" . PHP_EOL . PHP_EOL .
                'For further information have a look at:' . PHP_EOL .
                'https://github.com/doctrine/DoctrineBundle/issues/673',
                0,
                $driverException
            );
        }
    }
1013551
public function setConnection($connection)
	{
		if (is_string($connection)) {
			$connection = Yii::$app->{$connection};
		}
		$this->_connection = $connection;
	}
929483
public function create(Connection $connection)
    {
        // Get config with containing all metadata drivers
        $configuration = $this->configFactory->getConfiguration();

        // Get orm event manager
        $eventManager = $connection->getEventManager();

        // Pass the database connection, the orm config and the event manager 
        // to the concrete5 event system so packages can hook in to the process
        // and alter the values
        $event = new \Symfony\Component\EventDispatcher\GenericEvent();
        $event->setArgument('connection', $connection);
        $event->setArgument('configuration', $configuration);
        $event->setArgument('eventManager', $eventManager);
        Events::dispatch('on_entity_manager_configure', $event);

        // Reasign the values from the dispatched event
        $conn   = $event->getArgument('connection');
        $config = $event->getArgument('configuration');
        $evm    = $event->getArgument('eventManager');

        // Inject the orm eventManager into the entityManager so orm events
        // can be triggered.
        return EntityManager::create($conn, $config, $evm);
    }
102987
protected function connect(string $connection): Redis
	{
		if(!isset($this->configurations[$connection]))
		{
			throw new RuntimeException(vsprintf('[ %s ] has not been defined in the redis configuration.', [$connection]));
		}

		$config = $this->configurations[$connection];

		return new Redis(new Connection($config['host'], $config['port'], $config['persistent'] ?? false, $config['timeout'] ?? 60, $connection), $config);
	}
1358175
protected function getNewConnection($connections)
    {
        $connection = $this->ApplicationContext->object($this->DatabaseServiceName);
        $connection->setConnectionInfo($connections);
        return $connection;
    }
940236
public function on($connection)
    {
        $this->setDatabase($connection);
        $this->_connection = null;

        $this->setDatabaseConnection($this->getDatabase());

        return $this;
    }
955841
protected function selectSQLDriver($connection)
    {
        switch (strtolower($connection)) {
            case 'mysql':
                $this->db = [
                    'driver'   => 'pdo_mysql',
                    'host'     => env('DB_HOST', '127.0.0.1'),
                    'port'     => env('DB_PORT', '3306'),
                    'dbname'   => env('DB_DATABASE', 'teamelf'),
                    'user'     => env('DB_USERNAME', 'teamelf'),
                    'password' => env('DB_PASSWORD', 'teamelf'),
                    'charset'  => 'UTF8'
                ];
                break;
            default:
                throw new Exception($connection . 'has not been supported yet! use [mysql] instead!');
        }
    }
640202
public function setConnection(Connection $connection)
    {
        if (! in_array($connection, $this->_connections, true)) {
            $this->_connections[] = $connection;
        }
    }
490158
protected function createConnection($pdo)
    {
        $params = [
            'user' => $this->config['username'],
            'password' => $this->config['password'],
            'pdo' => $pdo,
            'driverClass' => DoctrineDriver::class,
        ];
        $this->doctrineConnection = \Doctrine\DBAL\DriverManager::getConnection($params);
    }
486701
public function setDriver( IDriver $driver ) : Connection
   {

      $this->_driver = $driver;
      $this->_pdo    = null;

      return $this;

   }
596591
public function setPdo($pdo)
    {
        $this->connection = $this->createConnection();
        $this->getManagedConfigure($this->config);
        $this->useDefaultQueryGrammar();
        $this->useDefaultPostProcessor();

        return $this;
    }
144584
protected function setCustomModes(PDO $connection, array $config)
    {
        $modes = implode(',', $config['modes']);

        $connection->prepare("set session sql_mode='{$modes}'")->execute();
    }
1269658
public function setConnection()
	{
		$connection = Config::get('core::database.default');

		if ($connection !== 'default')
		{
			$wardrobeConfig = Config::get('core::database.connections.'.$connection);
		}
		else
		{
			$connection = Config::get('database.default');
			$wardrobeConfig = Config::get('database.connections.'.$connection);
		}

		Config::set('database.connections.wardrobe', $wardrobeConfig);
	}
1283630
protected function configure(Connection $connection, $name)
    {
        $connection->setName($name);

        if ($this->events && $this->app->bound('events')) {
            $connection->setEventDispatcher($this->app->make('events'));
        }

        return $connection;
    }
280887
private static function setConnectionCharset(Connection $connection, array $options = array())
    {
        if (isset($options['charset'])) {
            try {
                if ('pdo_mysql' === $connection->getDriver()->getName()) {
                    $connection->executeQuery('SET SESSION character_set_client = "'.addslashes($options['charset']).'";');
                    $connection->executeQuery('SET SESSION character_set_connection = "'.addslashes($options['charset']).'";');
                    $connection->executeQuery('SET SESSION character_set_results = "'.addslashes($options['charset']).'";');
                }
            } catch (\Exception $e) {
                throw new InvalidArgumentException(
                    sprintf('Invalid database character set `%s`', $options['charset']),
                    InvalidArgumentException::INVALID_ARGUMENT,
                    $e
                );
            }
        }
    }