Return PDO connection object. If connection lost will try again to connect.

@return PDO
494687
public function create()
    {
        $pdo = null;
        try {
            $pdo = $this->connect();
        } catch (\Exception $e) {
            $pdo = null;
            if ($this->isLostConnection($e)) {
                $pdo = $this->reconnect();
            }

            throw new \LogicException('Connection lost and no reconnector available.');
        }

        return $pdo;
    }
577428
protected function getPDO()
    {
        if (null === $this->pdo) {
            $this->pdo = new \PDO($this->dsn, $this->user, $this->password, $this->options);
        }
        return $this->pdo;
    }
74870
public static function db()
    {
        self::$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        return self::$conn;
    }
1139220
public function getConnection() : \PDO
    {
        if (!$this->connection) {
            if (!$this->connection = new \PDO($this->dsn, $this->login, $this->password, $this->options)) {
                throw new PDOConnectionException();
            }

            $this->connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
            $this->connection->setAttribute(\PDO::ATTR_ORACLE_NULLS, \PDO::NULL_NATURAL);
            $this->connection->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC);

            $this->userId && $this->connection->prepare("SELECT set_config('user.id', :user_id, false)")
                ->execute(['user_id' => $this->userId]);
            $this->timeZone && $this->connection->prepare("SELECT set_config('timezone', :timezone, false)")
                ->execute(['timezone' => $this->timeZone]);
            $this->locale && $this->connection->prepare("SELECT set_config('lc_messages', :locale, false)")
                ->execute(['locale' => $this->locale]);
            $this->isTransactional && $this->beginTransaction();
        }

        return $this->connection;
    }
1328237
protected static function newConnection()
    {
        static $newDb;

        if ($newDb === null) {
            $db = static::getDb();
            $className = get_class($db);
            $newDb = new $className;

            $class = new \ReflectionClass($db);
            foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
                if (!$property->isStatic()) {
                    $name = $property->getName();
                    $newDb->$name = $db->$name;
                }
            }

            $newDb->pdo = null;
        }

        return $newDb;
    }
902577
public function getConnection()
    {
        if (!$this->connection) {
            $this->connFac->setConfig($this->config);
            try {
                $this->connection = $this->connFac->create();
            } catch (PDOException $e) {
                throw new ClientException(
                    'Failed to create a MySQL connection.',
                    null,
                    $e
                );
            }
        }
        return $this->connection;
    }
1109675
public function getPdo()
    {
        if ($this->pdo === null) {
            $this->pdo = $this->doConnect();
        }
        return $this->pdo;
    }
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);
    }
462978
public function getDBO()
	{
		$db = \App::get('db');

		// Test the connection
		if (!$db->connected())
		{
			$this->log('PDO connection failed', 'error');
			return false;
		}

		// Check for the existance of the migrations table
		$tables = $db->getTableList();
		$prefix = $db->getPrefix();
		$tableset = false;

		if (in_array('migrations', $tables))
		{
			$this->setTableName('migrations');
			$tableset = true;
		}

		if (in_array($prefix . 'migrations', $tables))
		{
			if ($tableset)
			{
				$this->log('Tables `migrations` and `' . $prefix . 'migrations` both exist', 'error');
				return false;
			}

			$this->setTableName('#__migrations');
			$tableset = true;
		}

		if (!$tableset)
		{
			if ($this->createMigrationsTable($db) === false)
			{
				return false;
			}
		}

		// Add a callback so that a migration can update $this in real time if necessary
		$this->registerCallback('migration', $this);

		return $db;
	}
1185757
public function getDoctrineConnection()
    {
        if (is_null($this->doctrineConnection)) {
            $data                     = ['pdo' => $this->getPdo(), 'user' => $this->getConfig('username')];
            $this->doctrineConnection = new DoctrineConnection(
                $data,
                $this->getDoctrineDriver()
            );
        }

        return $this->doctrineConnection;
    }
1057821
public function get()
    {
        $anonymous = !$this->connection->isBound();

        try {
            $rootDse = self::doLdapQuery($anonymous);
        } catch (\Exception $e) {
            throw new LdapConnectionException(sprintf(
                'Unable to query the RootDSE. %s',
                $e->getMessage()
            ), $e->getCode());
        } finally {
            // Make sure to set things back to how they were...
            if ($anonymous && $this->connection->isBound()) {
                $this->connection->close();
            }
        }

        return $rootDse;
    }
874086
public function getConnection() {
        if (is_null($this->conn) || !($this->conn)) {
            $dsn = 'dblib:host=' . $this->host . ':1433;dbname=' . $this->db . ';charset=utf8';
            $this->conn = new \PDO($dsn, $this->user, $this->pass);

            if (is_bool($this->conn)) {
                throw new \Exception('unable to connect to db with provided credentials');
            }
        }

        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;
    }
1105061
public function getDoctrineConnection()
    {
        $driver = $this->getDoctrineDriver();

        $data = array('pdo' => $this->pdo, 'dbname' => $this->getConfig('database'));

        return new DoctrineConnection($data, $driver);
    }
1323180
public function connection()
    {
        if (!is_object($this->db)) {
            $this->db = new DB;
            $this->db->addConnection($this->database);
            $this->db->setEventDispatcher(new Dispatcher(new Container));
            $this->db->setAsGlobal();
            $this->db->bootEloquent();
        }

        return $this;
    }
830643
protected function connect(): PDO
	{
		// Connect to the database

		try
		{
			$pdo = new PDO($this->dsn, $this->username, $this->password, $this->getConnectionOptions());
		}
		catch(PDOException $e)
		{
			throw new RuntimeException(vsprintf('Failed to connect to the [ %s ] database. %s', [$this->name, $e->getMessage()]));
		}

		// Run queries

		foreach($this->onConnectQueries as $query)
		{
			$pdo->exec($query);
		}

		// Return PDO instance

		return $pdo;
	}
662297
private function connect()
    {
        if (is_null($this->connection)) {
            $this->connection = call_user_func($this->connectionFactory, $this->config);
        }

        return $this;
    }