Configure the database.

@param array $default

@return void
771589
protected function configureDatabase(array $default = [])
    {
        $config = array_merge([
            'DB_DRIVER'   => null,
            'DB_HOST'     => null,
            'DB_DATABASE' => null,
            'DB_USERNAME' => null,
            'DB_PASSWORD' => null,
            'DB_PORT'     => null,
            'DB_PREFIX'   => null,
        ], $default);

        $config['DB_DRIVER'] = $this->choice('Which database driver do you want to use?', [
            'mysql'      => 'MySQL',
            'pgsql'      => 'PostgreSQL',
            'sqlite'     => 'SQLite',
        ], $config['DB_DRIVER']);

        if ($config['DB_DRIVER'] === 'sqlite') {
            $config['DB_DATABASE'] = $this->ask('Please provide the full path to your SQLite file.', $config['DB_DATABASE']);
        } else {
            $config['DB_HOST'] = $this->ask("What is the host of your {$config['DB_DRIVER']} database?", $config['DB_HOST']);
            if ($config['DB_HOST'] === 'localhost' && $config['DB_DRIVER'] === 'mysql') {
                $this->warn("Using 'localhost' will result in the usage of a local unix socket. Use 127.0.0.1 if you want to connect over TCP");
            }

            $config['DB_DATABASE'] = $this->ask('What is the name of the database that Cachet should use?', $config['DB_DATABASE']);

            $config['DB_USERNAME'] = $this->ask('What username should we connect with?', $config['DB_USERNAME']);

            $config['DB_PASSWORD'] = $this->secret('What password should we connect with?', $config['DB_PASSWORD']);

            $config['DB_PORT'] = $config['DB_DRIVER'] === 'mysql' ? 3306 : 5432;
            if ($this->confirm('Is your database listening on a non-standard port number?')) {
                $config['DB_PORT'] = $this->anticipate('What port number is your database using?', [3306, 5432], $config['DB_PORT']);
            }
        }

        if ($this->confirm('Do you want to use a prefix on the table names?')) {
            $config['DB_PREFIX'] = $this->ask('Please enter the prefix now...', $config['DB_PREFIX']);
        }

        // Format the settings ready to display them in the table.
        $this->formatConfigsTable($config);

        if (!$this->confirm('Are these settings correct?')) {
            return $this->configureDatabase($config);
        }

        foreach ($config as $setting => $value) {
            $this->writeEnv($setting, $value);
        }
    }
885117
public function setDefault($default)
    {
        if ($default !== null && !$this->getDataType()->doesAllowDefault()) {
            throw new LogicException(
                sprintf(
                    'Unable to set default value for the column. The data-type "%s" does not support a default.',
                    $this->getDataType()->getType()
                )
            );
        }

        if (is_array($default)) {
            foreach ($default as $k => $v) {
                $default[$k] = $this->getDataType()->cast($v);
            }
        } elseif ($default !== null) {
            if (!($this->getDataType() instanceof TimeTypeInterface)) {
                $default = $this->getDataType()->cast($default);
            }
        }

        $this->default = $default;
    }
959978
public function setDefaultsFromConfiguration()
    {
        if ($this->options['dsn']) {
            $dsn = explode(':', $this->options['dsn']);
            $this->setSQLDialect($dsn[0]);
        }

        $this->setTablePrefix($this->options['table_prefix']);
    }
1203631
protected function initDefaults($defaults)
    {
        if (!$defaults) {
            return;
        }

        $defaults = $this->fetchParameters($defaults);
        $this->initDefaultsInConfigArray($defaults);
    }
763004
protected function _initialize()
    {
        $config = $this->_config->get('joomla');

        if(is_null($config) || !is_array($config)) {
            $config = array();
        }

        $defaults = array(
            'name' => 'root',
            'username'  => 'root',
            'groups'    => array(8),
            'email'     => 'root@localhost.home'
        );

        $this->_credentials = array_merge($defaults, $config);

        $this->_bootstrap();
        $this->_loadFramework();
    }
547717
protected function configure()
	{
		$this->setName( self::$defaultName );
		$this->setDescription( 'Clears the content cache' );
		$this->addArgument( 'site', InputArgument::OPTIONAL, 'Site codes to clear the cache like "default unittest" (none for all)' );
	}
1325677
private function loadDatabases()
	{
		$databaseKeys = $this->config->get('databases:keys')?: [];

		if (!isset($databaseKeys['database'])) $databaseKeys[] = 'database'; // Default database config key

		foreach ($databaseKeys as $databaseKey) {
			$database = $this->config->get($databaseKey);
			if ($database !== false) $this->initConnection($database, $databaseKey);
			$this->config->destroy($databaseKey);
			unset($database);
		}
    }
901583
public function buildDefaults()
    {
        $da = DatabaseAdmin::create();

        $renderer = null;
        if (!Director::is_cli()) {
            $renderer = DebugView::create();
            echo $renderer->renderHeader();
            echo $renderer->renderInfo("Defaults Builder", Director::absoluteBaseURL());
            echo "<div class=\"build\">";
        }

        $da->buildDefaults();

        if (!Director::is_cli()) {
            echo "</div>";
            echo $renderer->renderFooter();
        }
    }
932632
protected function setLocalDbConfig() {
    $config_local_db = $this->confirm("Would you like to configure the local database credentials?");
    $db = [];

    if ($config_local_db) {
      $default_db = $this->getConfigValue('drupal.db');
      $db['database'] = $this->askDefault("Local database name",
        $default_db['database']);
      $db['username'] = $this->askDefault("Local database user",
        $default_db['username']);
      $db['password'] = $this->askDefault("Local database password",
        $default_db['password']);
      $db['host'] = $this->askDefault("Local database host",
        $default_db['host']);
      $db['port'] = $this->askDefault("Local database port",
        $default_db['port']);
      $this->getConfig()->set('drupal.db', $db);
    }

    return $db;
  }
1080326
protected function set_defaults()
	{
		$this->options   = $this->default_options;
		$this->params    = $this->default_params;
		return $this;
	}
289086
public function setDefault($default) {
        // Check, warn and auto-fix '' (empty) defaults for CHAR NOT NULL columns, changing them
        // to NULL so XMLDB will apply the proper default
        if ($this->type == XMLDB_TYPE_CHAR && $this->notnull && $default === '') {
            $this->errormsg = 'XMLDB has detected one CHAR NOT NULL column (' . $this->name . ") with '' (empty string) as DEFAULT value. This type of columns must have one meaningful DEFAULT declared or none (NULL). XMLDB have fixed it automatically changing it to none (NULL). The process will continue ok and proper defaults will be created accordingly with each DB requirements. Please fix it in source (XML and/or upgrade script) to avoid this message to be displayed.";
            $this->debug($this->errormsg);
            $default = null;
        }
        // Check, warn and autofix TEXT|BINARY columns having a default clause (only null is allowed)
        if (($this->type == XMLDB_TYPE_TEXT || $this->type == XMLDB_TYPE_BINARY) && $default !== null) {
            $this->errormsg = 'XMLDB has detected one TEXT/BINARY column (' . $this->name . ") with some DEFAULT defined. This type of columns cannot have any default value. Please fix it in source (XML and/or upgrade script) to avoid this message to be displayed.";
            $this->debug($this->errormsg);
            $default = null;
        }
        $this->default = $default;
    }
894909
public function setDefault(): void
	{
		$repo = $this->getRepository();
		$locales = $repo->findAll();
		foreach ($locales as $locale) {
			/* @var $locale self */
			$locale->default = false;
			$repo->persist($locale);
		}
		$this->default = true;
		$repo->persist($this);
		$repo->flush();
	}
1137302
public function connection()
    {
        $db = ConnectionManager::get('default');
        foreach ($db->config() as $key => $value) {
            if (is_array($value)) {
                continue;
            }
            $this->out(sprintf('- %s: %s', $key, $value));
        }
    }
92283
protected function setDefaultConfig($args)
    {
        if (!current($this->config)) {
            $this->config = $this->toArray($args);
        }
    }
69987
public function setData($property = AnDomain::ACCESS_PUBLIC, $default = null)
    {
        $config_file_path = ANPATH_SITE.DS.'components'.DS.$this->package.DS.'config.json';

        if(file_exists($config_file_path)) {

            $app_config = json_decode(file_get_contents($config_file_path));
            $fields = $app_config->fields;

            foreach ($fields as $field) {
                $key = $field->name;
                if(isset($property['meta'][$key])){
                    $this->setValue($key, $property['meta'][$key]);
                }
            }
        }

        parent::setData($property, $default);
    }
1060535
private function initDbal()
	{
		$app = $this->getApp();

		$config = $app->getConfig();

		$config->load('db', true);
		$config->load('dbal', true);

		$this->defaultConfig = Arr::filterKeys($config->get('dbal', []), ['connections', 'types'], true);

		// Register types
		foreach ($config->get('dbal.types', []) as $type => $class)
		{
			Type::addType($type, $class);
		}
	}
311431
public function connect(array $config){

		// Defaults
		$defaults = array(
			'resource' => null,
			'charset' => 'utf8',
			'username' => ini_get('mysql.default_user'),
			'password' => ini_get('mysql.default_password'),
			'host' => ini_get('mysql.default_host'),
			'port' => ini_get('mysql.default_port'),
			'persistent' => false,
			'unbuffered' => false
		);

		$config += $defaults;
		if(isset($config['port']))
			$host = $config['host'] . ':' . $config['port'];
		else
			$host = $config['host'];

		// Connect
		if(is_resource($config['resource']))
			$connection = $config['resource'];
		elseif($config['persistent'])
			$connection = @mysql_pconnect($host, $config['username'], $config['password']);
		else
			$connection = @mysql_connect($host, $config['username'], $config['password']);

		if(!is_resource($connection))
			throw new DriverException("Connection to host '$host' failed.");

		// Select DB
		if(isset($config['database'])){
			$db = mysql_select_db($config['database']);
			if(!$db)
				throw new DriverException("Could not select database '$config[database]'.");
		}

		$this->resource = $connection;

		//Set charset
		if(is_resource($connection)){
			if(function_exists('mysql_set_charset'))
				@mysql_set_charset($config['charset'], $connection);
			else
				$this->runQuery("SET NAMES " . $config['charset']);
		}

		$this->unbuffered = $config['unbuffered'];
	}