Establishes a connection to the database server

@return bool true on success
321352
public function connect()
    {
        if ($this->_connection) {
            return true;
        }
        $config = $this->_config;

        if ($config['timezone'] === 'UTC') {
            $config['timezone'] = '+0:00';
        }

        if (!empty($config['timezone'])) {
            $config['init'][] = sprintf("SET time_zone = '%s'", $config['timezone']);
        }
        if (!empty($config['encoding'])) {
            $config['init'][] = sprintf('SET NAMES %s', $config['encoding']);
        }

        $config['flags'] += [
            PDO::ATTR_PERSISTENT => $config['persistent'],
            PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        ];

        if (!empty($config['ssl_key']) && !empty($config['ssl_cert'])) {
            $config['flags'][PDO::MYSQL_ATTR_SSL_KEY] = $config['ssl_key'];
            $config['flags'][PDO::MYSQL_ATTR_SSL_CERT] = $config['ssl_cert'];
        }
        if (!empty($config['ssl_ca'])) {
            $config['flags'][PDO::MYSQL_ATTR_SSL_CA] = $config['ssl_ca'];
        }

        if (empty($config['unix_socket'])) {
            $dsn = "mysql:host={$config['host']};port={$config['port']};dbname={$config['database']};charset={$config['encoding']}";
        } else {
            $dsn = "mysql:unix_socket={$config['unix_socket']};dbname={$config['database']}";
        }

        $this->_connect($dsn, $config);

        if (!empty($config['init'])) {
            $connection = $this->getConnection();
            foreach ((array)$config['init'] as $command) {
                $connection->exec($command);
            }
        }

        return true;
    }
1151924
public function connect()
    {
        $this->connection = ftp_connect($this->host);
        if (ftp_login($this->connection, $this->username, $this->password)) {
            if (ftp_chdir($this->connection, $this->getChdir()) && ftp_pasv($this->connection, $this->passive)) {
                $this->connected = true;
                return true;
            }
        }
        return false;
    }
498346
public function connect() {
		try {
			$this->_connect ();
			return true;
		} catch ( \PDOException $e ) {
			throw new DBException ( $e->getMessage (), $e->getCode (), $e->getPrevious () );
		}
	}
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);
    }
470419
public function connect()
	{
		if ($this->host == '')
		{
			return false;
		}

		$this->resource = @ ldap_connect($this->host, $this->port);

		if ($this->resource)
		{
			if ($this->use_ldapV3)
			{
				if (!@ldap_set_option($this->resource, LDAP_OPT_PROTOCOL_VERSION, 3))
				{
					return false;
				}
			}

			if (!@ldap_set_option($this->resource, LDAP_OPT_REFERRALS, (int) $this->no_referrals))
			{
				return false;
			}

			if ($this->negotiate_tls)
			{
				if (!@ldap_start_tls($this->resource))
				{
					return false;
				}
			}

			return true;
		}
		else
		{
			return false;
		}
	}
313135
public function connect()
    {

        if ($this->_connection && $this->_connection->connect()) {
            return true;
        }
        /**
         * Add required variables
         * Clear the connection parameters for security
         */
        $config = $this->_config['connection'] + array(
                'hostnames'  => 'localhost:27017'
        );

        unset($this->_config['connection']);

        /* Add Username & Password to server string */
        if (isset($config['username']) && isset($config['password'])) {
            $config['hostnames'] = $config['username'] . ':' . $config['password'] . '@' . $config['hostnames'] . '/' . $config['database'];
        }

        /* Add required 'mongodb://' prefix */
        if (strpos($config['hostnames'], 'mongodb://') !== 0) {
            $config['hostnames'] = 'mongodb://' . $config['hostnames'];
        }

        if (!isset($config['options']) || !is_array($config['options'])) {
            $config['options'] = array();
        }

        /* Create connection object, attempt to connect */
        $config['options']['connect'] = false;

        $class = '\MongoClient';
        if (!class_exists($class)) {
            $class = '\Mongo';
        }

        $this->_connection = new $class($config['hostnames'], $config['options']);

        /* Try connect */
        try {
            $this->_connection->connect();
        } catch (\MongoConnectionException $e) {
            throw new \Exception('Unable to connect to MongoDB server at ' . $config['hostnames']);
        }

        if (!isset($config['database'])) {
            throw new \Exception('No database specified in MangoDB Config');
        }

        $this->_db = $this->_connection->selectDB($config['database']);

        if(!$this->_db instanceof \MongoDB) {
            throw new \Exception('Unable to connect to database :: $_db is ' . gettype($this->_db));
        }
        
        $this->_connected = true;

        return true;
    }
1312468
protected function establishConnection() {
		// Acquire database connection
		$this->db = new \PDO($this->dsn, $this->user, $this->password);
		$this->db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
		
		// Prepare the insert statement
		$insertSQL = str_replace('__TABLE__', $this->table, $this->insertSQL);
		$this->preparedInsert = $this->db->prepare($insertSQL);
	}
788002
public function connect()
    {
        try {
            // Make string containing database settings
            $database = 'sqlsrv:Server=' . $this->host . ';Database=' . $this->database;

            // Make connection.
            $conn = new \PDO($database, $this->username, $this->password);

            // Set attributes from parameters
            $conn->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, $this->fetch);
            $conn->setAttribute(\PDO::ATTR_ERRMODE, $this->error);

            return $conn;
        } catch (\PDOException $ex) {
            throw new \InvalidArgumentException('Error! Cannot connect to database ' . $ex->getMessage());
        }
    }
1101873
protected function _connect(): bool {

		if ($this->_oPDO) {
			return FALSE;
		}

		$sName = $this->_sName;
		$sDSN = $this->_aConfig['dsn'];
		$this->_sPrevPrepareQuery = NULL;
		$this->_oPrevPrepare = NULL;

		try {

			$this->_oPDO = new \PDO(
				$this->_aConfig['dsn'],
				$this->_aConfig['user'],
				$this->_aConfig['password'],
				$this->_aConfig['option']
			);

		} catch (\Throwable $e) {

			$sError = 'MySQL Connect fail, Database "' . $sName . '"' . "\n"
				. $e->getMessage() . "\n"
				. 'DSN ' . $sDSN;
			throw new TangoException($sError, 2);
		}
		return TRUE;
	}
1011185
public function connect() {
        $adapter = Zend_Db_Table::getDefaultAdapter();
        if (!$adapter) {
            Garp_Cli::errorOut('No database adapter found');
            return false;
        }
        $config = $adapter->getConfig();
        $params = array(
            '-u' . escapeshellarg($config['username']),
            '-p' . escapeshellarg($config['password']),
            '-h' . escapeshellarg($config['host']),
            ' ' . escapeshellarg($config['dbname'])
        );
        $cmd = 'mysql ' . implode(' ', $params);
        $process = proc_open($cmd, array(0 => STDIN, 1 => STDOUT, 2 => STDERR), $pipes);
        $proc_status = proc_get_status($process);
        $exit_code = proc_close($process);
        return ($proc_status["running"] ? $exit_code : $proc_status["exitcode"] ) == 0;
    }
1123523
public function connect(): bool {
        if (!$this->hasMinimumCredentials()) {
            throw new InvalidCredentialsException();
        }
        $host = $this->credentials["servername"];
        $db = $this->credentials["dbname"];
        $dsn = "mysql:host=$host;dbname=$db;charset=utf8";
        $this->pdo = new \PDO($dsn,
            $this->credentials["username"],
            $this->credentials["password"]
        );
        $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
        return $this->pdo !== null;
    }
15154
private function connect()
    {
        $server = $this->config['server'];
        if (isset($this->config['ssl']) && $this->config['ssl'] == true) {
            $server = 'ssl://' . $server;
        }

        stream_set_blocking(STDIN, 0);
        $this->socket = fsockopen($server, $this->config['port']);

        return (bool) $this->socket;
    }
830110
public function connect()
    {
        if ($this->ssl !== false) {
            $function = 'ftp_ssl_connect';
        } else {
            $function = 'ftp_connect';
        }

        $result = call_user_func_array($function, array($this->host, $this->port, $this->timeout));

        if (!$result) {
            return false;
        } else {
            $this->stream = $result;
            return true;
        }
    }
1110033
public static function connect() :void {

		// configure the database and get the dns
		$dsn = self::configureAndGetDSN();

		// try to connect
		self::$_handle = new \PDO(
			$dsn, 
			self::$_config['username'] ?: null, 
			self::$_config['password'] ?: null
		);

		// check if connection the connexion failed
		if(!self::$_handle) {
			// throw an exception if it failed
			Throw new Exception('Database::connect() : Failed to connect', 500);
		}

		// if a before statement has to be executed
		if(self::$_config['before']) {
			// execute the before statement
			self::$_handle->query(self::$_config['before']);
		}
	}
734709
public static function connect()
    {   
        self::getEnv();
        return new PDO(self::$driver.':host='.self::$host.';dbname='.self::$dbname, self::$user, self::$pass);
    }
1346749
private function connect()
    {
		$this->sessionLink = mysqli_connect($this->host_master,$this->user,$this->password,$this->name) or die("Error " . mysqli_error($this->sessionLink));

//        $this->pdo = new \PDO($dsn, $this->username, $this->password, $this->connectionOptions);
//        $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
//        $this->driver = $this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
    }
731385
public function connect() : bool
    {
        try {
            $connection_string = 'sqlsrv:SERVER=' . $this->configuration['server'] . ';DATABASE=' . $this->configuration['dbname'];
            if (isset($this->configuration['encrypt']) && true === $this->configuration['encrypt']) {
                $connection_string .= ';ENCRYPT=1';
            }
            $this->logger->debug('Connecting to database engine.');
            $this->dbconn = new PDO($connection_string, $this->configuration['username'],
                $this->configuration['password']);
            $this->dbconn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $this->logger->debug('Connected to database engine.');
            $this->is_connected = true;
        } catch (\Exception $e) {
            throw new DatabaseConnectionException('MSSQL Connection to <strong>' . $this->configuration['server'] . '</strong> failed!<br>' . $e->getMessage());
        }
        return true;
    }