Returns the database connection.

@return \Illuminate\Database\Connection
@throws \InvalidArgumentException
509786
public function getConnection()
	{
		if ($this->connection === null)
		{
			$connection = null;

			// We will now provide the query grammar to the connection.
			switch ($this->driverName)
			{
				case 'mysql':
					$connection = '\Illuminate\Database\MySqlConnection';
					break;

				case 'pgsql':
					$connection = '\Illuminate\Database\PostgresConnection';
					break;

				case 'sqlsrv':
					$connection = '\Illuminate\Database\SqlServerConnection';
					break;

				case 'sqlite':
					$connection = '\Illuminate\Database\SQLiteConnection';
					break;

				default:
					throw new \InvalidArgumentException("Cannot determine grammar to use based on {$this->driverName}.");
					break;
			}
			
			$this->connection = new $connection($this->pdo, '', $this->tablePrefix);
		}

		return $this->connection;
	}
1351359
public function getRedis(): ?Connection
    {
        if (!$this->hasRedis()) {
            $this->setRedis($this->getDefaultRedis());
        }
        return $this->redis;
    }
351428
public function getConnection()
    {
        if (null === $this->conn) {
            $this->checkConfiguration();

            try {
                $this->conn = new SQL(
                    $this->buildDsn(),
                    $this->config['username'],
                    $this->config['password']
                );
            } catch (Exception $e) {
                throw new RuntimeException(static::E_CONNECT);
            }
        }

        return $this->conn;
    }
867002
public function getDefaultConnection()
    {
        $config = Config::getEnv('database.default');

        if (empty($config)) {
            throw new \InvalidArgumentException("'database'配置文件中的'default'配置项无效：该配置必须是非空数组");
        }

        $driver_str = isset($config->driver) ? $config->driver : null;
        $driver = strtolower($driver_str);
        unset($config->driver);

        $config = (array) $config;
        $config['options'] = [
            \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
            \PDO::ATTR_EMULATE_PREPARES => false,
            \PDO::ATTR_STRINGIFY_FETCHES => false,
            \PDO::ATTR_DEFAULT_FETCH_MODE => $this->getDefaultFetch(),
        ];

        return new ConnectionObj('db', $driver, $config);
    }
655383
public function getConnection()
    {
        if (null === $this->connection) {
            $this->setConnection(\Doctrine_Manager::getInstance()->getCurrentConnection());
        }

        return $this->connection;
    }
276607
public function getConnection()
    {
        $conn = mysqli_init();
        if ($this->encryption === true) {
            Logger::debug("Getting connection with encryption.");
            mysqli_ssl_set($conn, $this->sslKey, $this->sslCert, $this->sslCA, $this->sslCAPath, null);
            if ($this->port === null) {
                mysqli_real_connect($conn, $this->serverName, $this->username, $this->password, $this->databaseName);
            } else {
                mysqli_real_connect(
                    $conn,
                    $this->serverName,
                    $this->username,
                    $this->password,
                    $this->databaseName,
                    $this->port
                );
            }
        } elseif ($this->port === null) {
            mysqli_real_connect($conn, $this->serverName, $this->username, $this->password, $this->databaseName);
        } else {
            mysqli_real_connect(
                $conn,
                $this->serverName,
                $this->username,
                $this->password,
                $this->databaseName,
                $this->port
            );
        }
        return $conn;
    }
263097
public function getConnection()
    {
        if (null === $this->_conn && null !== $this->_tableName) {

            $this->_conn = \Doctrine::getConnectionByTableName($this->_tableName);
        }

        return $this->_conn;
    }
908217
public function connect(): DatabaseConnection
    {
        if (null !== $this->pdo) {
            return $this;
        }

        try {
            $pdoCreator = $this->getPdoCreator();
            $this->pdo  = $pdoCreator($this->configuration);
            $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $this->pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
            if ($this->configuration->hasInitialQuery()) {
                $this->pdo->query($this->configuration->getInitialQuery());
            }
        } catch (PDOException $pdoe) {
            throw new DatabaseException($pdoe->getMessage(), $pdoe);
        }

        return $this;
    }
439588
final public function db() {
        if (!$this->connector) {
            $this->connector = $this->getWorker()->getConnector();
        }
        return $this->connector;
    }
1280686
public function getConn()
    {
        if (!$this->config('connection.className')) {
            $this->error(__d('installer', 'Database engine cannot be empty.'));

            return false;
        }

        try {
            ConnectionManager::drop('installation');
            ConnectionManager::config('installation', $this->config('connection'));
            $conn = ConnectionManager::get('installation');
            $conn->connect();

            return $conn;
        } catch (\Exception $ex) {
            $this->error(__d('installer', 'Unable to connect to database, please check your information. Details: {0}', '<p>' . $ex->getMessage() . '</p>'));

            return false;
        }
    }
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;
    }
554781
public function getDefaultConnection()
    {
        if (!$this->defaultConnection && empty($this->connections)) {
            throw new InvalidConnectionException('There are no connections configured');
        }

        if (!$this->defaultConnection) {
            reset($this->connections);

            return current($this->connections);
        }

        return $this->getConnection($this->defaultConnection);
    }
866005
public static function getDatabase()
    {
        $attribute = 'database';

        if (!static::hasClassAttribute($attribute)) {
            $database = Database::getDefault();

            if (!$database) {
                $error = static::error('connection', 'database not found', 'required-for', 6);
                switch (static::getClassConfig('error-mode')) {
                    case 'silent': break;
                    case 'exception': throw new Exception($error);
                    default: trigger_error($error, E_USER_ERROR);
                }
            }

            static::setClassAttribute($attribute, $database);
        }

        return static::getClassAttribute($attribute);
    }
419618
public function getDb()
    {
        if (!$this->db) {
            $this->db = Bootstrap::getSingleton()->getDatabase();
        }
        return $this->db;
    }
937621
public function getConnection($name = null)
    {
        if (null === $name) {
            $name = $this->defaultConnection;
        }

        if (!isset($this->connections[$name])) {
            throw new \InvalidArgumentException(sprintf('AMQP Connection named "%s" does not exist.', $name));
        }

        return $this->connections[$name];
    }
1209373
public function chosen() : ?Connection
    {
        if ($this->filename === null) {
            return null;
        }

        if (! file_exists($this->filename)) {
            return null;
        }

        $params = include $this->filename;

        if (! is_array($params)) {
            throw InvalidConfiguration::invalidArrayConfiguration();
        }

        return DriverManager::getConnection($params);
    }
1251032
public function getConnection($name = ''): QueryBuilderInterface
	{
		// If the parameter is a string, use it as an array index
		if (is_scalar($name) && isset($this->connections[$name]))
		{
			return $this->connections[$name];
		}
		else if (empty($name) && ! empty($this->connections)) // Otherwise, return the last one
		{
			return end($this->connections);
		}

		// You should actually connect before trying to get a connection...
		throw new InvalidArgumentException('The specified connection does not exist');
	}