Try to etablish a connetion to the database. Also assign the connection
and query builder to the current DB driver.

@param string|array 	$name	When passing an array it will be uesed as configuration.
@return void
508895
protected function connect( $name ) 
	{
		if ( $this->_connected ) 
		{
			return true; 
		}
		
		// check if the name is an array. This way we can
		// pass the configuration directly. We need this 
		// to create for example an handler without having
		// the configuration in the database conf file.
		if ( is_array( $name ) )
		{
			$config = $name;
		}
		else 
		{
			$config = \CCConfig::create( 'database' )->get( $name );
			
			// check for an alias. If you set a string 
			// in your config file we use the config 
			// with the passed key.
			if ( is_string( $config ) ) 
			{
				$config = \CCConfig::create( 'database' )->get( $config );
			}
		}

		// Setup the driver class. We simply use name 
		// from the confif file and make the first letter 
		// capital. example: Handler_Mysql, Handler_Sqlite etc.
		$driver_class = __NAMESPACE__."\\Handler_".ucfirst( $config['driver'] );
		
		if ( !class_exists( $driver_class ) )
		{
			throw new Exception( "DB\\Handler::connect - The driver (".$driver_class.") is invalid." );
		}
		
		$this->set_driver( $driver_class );
		
		// setup the builder the same way as the handler.
		$driver_class = __NAMESPACE__."\\Builder_".ucfirst( $config['driver'] );
		
		if ( !class_exists( $driver_class ) )
		{
			throw new Exception( "DB\\Handler::connect - The builder (".$driver_class.") is invalid." );
		}
		
		$this->set_builder( $driver_class );
		
		// finally try to connect the driver with the databse
		if ( $this->driver()->connect( $config ) ) 
		{
			return $this->_connected = true;
		}

		return $this->_connected = false;
	}
488936
public function removeConfiguration(string $name): void
	{
		unset($this->configurations[$name], $this->connections[$name]);
	}
375277
public function disconnect($name = '')
    {
        if (empty($name)) {
            $name = $this->dbName;
        }
        try {
            $this->db->disconnect($name);
            unset($this->db);
        }
        catch (\Exception $e) {
            $this->debug->error(__FUNCTION__, $e->getFile() . ' - Line: ' . $e->getLine() . ' - Message: ' . $e->getMessage());

            return NULL;
        }
    }
715255
public function setConnection($nameDB, $table){
        $this->nameDB= $nameDB;
        $this->table= $table;
        $this->connection= $this->connection->changeConnection($nameDB);
    }
12704
public function connection($name = null)
    {
        if ( ! isset($this->connections[$name]))
        {
            $this->connections[$name] = $this->createConnection($name);
        }

        return $this->connections[$name];
    }
133677
public function loadConfig($name)
    {
        // only if config not yet exists
        if (!$this->configExists($name))
            $this->config[$name] = $this->getConfigObjectFromDatabase($name);
    }
507512
public function referenceBegin($name): void
    {
        $this->client->sendBuffer .= $this->client->preparedToSendBuffer;
        $this->client->preparedToSendBuffer = null;
        $signature = sprintf('<H p="1" v="%s">', $name);
        $this->write($signature);
        $signature[6] = '2';
        $this->client->currentArgumentsFormat = $signature;
    }
1345652
private function bakeDatabaseConfig(string $name) : void
    {
        $options = [
            'path' => Configure::read('CsvMigrations.modules.path') . $name . DS . 'db' . DS,
            'ext' => 'json'
        ];

        $this->bake('migration.dist', 'Module/db/migration', [], '', $options);
    }
355597
public function dropIndex($name)
    {
        if (is_array($name))
            $name = $this->name.'___'.implode('__', $name);
        elseif(!is_int(strpos($name,'___')))
            $name = $this->name.'___'.$name;
        $name = $this->db->quotekey($name);
        $table = $this->db->quotekey($this->name);
        $cmd = array(
            'pgsql|sqlite2?|ibm' =>
                "DROP INDEX $name;",
            'mssql|sybase|dblib|odbc|sqlsrv' =>
                "DROP INDEX $table.$name;",
            'mysql'=>
                "ALTER TABLE $table DROP INDEX $name;",
        );
        $query = $this->findQuery($cmd);
        $this->queries[] = $query;
    }
236358
public function addConnection(array $config, $name = 'default')
    {
        $connections = $this->container['config']['database.connections'];

        $connections[$name] = $config;

        $this->container['config']['database.connections'] = $connections;
    }
458592
public function bind($name = null, $password = null)
    {
        if (strlen(trim($name)) > 0) {
            $password = (null === $password)?'':$password;
            $this->connection->bind($name, $password);
            $this->isBound = true;
            return;
        }

        if ($this->configuration['bind_anonymous']) {
            $this->connection->bind();
            $this->isBound = true;
            return;
        }

        $this->connection->bind(
            $this->configuration['bind_dn'],
            $this->configuration['bind_password']
        );
        $this->isBound = true;
    }
181781
public function setName($name)
    {
        $this->name = $name;

        if ($this->id === null) {
            $this->id = $name;
        }
    }
163951
private function dropColumnOnSqlite($name)
    {
        $pdo = Database::getPdo();

        $names = (array) $name;

        $statement = $pdo->query(sprintf('PRAGMA table_info(%s);', $this->table));

        $statement->execute();

        $sql = [];

        foreach ($statement->fetchAll() as $column) {
            if (!in_array($column->name, $names)) {
                $select[] = $column->name;
            }
        }

        $pdo->exec('BEGIN TRANSACTION;');

        $pdo->exec(sprintf(
            'CREATE TABLE __temp_sqlite_table AS SELECT %s FROM %s;',
            implode(', ', $select),
            $this->table
        ));

        $pdo->exec(sprintf('DROP TABLE %s;', $this->table));

        $pdo->exec(sprintf('ALTER TABLE __temp_sqlite_table RENAME TO %s;', $this->table));

        $pdo->exec('COMMIT;');
    }
452456
protected function dbseed($name)
    {
        $params = [
            '--class' => $this->option('class') ?: $this->getSeederName($name),
        ];

        if ($option = $this->option('database')) {
            $params['--database'] = $option;
        }

        $this->call('db:seed', $params);
    }
562804
public function connect(array $config, string $name = 'main'): Connection
    {
        if (isset($this->connections[$name])) {
            throw new InvalidArgumentException("Connection [$name] is already configured.");
        }

        $this->connections[$name] = new Connection($config);

        return $this->connections[$name];
    }
996564
protected function insertRecord($name)
    {
        try {
            return (bool) $this->db
                    ->insert(array(
                        $this->columns['name'] => $name,
                        $this->columns['data'] => serialize($this->cache[$name]->toArray()),
                    ))
                    ->into($this->table);
        } catch (PDOException $e) {
            return false;
        }
    }
1344496
static public function connection($name = null)
    {
        if ($name === null) {
            $name = self::$activeConnectionName;
            
            if (!$name) {
                if (self::$defaultConnectionName) {
                    $name = self::$defaultConnectionName;
                    self::setConnection($name);
                    self::$defaultConnectionName = null;
                } else {
                    throw new Exception\RuntimeException("No database connection is active");
                }
            }
        } else {
            self::create_connection($name);
        }
        
        return self::$_connections[$name];
    }