Connects to database
165894
public function connectToDB(){
        //if querybuilder is already connected there is no nedd to connect again
        if($this->queryBuilder->isConnected()) {
            return;
        }
        //check for database parameters
        if(empty($this->DBParameters)) {
            throw new \Exception('missing database parameters');
        }
        $this->queryBuilder->connect(
            $this->DBParameters['driver'],
            $this->DBParameters['host'],
            $this->DBParameters['database'],
            $this->DBParameters['username'],
            $this->DBParameters['password'],
            $this->DBParameters['charset'],
            $this->DBParameters['collation'],
            $this->DBParameters['options']
        );
    }
34467
private function connect()
    {
        $username = $this->config->get('username');
        $password = $this->config->get('password');
        $host = $this->config->get('hostname');
        $database = $this->config->get('database');
        $schema = $this->config->get('schema');
        $this->dsn = $this->config->get('dsn');
        if (!$this->config->has('type', Type::STRING))
            throw new ConfigurationException("Please specify the database type in the configuration section [sql]");

        $type = $this->config->getString('type');

        // Set up the driver
        $this->driver = $this->setupDriver($type);
        $this->driver->setTablePrefix($this->config->dget('prefix', ''));
            
        if (!$this->dsn)
        {
            $this->dsn = $this->driver->generateDSN($this->config->toArray());
            self::$logger->debug("Generated DSN: {0}", [$this->dsn]);
            $this->config->set('dsn', $this->dsn);
        }
            
        // Create the PDO and connect it to the database, setting default options
        //$pdo = new PDO($this->dsn, $username, $password);
        $pdo = DI::getInjector()
            ->newInstance(
                PDO::class,
                ['dsn' => $this->dsn, 'username' => $username, 'passwd' => $password]
            )
        ;
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
            
        $this->pdo = $pdo;
    }
371302
protected function connect()
    {
        if ($this->databaseHandle !== null) {
            return;
        }
        try {
            $splitdsn = explode(':', $this->dataSourceName, 2);
            $this->pdoDriver = $splitdsn[0];

            if ($this->pdoDriver === 'sqlite' && !file_exists($splitdsn[1])) {
                if (!file_exists(dirname($splitdsn[1]))) {
                    Files::createDirectoryRecursively(dirname($splitdsn[1]));
                }
                $this->databaseHandle = new \PDO($this->dataSourceName, $this->username, $this->password);
                $this->createCacheTables();
            } else {
                $this->databaseHandle = new \PDO($this->dataSourceName, $this->username, $this->password);
            }
            $this->databaseHandle->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);

            if ($this->pdoDriver === 'mysql') {
                $this->databaseHandle->exec('SET SESSION sql_mode=\'ANSI\';');
            }
        } catch (\PDOException $exception) {
            throw new Exception('Could not connect to cache table with DSN "' . $this->dataSourceName . '". PDO error: ' . $exception->getMessage(), 1334736164);
        }
    }
834068
def connect(self, *, db=None):
        
        if db:
            self.poll(command="stop")
            self.properties.db_name = db.split(".")[0]
            self.new_state(DeviceFromDB)
        else:
            self._log.warning(
                "Already connected, provide db arg if you want to connect to db"
            )
150770
public static function connectDb() {
        if 
            (!isset(self::$dbLink)) {
            $dbParams = self::getDatabaseParameters();
            self::validateDbParameters($dbParams);
            $dbParamsSan = self::sanitizeDbParameters($dbParams);
            $config = new Configuration();
            self::$dbLink = DriverManager::getConnection($dbParamsSan, $config);
        }
        
        return self::$dbLink;
    }
384256
public function connect(): bool
    {
        try {
            $this->checkConnect();
            $this->log('Connect to ' . $this->connect['host']);
            $this->handler = new \PDO(
                $this->connect['type'] . ':host=' . $this->connect['host'] . ';dbname=' . $this->connect['name'],
                $this->connect['user'],
                $this->connect['pass'],
                $this->connect['options']
            );

            foreach ($this->attributes as $attribute => $value) {
                $this->handler->setAttribute($attribute, $value);
            }

            $this->ok();
        } catch (\Exception $e) {
            throw new DbException("Attempt connection to database is failed: {$e->getMessage()}");
        }
        return true;
    }
1103475
def __connect(self):
        
        self.__methods     = _get_methods_by_uri(self.sqluri)
        uri_connect_method = self.__methods[METHOD_CONNECT]

        self.__dbapi2_conn = uri_connect_method(self.sqluri)
1345062
def _MakeConnection(self, database=""):
    """"""
    first_attempt_time = time.time()
    wait_time = config.CONFIG["Mysql.max_connect_wait"]
    while wait_time == 0 or time.time() - first_attempt_time < wait_time:
      try:
        connection_args = dict(
            user=config.CONFIG["Mysql.database_username"],
            db=database,
            charset="utf8",
            passwd=config.CONFIG["Mysql.database_password"],
            autocommit=True,
            cursorclass=cursors.DictCursor,
            host=config.CONFIG["Mysql.host"],
            port=config.CONFIG["Mysql.port"])

        key_path = config.CONFIG["Mysql.client_key_path"]
        if key_path:
          cert_path = config.CONFIG["Mysql.client_cert_path"]
          ca_cert_path = config.CONFIG["Mysql.ca_cert_path"]
          logging.debug("Client key file configured, trying to use SSL.")

          connection_args["ssl"] = {
              "key": key_path,
              "cert": cert_path,
              "ca": ca_cert_path,
          }

        return MySQLdb.connect(**connection_args)

      except MySQLdb.OperationalError as e:
        # This is a fatal error, we just raise the top level exception here.
        if "Access denied" in str(e):
          raise Error(str(e))

        if "Can't connect" in str(e):
          logging.warning("Datastore connection retrying after failed with %s.",
                          str(e))
          time.sleep(.5)
          continue
        raise

    raise IOError("Unable to connect to Mysql database.")
698573
public function connect()
    {
        $dsn = "sqlite:{$this->_file}";
        try {
            $class = $this->_handlerClass;
            $this->_handler = new $class($dsn);
            $this->_handler->setAttribute(
                PDO::ATTR_ERRMODE,
                PDO::ERRMODE_EXCEPTION
            );
            $this->_connected = true;
        } catch (\Exception $exp) {
            throw new ServiceException(
                "An error occurred when trying to connect to database " .
                "service. Error: {$exp->getMessage()}"
            );
        }
        return $this;
    }
771749
public function connect() {
        $dbConfig = $this->getDbConfig();
        $this->setDbConfig($dbConfig);
        $this->setORM($dbConfig);
        HookManager::call('dbConnect', self::$dbConnections, self::$ormPath);
    }
455779
private function connect()
    {
        try {
            $this->db = new \PDO(
                $this->dbOptions['dsn'],
                $this->dbOptions['username'],
                $this->dbOptions['password'],
                $this->dbOptions['driver_options']
            );

        } catch (\Exception $e) {
            //Change to true to debug database connection
            if ($this->dbOptions['debug']) {
                // For debug purpose, shows all connection details
                throw $e;
            } else {
                // Hide connection details.
                throw new \PDOException("Could not connect to database, hiding connection details.");
            }
        }
        $this->db->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_OBJ);
    }
404396
protected function connect() {
        $db = Config::config()['user']['database'];

        if ($db['enabled']) {
            switch ($db['driver']) {
                case 'pdo' :
                    $options = [Pdo::ATTR_STATEMENT_CLASS => ['\Gcs\Framework\Core\Pdo\PdoStatement', []]];

                    switch ($db['type']) {
                        case 'mysql':
                            try {
                                $this->db = new Pdo('mysql:host=' . $db['hostname'] . ';dbname=' . $db['database'], $db['username'], $db['password'], $options);
                                //self::$sql->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                                $this->db->exec('SET NAMES ' . strtoupper($db['charset']));
                            }
                            catch (\PDOException $e) {
                                throw new MissingDatabaseException($e->getMessage() . ' / ' . $e->getCode() . ' / ' . $e->getFile());
                            }
                            break;

                        case 'pgsql':
                            try {
                                $this->db = new Pdo('mysql:host=' . $db['hostname'] . ';dbname=' . $db['database'], $db['username'], $db['password'], $options);
                                //self::$sql->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                                $this->db->exec('SET NAMES ' . strtoupper($db['charset']));
                            }
                            catch (\PDOException $e) {
                                throw new MissingDatabaseException($e->getMessage() . ' / ' . $e->getCode());
                            }
                            break;

                        default :
                            throw new MissingDatabaseException("Can't connect to SQL Database because the driver is not supported");
                            break;
                    }
                    break;

                default :
                    throw new MissingDatabaseException("Can't connect to SQL Database because the API is unrecognized");
                    break;
            }

            return $this->db;
        }
        else {
            return null;
        }
    }
766763
def connect(self, **kwargs):
        ''' 
        '''
        if 'database' not in kwargs:
            kwargs['database'] = 'ait'

        self._conn = self._backend.connect(kwargs['database'])
884353
def connect(self):
        """"""
        self._client = self._create_client()
        self._db = getattr(self._client, self._db_name)
        self._generic_dao = GenericDAO(self._client, self._db_name)
797371
def connect(
    database: Union[str, Path], *, loop: asyncio.AbstractEventLoop = None, **kwargs: Any
) -> Connection:
    """"""
    if loop is None:
        loop = asyncio.get_event_loop()

    def connector() -> sqlite3.Connection:
        if isinstance(database, str):
            loc = database
        elif isinstance(database, bytes):
            loc = database.decode("utf-8")
        else:
            loc = str(database)

        return sqlite3.connect(loc, **kwargs)

    return Connection(connector, loop)
810609
def connect(self,
                engine: str = None,
                interface: str = None,
                host: str = None,
                port: int = None,
                database: str = None,
                driver: str = None,
                dsn: str = None,
                odbc_connection_string: str = None,
                user: str = None,
                password: str = None,
                autocommit: bool = True,
                charset: str = "utf8",
                use_unicode: bool = True) -> bool:
        

        # Catch all exceptions, so the error-catcher never shows a password.
        # Note also that higher-level things may catch exceptions, so use the
        # logger as well.
        try:
            return self._connect(
                engine=engine, interface=interface,
                host=host, port=port, database=database,
                driver=driver, dsn=dsn,
                odbc_connection_string=odbc_connection_string,
                user=user, password=password,
                autocommit=autocommit, charset=charset,
                use_unicode=use_unicode)
        except Exception as e:
            self.reraise_connection_exception(e)
544817
public function connect()
    {
        $dsnString = "{$this->dbDriver}:host={$this->dbHostname};dbname={$this->dbName};";
        $dsnString .= "charset={$this->dbCharset}";
        /*
         * Try to connect to database
         */
        try {
            $this->dbConnection = new \PDO(
                $dsnString,
                "{$this->dbUsername}",
                "{$this->dbPassword}",
                $this->driverOptions
            );
        } catch (\PDOException $ex) {
            // Error during database connection, check params.
            throw new \InvalidArgumentException(
                __METHOD__.': '.$ex->getMessage()
            );
        }

        return $this->dbConnection;
    }