Returns the connection.

@return \Mongator\ConnectionInterface The connection.

@api
768745
public function getConnection()
    {
        if (!$this->connection) {
            if ($this->connectionName) {
                $this->connection = $this->mongator->getConnection($this->connectionName);
            } else {
                $this->connection = $this->mongator->getDefaultConnection();
            }
        }

        return $this->connection;
    }
593807
public function createConnection(): ConnectionInterface
    {
        $driver    = $this->poolConfig->getDriver();
        $collector = ConnectionCollector::getCollector();

        if (App::isCoContext()) {
            $connectClassName = $this->getCorConnectClassName($collector, $driver);
        } else {
            $connectClassName = $this->getSyncConnectClassName($collector, $driver);
        }

        return new $connectClassName($this);
    }
467722
function getConnector() {
    if (empty($this->connector)) $this->connector = new Connector($this->config);

    return $this->connector;
  }
442925
public function getConnection()
    {
        // if we already have a PDO object, no need to re-connect.
        if ($this->_connection) {
            return $this->_connection;
        }

        $this->_pdoType = "sqlsrv";
        // get the dsn first, because some adapters alter the $_pdoType
        //$dsn = $this->_dsn();

        // check for PDO extension
        if (!extension_loaded('pdo')) {
            /**
             * @see Zend_Db_Adapter_Exception
             */
            throw new \Zend_Db_Adapter_Exception('The PDO extension is required for this adapter but the extension is not loaded');
        }

        // check the PDO driver is available
        if (!in_array($this->_pdoType, PDO::getAvailableDrivers())) {
            /**
             * @see Zend_Db_Adapter_Exception
             */
            throw new \Zend_Db_Adapter_Exception('The ' . $this->_pdoType . ' driver is not currently installed');
        }

        // create PDO connection
        $q = $this->_profiler->queryStart('connect', Zend_Db_Profiler::CONNECT);

        // add the persistence flag if we find it in our config array
        if (isset($this->_config['persistent']) && ($this->_config['persistent'] == true)) {
            $this->_config['driver_options'][PDO::ATTR_PERSISTENT] = true;
        }

        try {
            $serverName = $this->_config["host"];
            $database   = $this->_config["dbname"];
            if (is_null($database)) {
                $database = 'master';
            }
            $uid = $this->_config['username'];
            $pwd = $this->_config['password'];
            if ($this->_config["port"] != "") {
                $serverName = $serverName . "," . $this->_config["port"];
            }

            $this->_connection = new PDO("sqlsrv:$serverName", $uid, $pwd, array('Database' => $database));

            if ($this->_connection === false) {
                die(self::FormatErrors(sqlsrv_errors()));
            }

            /*
            $this->_connection = new PDO(
                $dsn,
                $this->_config['username'],
                $this->_config['password'],
                $this->_config['driver_options']
            );
            */

            $this->_profiler->queryEnd($q);

            // set the PDO connection to perform case-folding on array keys, or not
            $this->_connection->setAttribute(PDO::ATTR_CASE, $this->_caseFolding);
            $this->_connection->setAttribute(PDO::SQLSRV_ENCODING_UTF8, true);

            // always use exceptions.
            $this->_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

            return $this->_connection;
        } catch (PDOException $e) {
            /**
             * @see Zend_Db_Adapter_Exception
             */
            throw new \Zend_Db_Adapter_Exception($e->getMessage(), $e->getCode(), $e);
        }
    }
1259879
public function getCollection()
    {
        if (!$this->collection) {
            // gridfs
            if ($this->isFile) {
                $this->collection = $this->getConnection()->getMongoDB()->getGridFS($this->collectionName);
            // normal
            } else {
                $this->collection = $this->getConnection()->getMongoDB()->selectCollection($this->collectionName);
            }
        }

        return $this->collection;
    }
184928
public function connect()
    {
        if ($this->connection) {
            return $this;
        }

        $dsn = PdoHelper::getDsn($this->options['driver'], $this->options);

        try {
            $this->connection = new \PDO(
                $dsn,
                $this->options['user'],
                $this->options['password'],
                $this->options['driverOptions']
            );
        } catch (\PDOException $e) {
            throw new \RuntimeException(
                'Could not connect to PDO: ' . $e->getMessage() . '. DSN: ' . $dsn,
                (int) $e->getCode(),
                $e
            );
        }

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

        return $this;
    }
287799
public function connection()
    {
        if (!is_object($this->db)) {
            $this->db = new \FaaPz\PDO\Database(
                $this->database['driver'] . ':host=' . $this->database['host'] . ';port=' . $this->database['port'] . ';dbname=' . $this->database['database'] . ';charset=' . $this->database['charset'] . ';collation=' . $this->database['collation'] . ';prefix=' . $this->database['prefix'],
                $this->database['username'],
                $this->database['password'],
                $this->database['options']
            );
            $this->db->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_OBJ);
        }

        return $this;
    }
1135695
public function chosen() : ?Connection
    {
        if ($this->helperSet->has($this->helperName)) {
            $connectionHelper = $this->helperSet->get($this->helperName);

            if ($connectionHelper instanceof ConnectionHelper) {
                return $connectionHelper->getConnection();
            }
        }

        return null;
    }
1191645
public function getConnection()
    {
        if ($chosenConn = $this->connections->pop()) {
            $this->connections->push($chosenConn);

            return $chosenConn;
        }
    }
482998
public function getConnection()
    {
        $connection = parent::getConnection();

        if ( ! app()->bound(Component::CORE)) {
            // @codeCoverageIgnoreStart
            return $connection;
            // @codeCoverageIgnoreEnd
        }

        /** @var CoreInterface $core */
        $core = app(Component::CORE);
        $cmsConnection = $core->config('database.driver');

        // If no separate database driver is configured for the CMS,
        // we can use the normal driver and rely on the prefix alone.
        if ( ! $cmsConnection) {
            return $connection;
        }

        // If we're running tests, make sure we use the correct override
        // for the CMS database connection/driver.
        // N.B. This is ignored on purpose if the default connection is not overridden normally.
        if (app()->runningUnitTests()) {
            $cmsConnection = $core->config('database.testing.driver') ?: $cmsConnection;
        }

        return $cmsConnection;
    }
239919
public function getConnection()
    {
        if(!$this->_connection) {
            $this->_connection = new \Guzzle\Http\Client($this->getHost());
        }

        return $this->_connection;
    }
1280786
protected function _connection() {
		if ($this->_connection) {
			return $this->_connection;
		}
		$host = "{$this->_config['protocol']}://{$this->_config['host']}";

		if ($this->_connection = fsockopen($host, $this->_config['port'], $message, $code)) {
			return $this->_connection;
		}
		throw new NetworkException("Growl connection failed: (`{$code}`) `{$message}`.");
	}
1072417
public function getConnection()
    {
        if ($this->conn === false) {
            $this->conn = null;
            if ($this->url) {
                $buf = "Using database settings:\n"
                    . " URL: " . $this->url . "\n"
                    . ($this->userId ? " user: " . $this->userId . "\n" : "")
                . ($this->password ? " password: " . $this->password . "\n" : "");

                $this->log($buf, Project::MSG_VERBOSE);

                // Set user + password to null if they are empty strings
                if (!$this->userId) {
                    $this->userId = null;
                }
                if (!$this->password) {
                    $this->password = null;
                }
                try {
                    $this->conn = new PDO($this->url, $this->userId, $this->password);
                    $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                } catch (PDOException $x) {
                    $this->log("Unable to create a PDO connection: " . $x->getMessage(), Project::MSG_WARN);
                }
            }
        }

        return $this->conn;
    }
304011
public static function getInstanceAndConnect() {
		if (!is_object(self::getInstance())) {
			return NULL;
		}
		if (!self::$instance->tryConnect()) {
			return NULL;
		}
		return self::$instance;
	}
1194917
protected function getConnection() {
        if (count($this->pool) > 0) {
            /**
             * @var $connection RedisConnection
             */
            foreach ($this->pool as $k => $connection) {
                unset($this->pool[$k]);
                break;
            }
            return $connection;
        } else {
            return new RedisConnection($this);
        }
    }
265283
protected function doConnect()
    {
        $host = $this->getParam('host');
        $port = $this->getParam('port');
        $timeout = $this->getParam('timeout');

        return $this->retry(function () use ($host, $port, $timeout) {
            $res = @ftp_connect($host, $port, $timeout);

            if (false === $res) {
                throw new \RuntimeException("Couldn't connect to: $host:$port");
            }

            return $res;
        });
    }
489422
public static function getConnection() {
        global $PDOX, $CFG;

        if ( isset($PDOX) && is_object($PDOX) && get_class($PDOX) == 'Tsugi\Util\PDOX' ) {
            return $PDOX;
        }

        if ( defined('PDO_WILL_CATCH') ) {
            $PDOX = new \Tsugi\Util\PDOX($CFG->pdo, $CFG->dbuser, $CFG->dbpass);
            $PDOX->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
        } else {
            try {
                $PDOX = new \Tsugi\Util\PDOX($CFG->pdo, $CFG->dbuser, $CFG->dbpass);
                $PDOX->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
            } catch(\PDOException $ex){
                error_log("DB connection: ".$ex->getMessage());
                die('Failure connecting to the database, see error log'); // with error_log
            }
        }
        if ( isset($CFG->slow_query) ) $PDOX->slow_query = $CFG->slow_query;
        return $PDOX;
    }