Load database connection
975063
private function _loadDatabase()
    {
        if (!isset(self::$db[$this->name])) {
            $config = Config::config()->{$this->name};
            if(!is_array($config))
                throw new \Exception ($config . ' not a valid db config');
            // Load database
            $db = new Database($config);

            self::$db[$this->name] = $db;
            self::$prefix = isset($config['prefix']) ? $config['prefix'] : '';
        }

        return $this->getDb();
    }
875261
def connect(self):
        
        self.log.debug('starting the ``get`` method')

        dbSettings = self.dbSettings

        port = False
        if "tunnel" in dbSettings and dbSettings["tunnel"]:
            port = self._setup_tunnel(
                tunnelParameters=dbSettings["tunnel"]
            )

        # SETUP A DATABASE CONNECTION
        host = dbSettings["host"]
        user = dbSettings["user"]
        passwd = dbSettings["password"]
        dbName = dbSettings["db"]
        dbConn = ms.connect(
            host=host,
            user=user,
            passwd=passwd,
            db=dbName,
            port=port,
            use_unicode=True,
            charset='utf8',
            local_infile=1,
            client_flag=ms.constants.CLIENT.MULTI_STATEMENTS,
            connect_timeout=36000,
            max_allowed_packet=51200000
        )
        if self.autocommit:
            dbConn.autocommit(True)

        self.log.debug('completed the ``get`` method')
        return dbConn
584025
def main():
    """"""
    logger.info('Waiting for database: `%s`', MYSQL_DB)

    connect_mysql(
        host=MYSQL_HOST, port=MYSQL_PORT,
        user=MYSQL_USER, password=MYSQL_PASSWORD,
        database=MYSQL_DB
    )

    logger.info('Database `%s` found', MYSQL_DB)
1092288
def load_database
      if dir_exists?
        config = {
          'adapter' => 'sqlite3',
          'database' => File.join(config_dir, DATABASE_FILE),
          'pool' => 5,
          'timeout' => 5000
        }

        begin
          ActiveRecord::Base.establish_connection(config)
          ActiveRecord::Migrator.migrate(File.join(File.dirname(__FILE__), \
            '../../db/migrate'), ENV['VERSION'] ? ENV['VERSION'].to_i : nil )

        rescue StandardError => e
          raise DatabaseAccessError, e.message
        end
      else
        raise ConfigDirMissingError, 'Config dir missing. Run init command'
      end
    end
1342579
private function loadingDatabases()
    {
        $database = [];
        if ($_SERVER['HTTP_HOST'] == SERVER_DEVELOP) {
            if (!is_file(SYSTEM_ROOT . '/config/database.local.php'))
                @copy(SYSTEM_ROOT . '/config/database.sample.php', SYSTEM_ROOT . '/config/database.local.php');
            require_once('config/database.local.php');
        } else {
            if (!is_file(SYSTEM_ROOT . '/config/database.php'))
                @copy(SYSTEM_ROOT . '/config/database.sample.php', SYSTEM_ROOT . '/config/database.php');
            require_once('config/database.php');
        }
        foreach ($database as $connect) {
            $object = $connect['objectName'];
            $this->DB[$object] = new DBconnect($connect['dbHost'], $connect['port'], $connect['dbUsername'],
                $connect['dbPassword'], $connect['dbName'], $connect['dbCharset'], $connect['dbType']);
        }
    }
397792
def connect_db(database_name=":memory:"):
    
    db = repo.Repo.connect_db(database_name)
    base.Repo.db = db
    query.Repo.db = db
96505
def _connect(self):
        
        self._close()
        self.conn = MySQLdb.Connect(host=self.hostname,
                                    port=self.port,
                                    user=self.username,
                                    passwd=self.password,
                                    db=self.database)
652434
protected static function _setupDb($connection_name = self::DEFAULT_CONNECTION) {

        if (!array_key_exists($connection_name, static::$_db) ||
            !is_object(static::$_db[$connection_name])) {

            static::_initDbConfigWithDefaultVals($connection_name);

            $db = new \PDO(
                static::$_config[$connection_name]['connection_string'],
                static::$_config[$connection_name]['username'],
                static::$_config[$connection_name]['password'],
                static::$_config[$connection_name]['driver_options']
            );

            $db->setAttribute(\PDO::ATTR_ERRMODE, static::$_config[$connection_name]['error_mode']);
            static::setDb($db, $connection_name);
        }
    }
822944
private function tryConnect(): void
    {
        $config = $this->getConfig();

        $pdoConfig = [
          PDO::ATTR_EMULATE_PREPARES => false,
          PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
          PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
        ];

        if (isset($config['adapter_options'])) {
            foreach ($config['adapter_options'] as $key => $value) {
                $pdoConfig[$key] = $value;
            }
        }

        if (isset($config['path'])) {
            $path = $config['path'];
            if (substr($path, 0, 8) == 'storage:') {
                $path = Application::getStoragePath(substr($path, 8));
            }
        } else {
            $path = Application::getStoragePath('data/database.sqlite');
        }

        $directory = dirname($path);
        if (!is_dir($directory)) {
            Directory::mkdir($directory, 0755);
        }

        $this->pdo = new PDO('sqlite:' . $path);
        foreach ($pdoConfig as $key => $value) {
            $this->pdo->setAttribute($key, $value);
        }

        // create needed function(s)
        $this->pdo->sqliteCreateFunction('ILIKE', function ($mask, $value) {
            $mask = str_replace(['%', '_'], ['.*?', '.'], preg_quote($mask, '/'));
            $mask = "/^$mask$/ui";
            return preg_match($mask, $value);
        }, 2);
    }
1329207
protected static function _setupDb($connection_name = self::DEFAULT_CONNECTION)
        {
            if (!Arrays::exists($connection_name, self::$_db) || !is_object(self::$_db[$connection_name])) {
                self::_setupDbConfig($connection_name);

                $db = new PDO(
                    self::$_config[$connection_name]['connection_string'],
                    self::$_config[$connection_name]['username'],
                    self::$_config[$connection_name]['password'],
                    self::$_config[$connection_name]['driver_options']
                );

                $db->setAttribute(PDO::ATTR_ERRMODE, self::$_config[$connection_name]['error_mode']);

                self::set_db($db, $connection_name);
            }
        }
18743
def load_db(file, db, verbose=True):
    
    db_data = json.load(file, verbose=verbose)
    return _load(db_data, db)
596040
def load(self, filename=None):
        '''
        
        '''
        fields = []
        with open(filename, 'r') as f:
            format_data = f.read().strip()

        lines = format_data.split('\n')
        self._sql_version = lines.pop(0)
        self._num_fields = int(lines.pop(0))

        for line in lines:
            # Get rid of mulitple spaces
            line = re.sub(' +', ' ', line.strip())
            row_format = BCPFormatRow(line.split(' '))
            fields.append(row_format)

        self.fields = fields
        self.filename = filename
845823
public function load()
	{
		if (!($this->get('db') instanceof \Hubzero\Database\Driver))
		{
			return;
		}

		// Initialise variables.
		$db = $this->get('db');

		$query = $db->getQuery()
			->select('m.id')
			->select('m.menutype')
			->select('m.title')
			->select('m.alias')
			->select('m.note')
			->select('m.path', 'route')
			->select('m.link')
			->select('m.type')
			->select('m.level')
			->select('m.language')
			->select('m.browserNav')
			->select('m.access')
			->select('m.params')
			->select('m.home')
			->select('m.img')
			->select('m.template_style_id')
			->select('m.component_id')
			->select('m.parent_id')
			->select('e.element', 'component')
			->from('#__menu', 'm')
			->join('#__extensions AS e', 'e.extension_id', 'm.component_id', 'left')
			->whereEquals('m.published', 1)
			->where('m.parent_id', '>', 0)
			->whereEquals('m.client_id', 0)
			->order('m.lft', 'asc');

		// Set the query
		$db->setQuery($query->toString());

		$this->_items = $db->loadObjectList('id');

		foreach ($this->_items as &$item)
		{
			// Get parent information.
			$parent_tree = array();
			if (isset($this->_items[$item->parent_id]))
			{
				$parent_tree  = $this->_items[$item->parent_id]->tree;
			}

			// Create tree.
			$parent_tree[] = $item->id;
			$item->tree = $parent_tree;

			// Create the query array.
			$url = str_replace('index.php?', '', $item->link);
			$url = str_replace('&amp;', '&', $url);

			parse_str($url, $item->query);
		}
	}
766763
def connect(self, **kwargs):
        ''' 
        '''
        if 'database' not in kwargs:
            kwargs['database'] = 'ait'

        self._conn = self._backend.connect(kwargs['database'])
806383
public function loadDatabase(string $file): void
	{
		Helpers::loadFromFile($this->context->getConnection(), $file);
	}
1110678
private function connect()
    {
        $this->conn = parent::getConn();
        $this->read = $this->conn->prepare($this->sql);
        $this->read->setFetchMode(\PDO::FETCH_ASSOC);
    }
200506
def _get_new_connection(self, conn_params):
    """"""
    self.__connection_string = conn_params.get('connection_string', '')
    conn = self.Database.connect(**conn_params)
    return conn