Connects to the database.
@param bool $failIfConnected  true=it throw an error if it's connected, otherwise it does nothing
@throws Exception
@test exception this(false)
331584
public function connect($failIfConnected=true)
	{
		mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
		if ($this->isOpen) {
			if (!$failIfConnected) return; // it's already connected.
			$this->throwError("Already connected","");
		}
		try {
			if ($this->logLevel>=2) {
				$this->storeInfo("connecting to {$this->server} {$this->user}/*** {$this->db}");
			}
			$this->conn1 = new \mysqli($this->server, $this->user, $this->pwd, $this->db);
			if ($this->charset!='') {
				$this->setCharset($this->charset);
			}
			$this->isOpen=true;
		} catch (Exception $ex) {
			$this->isOpen=false;
			$this->throwError("Failed to connect to MySQL", $ex->getMessage());
		}
		// Check connection
		if (mysqli_connect_errno()) {
			$this->isOpen=false;
			$this->throwError("Failed to connect to MySQL", mysqli_connect_error());
		}
	}
881710
private function connect()
        {
            $this->fd = fsockopen($this->serverHost, $this->serverPort, $errno, $errstr);

            if (!$this->fd) {
                throw new Exception('fsockopen returned: '.$errstr);
            }

            $key = $this->generateKey();

            $out  = "GET " . $this->serverPath . "/websocket/" . $this->session['sid'] . " HTTP/1.1\r\n";
            $out .= "Host: " . $this->serverHost . "\r\n";
            $out .= "Upgrade: WebSocket\r\n";
            $out .= "Connection: Upgrade\r\n";
            $out .= "Sec-WebSocket-Key: " . $key . "\r\n";
            $out .= "Sec-WebSocket-Version: 13\r\n";
            $out .= "Origin: *\r\n\r\n";

            fwrite($this->fd, $out);

            $res = fgets($this->fd);

            if ($res === false) {
                throw new Exception('Socket.io did not respond properly. Aborting...');
            }

            if ($subres = substr($res, 0, 12) != 'HTTP/1.1 101') {
                throw new Exception('Unexpected Response. Expected HTTP/1.1 101 got '.$subres.'. Aborting...');
            }

            while(true) {
                $res = trim(fgets($this->fd));
                if ($res === '') break;
            }

            if ($this->read) {
                if ($this->read() != '1::') {
                    throw new Exception('Socket.io did not send connect response. Aborting...');
                } else {
                    $this->stdout('info', 'Server report us as connected !');
                }
            }

            $this->heartbeatStamp = time();
        }
729330
public function connect() {

		if($this->db !== null) return $this->db;

		try {

			$this->db = new \PDO(
				$this->config['datasource'],
				$this->config['username'],
				$this->config['password']
			);

			$this->db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);

			return true;

		} catch(\PDOException $e) {
			throw new \HybridLogic\DB\Exception\ConnectionException($e);
		}

	}
663676
protected function connect()
        {
            if (!is_null($this->connection)) {
                return $this->connection;
            }
            // $this->connection = fsockopen($this->host, $this->port, $error, $message);
            $remote_socket = 'tcp://'.$this->host.':' . $this->port;
            $this->connection = @stream_socket_client($remote_socket, $errno, $error, 30);
            if ($this->connection === false) {
                throw new Exception("Error making Redis connection: {$error} - {$message}");
            }
            // $this->select($this->database);
            return $this->connection;
        }
207251
final public function connect()
    {
        /* If an established connection is available, then there's
         * no need to connect and select the database.
         *
         * Depending on the database driver, conn_id can be either
         * boolean TRUE, a resource or an object.
         */
        if ($this->handle) {
            return;
        }

        //--------------------------------------------------------------------

        $this->connectTimeStart = microtime(true);

        // Connect to the database and set the connection ID
        $this->platformConnectHandler($this->config);

        // No connection resource? Check if there is a failover else throw an error
        if ( ! $this->handle) {
            // Check if there is a failover set
            if ( ! empty($this->config[ 'failover' ]) && is_array($this->config[ 'failover' ])) {
                // Go over all the failovers
                foreach ($this->config[ 'failover' ] as $failover) {

                    // Try to connect
                    $this->platformConnectHandler($failover = new Config($failover));

                    // If a connection is made break the foreach loop
                    if ($this->handle) {
                        $this->config = $failover;
                        break;
                    }
                }
            }

            // We still don't have a connection?
            if ( ! $this->handle) {
                throw new RuntimeException('DB_E_UNABLE_TO_CONNECT', 0, [$this->platform]);
            }
        }

        $this->connectTimeDuration = microtime(true) - $this->connectTimeStart;
    }
330898
public function failConnect(FailedConnectionEvent $args)
    {
        $e = $args->getException();
        $this->logger->debug($e->getMessage(), ['event' => 'exception', 'exception' => $e]);

        throw new DatabaseConnectionException($args->getDriver()->getName(), $e->getMessage(), $e);
    }
1069789
public void connect() throws Exception {
        if (connection != null && !connection.isOpen()) {
            connection.open();
            transaction = connection.getModbusTransport().createTransaction();
            ((ModbusSerialTransaction) transaction).setTransDelayMS(transDelay);
            setTransaction(transaction);
        }
    }
1246503
private function connect()
    {
        if (!$this->isConnected) {
            parent::__construct(
                $this->dsn,
                $this->server->getUsername(),
                $this->server->getPassword(),
                $this->driverOptions
            );
            parent::setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            parent::setAttribute(
                PDO::ATTR_STATEMENT_CLASS,
                [__NAMESPACE__ . '\\' . self::PDO_STATEMENT_CLASS, [$this]]
            );

            $this->isConnected = true;
        }
    }
621669
public function connect()
	{
		if ($this->connection)
		{
			return;
		}

		// Build the connection configuration array.
		$config = array(
			'Database'             => $this->options['database'],
			'uid'                  => $this->options['user'],
			'pwd'                  => $this->options['password'],
			'CharacterSet'         => 'UTF-8',
			'ReturnDatesAsStrings' => true,
		);

		// Make sure the SQLSRV extension for PHP is installed and enabled.
		if (!static::isSupported())
		{
			throw new UnsupportedAdapterException('PHP extension sqlsrv_connect is not available.');
		}

		// Attempt to connect to the server.
		if (!($this->connection = @ sqlsrv_connect($this->options['host'], $config)))
		{
			$this->log(Log\LogLevel::ERROR, 'Could not connect to SQL Server', array('errors' => sqlsrv_errors()));

			throw new ConnectionFailureException('Could not connect to SQL Server');
		}

		// Make sure that DB warnings are not returned as errors.
		sqlsrv_configure('WarningsReturnAsErrors', 0);

		// If auto-select is enabled select the given database.
		if ($this->options['select'] && !empty($this->options['database']))
		{
			$this->select($this->options['database']);
		}
	}
404262
public function connect()
	{
		if ($this->getConnection())
		{
			return;
		}

		try
		{
			// Try to connect to MySQL
			parent::connect();
		}
		catch (ConnectionFailureException $e)
		{
			// If the connection failed, but not because of the wrong character set, then bubble up the exception.
			if (!$this->utf8mb4)
			{
				throw $e;
			}

			/*
			 * Otherwise, try connecting again without using utf8mb4 and see if maybe that was the problem. If the connection succeeds, then we
			 * will have learned that the client end of the connection does not support utf8mb4.
  			 */
			$this->utf8mb4            = false;
			$this->options['charset'] = 'utf8';

			parent::connect();
		}

		if ($this->utf8mb4)
		{
			// At this point we know the client supports utf8mb4.  Now we must check if the server supports utf8mb4 as well.
			$serverVersion = $this->connection->getAttribute(\PDO::ATTR_SERVER_VERSION);
			$this->utf8mb4 = version_compare($serverVersion, '5.5.3', '>=');

			if (!$this->utf8mb4)
			{
				// Reconnect with the utf8 character set.
				parent::disconnect();
				$this->options['charset'] = 'utf8';
				parent::connect();
			}
		}

		$this->connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
		$this->connection->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
	}
786385
public function connect()
    {
        if ($this->connection) {
            $this->countConnections++;
            return false;
        }
        $connection = $this->implementation->connect($this->params, $errorInfo, $errorCode);
        if (!$connection) {
            throw new Connect($errorInfo, $errorCode);
        }
        $this->connection = $connection;
        $this->countConnections = 1;
        return true;
    }
465802
private function _connect() 
    {

        if ($this->config['host'] && $this->config['port']) {
            // establish the memcache connection
            $this->memcache = new Memcache;
            $this->memcache->pconnect(
            	$this->config['host'], 
                $this->config['port']
            );

        } else {
            throw new Exception('Insufficient connection parameters');
        }
    }
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;
    }
790798
public function connect($nameDB = NULL, $configFile = NULL){
        if($configFile != NULL){
            $this->configFile= $configFile;
            self::$config_db= NULL;
        }
        $this->connection= $this->getConnection($nameDB);
    }
455483
private function checkMysqlConnection() {
        $this->connection = new \mysqli(
            $this->config->get('backup::config')['BACKUP_MYSQL_HOST'],
            $this->config->get('backup::config')['BACKUP_MYSQL_USER'],
            $this->config->get('backup::config')['BACKUP_MYSQL_PASSWORD']);

        if ($this->connection->connect_errno) {
            $this->event->fire('MonasheeBackupError', 'No database connection');

            throw new \Exception('Error connecting to MySQL');
        }

        echo 'Connected: '.$this->connection->host_info."\n";
        echo 'Server info: '.$this->connection->get_server_info()."\n";

        return true;
    }
405694
public function setFailQueryFailed(bool $fail_query_failed = true) : void
    {
        $this->query_succeeded = false;
        $this->fail_query_failed = $fail_query_failed;
    }
48173
protected function tryConnection($connectionInfo, OutputInterface $output)
    {
        if (\is_null($connectionInfo["dbName"])) {
            return false;
        }

        $dsn = "mysql:host=%s;port=%s";

        try {
            $connection = new \PDO(
                sprintf($dsn, $connectionInfo["host"], $connectionInfo["port"]),
                $connectionInfo["username"],
                $connectionInfo["password"]
            );
            $connection->query('SET NAMES \'UTF8\'');
        } catch (\PDOException $e) {
            $output->writeln(array(
                "<error>Wrong connection information</error>"
            ));

            return false;
        }

        return $connection;
    }