save one Database
@param string $dbconfiguration Database configuration name
@return Renderer
@throws Exception
480535
public function updateActivity(string $dbconfiguration):Renderer
    {
        $config   = $dbconfiguration;
        $name     = $this->clean($this->get("request")->get("name"), false);
        $host     = $this->get("request")->get("host");
        $user     = $this->get("request")->get("user");
        $password = $this->get("request")->get("password");
        $port     = $this->get("request")->get("port");
        $driver   = $this->get("request")->get("driver");

        if (trim($name) == ""  || trim($host) == "" || trim($user) == "" || trim($driver) == "") {
            return ((new Renderer())->jsonRenderer(array("code" => 500,
                "msg" => "Error on databases parameters : A parameter is empty")));
        }

        $file = JL::open(FEnv::get("framework.config.db.file"));
        if (!isset($file->$config)) {
            return ((new Renderer())->jsonRenderer(array("code" => 500,
                "msg" => "Error on databases parameters : Database configuration does not exist")));
        }

        $file->$config = new \stdClass();
        $file->$config->db_name = $name;
        $file->$config->db_host = $host;
        $file->$config->db_port = $port;
        $file->$config->db_user = $user;
        $file->$config->db_password = $password;
        $file->$config->db_driver = $driver;

        JL::put(FEnv::get("framework.config.db.file"), json_encode($file, JSON_PRETTY_PRINT));

        return ((new Renderer())->jsonRenderer(array("code" => 200, "msg" => "OK")));
    }
38105
public function save()
    {
        $values = $this->prepareValuesToSave();

        if ($this->isNew()) {
            if (!$resource = $this->class->createInstanceWithProperties($values)) {
                throw new common_Exception(__('Unable to save resource.'));
            }
            $this->resource = $resource;
        } else {
            $binder = new tao_models_classes_dataBinding_GenerisFormDataBinder($this->resource);
            $binder->bind($values);
        }

        return $this->resource;
    }
670513
public static function getInstance($db)
    {
        if (!isset(self::$instances[$db])) {
            $config = config('database.' . $db);
            if (!$config) {
                throw new RuntimeException('Not found database config [' . $db . '], Please checking file config/database.php');
            }

            switch ($config['driver']) {
                case 'mysql':
                    self::$instances[$db] = new MysqlConnection($config);
                    break;
            }
        }

        return self::$instances[$db];
    }
400028
public function getDefaultDatabase()
    {
        if (!isset($this->_config['database'])) {
            throw new Exception(sprintf('You have not configured a default database for Datasource %s yet.', $this->_config['name']));
        }
        $db = $this->_config['database'];
        return $this->connect()->database($db);
    }
44754
public static function setDbType($dbType) {
        $dbTypeCast = (string) $dbType;
        
        if (array_search($dbTypeCast, self::$dbList) === false) {
            throw new DBException('Illegal database type provided to DB Service');
        }
        
        self::$dbType = $dbTypeCast;
    }
914531
public function createDatabaseObject()
    {
        $dbname = trim($this->getSubmitValue('dbname'));
        if (empty($dbname)) // disallow database object creation w/ no selected database
        {
            throw new Exception("No database name");
        }

        $adapter = $this->getSubmitValue('adapter');
        $port = Adapter::getDefaultPortForAdapter($adapter);

        $host = $this->getSubmitValue('host');
        $tables_prefix = $this->getSubmitValue('tables_prefix');
        
        $dbInfos = array(
            'host'          => (is_null($host)) ? $host : trim($host),
            'username'      => $this->getSubmitValue('username'),
            'password'      => $this->getSubmitValue('password'),
            'dbname'        => $dbname,
            'tables_prefix' => (is_null($tables_prefix)) ? $tables_prefix : trim($tables_prefix),
            'adapter'       => $adapter,
            'port'          => $port,
            'schema'        => Config::getInstance()->database['schema'],
            'type'          => $this->getSubmitValue('type')
        );

        if (($portIndex = strpos($dbInfos['host'], '/')) !== false) {
            // unix_socket=/path/sock.n
            $dbInfos['port'] = substr($dbInfos['host'], $portIndex);
            $dbInfos['host'] = '';
        } else if (($portIndex = strpos($dbInfos['host'], ':')) !== false) {
            // host:port
            $dbInfos['port'] = substr($dbInfos['host'], $portIndex + 1);
            $dbInfos['host'] = substr($dbInfos['host'], 0, $portIndex);
        }

        try {
            @Db::createDatabaseObject($dbInfos);
        } catch (Zend_Db_Adapter_Exception $e) {
            $db = Adapter::factory($adapter, $dbInfos, $connect = false);

            // database not found, we try to create  it
            if ($db->isErrNo($e, '1049')) {
                $dbInfosConnectOnly = $dbInfos;
                $dbInfosConnectOnly['dbname'] = null;
                @Db::createDatabaseObject($dbInfosConnectOnly);
                @DbHelper::createDatabase($dbInfos['dbname']);

                // select the newly created database
                @Db::createDatabaseObject($dbInfos);
            } else {
                throw $e;
            }
        }

        return $dbInfos;
    }
598880
private function getDbConfig() {
        if (file_exists(MODULES_DIR . DS . $this->currentRoute['module'] . '/Config/database.php')) {
            $dbConfig = require_once MODULES_DIR . DS . $this->currentRoute['module'] . '/Config/database.php';

            if (!empty($dbConfig) && is_array($dbConfig)) {
                return $dbConfig;
            } else {
                throw new \Exception(ExceptionMessages::INCORRECT_CONFIG);
            }
        } else {
            if (file_exists(BASE_DIR . '/config/database.php')) {
                $dbConfig = require_once BASE_DIR . '/config/database.php';
                if (!empty($dbConfig) && is_array($dbConfig)) {
                    return $dbConfig;
                } else {
                    throw new \Exception(ExceptionMessages::INCORRECT_CONFIG);
                }
            } else {
                throw new \Exception(ExceptionMessages::DB_CONFIG_NOT_FOUND);
            }
        }
    }
1134752
public function createDatabase($connectionName)
    {
        $configuration = $this->getConfiguration($connectionName);
        $database = $this->getConnection($connectionName);

        $database->DBCreate(
            $configuration->getDatabase(),
            $configuration->getDataType(),
            $configuration->getStorageType()
        );

        return $this->getDatabase($connectionName);
    }
440960
public function cache()
    {
        if ($this->cache !== null) {
            return $this->cache;
        }
        switch ($this->driver) {
            case self::DRIVER_MYSQL:
                return $this->cache = new Cache\MySQL\Manage($this->pdo);
        }
        throw new DatabaseException('Unsupported PDO driver.');
    }
146095
private function createConfigFile($dbInfos)
    {
        $config = Config::getInstance();

        // make sure DB sessions are used if the filesystem is NFS
        if (count($headers = ProxyHeaders::getProxyClientHeaders()) > 0) {
            $config->General['proxy_client_headers'] = $headers;
        }
        if (count($headers = ProxyHeaders::getProxyHostHeaders()) > 0) {
            $config->General['proxy_host_headers'] = $headers;
        }

        if (Common::getRequestVar('clientProtocol', 'http', 'string') == 'https') {
            $protocol = 'https';
        } else {
            $protocol = ProxyHeaders::getProtocolInformation();
        }

        if (!empty($protocol)
            && !\Piwik\ProxyHttp::isHttps()) {
            $config->General['assume_secure_protocol'] = '1';
        }

        $config->General['salt'] = Common::generateUniqId();
        $config->General['installation_in_progress'] = 1;

        $config->database = $dbInfos;
        if (!DbHelper::isDatabaseConnectionUTF8()) {
            $config->database['charset'] = 'utf8';
        }

        $config->forceSave();

        // re-save the currently viewed language (since we saved the config file, there is now a salt which makes the
        // existing session cookie invalid)
        $this->resetLanguageCookie();
    }
529887
public function connect( $config )
    {
        if ( $config !== NULL )
        {
            $this->host     = $config[ 'db_host' ];
            $this->user     = $config[ 'db_user' ];
            $this->password = $config[ 'db_pass' ];
            $this->name     = $config[ 'db_name' ];

            try
            {
                $dns = "mysql:host=" . $this->host . ";dbname=" . $this->name;

                $this->database = new PDO( $dns, $config[ 'db_user' ], $config[ 'db_pass' ] );
            }
            catch ( Exception $e )
            {
                throw new DatabaseException( $e->getMessage() );
            }
        }
    }
582544
protected function processConfigurationTraitDatabase(&$configuration)
    {
        if(!isset($configuration['database'])) {
            throw new \Exception('missing database parameters into configuration');
        } else {
            $this->setDBParameters($configuration['database']['driver'], $configuration['database']['host'], $configuration['database']['username'], $configuration['database']['password'], $configuration['database']['database'], $configuration['database']['schema']);
        }
    }
787160
private function configureDatabase(array $config) {
        if (!isset($config['database']) || !isset($config['database']['adapter'])) {
            throw new InvalidArgumentException('Missing database adapter configuration for the image variations event listener', 500);
        }

        $config = $config['database'];

        if (is_callable($config['adapter'])) {
            $databaseAdapter = $config['adapter']();
        } else if (is_string($config['adapter'])) {
            $databaseAdapter = new $config['adapter'](isset($config['params']) ? $config['params'] : null);
        } else {
            $databaseAdapter = $config['adapter'];
        }

        if (!($databaseAdapter instanceof DatabaseInterface)) {
            throw new InvalidArgumentException('Invalid database adapter for the image variations event listener', 500);
        }

        $this->database = $databaseAdapter;
    }
4097
public function initialize()
	{
		//throw exception if no database type has been set
		if( ! $this->type )
		{
			//Throw exception
			throw new DbException("Invalid database type provided");
			
		}

		//check the type of  database provided returning instance
		//set the parameter to check in switch clause
		switch ($this->type ) 
		{
			case 'mysql':

				return new MySQL($this->options);

				break;
			
			default:

				throw new DbException("Valid database type provided");
				

				break;
		}

	}
162929
public static function useNewDatabaseDriver($configuration): void
    {
        static::throwExceptionIfHasStarted();

        $driver = new Database();
        $driver->setNewDatabase($configuration);

        static::$driver = $driver;
    }
1090406
function databaseSetup()
    {
        $this->checkPiwikIsNotInstalled();

        $view = new View(
            '@Installation/databaseSetup',
            $this->getInstallationSteps(),
            __FUNCTION__
        );

        $view->showNextStep = false;

        $form = new FormDatabaseSetup();

        if ($form->validate()) {
            try {
                $dbInfos = $form->createDatabaseObject();

                DbHelper::checkDatabaseVersion();

                Db::get()->checkClientVersion();

                $this->createConfigFile($dbInfos);

                $this->redirectToNextStep(__FUNCTION__);
            } catch (Exception $e) {
                $view->errorMessage = Common::sanitizeInputValue($e->getMessage());
            }
        }
        $view->addForm($form);

        return $view->render();
    }
668947
public static function getDatabaseConfig($dbConfig = null)
    {
        $config = Config::getInstance();

        if (is_null($dbConfig)) {
            $dbConfig = $config->database;
        }

        /**
         * Triggered before a database connection is established.
         *
         * This event can be used to change the settings used to establish a connection.
         *
         * @param array *$dbInfos Reference to an array containing database connection info,
         *                        including:
         *
         *                        - **host**: The host name or IP address to the MySQL database.
         *                        - **username**: The username to use when connecting to the
         *                                        database.
         *                        - **password**: The password to use when connecting to the
         *                                       database.
         *                        - **dbname**: The name of the Piwik MySQL database.
         *                        - **port**: The MySQL database port to use.
         *                        - **adapter**: either `'PDO\MYSQL'` or `'MYSQLI'`
         *                        - **type**: The MySQL engine to use, for instance 'InnoDB'
         */
        Piwik::postEvent('Db.getDatabaseConfig', array(&$dbConfig));

        $dbConfig['profiler'] = @$config->Debug['enable_sql_profiler'];

        return $dbConfig;
    }