*********************************\
Returns the connection if it exists
Otherwise it creates it before returning it
@return PDO $pdo => The connection to the database
357831
public static function getConnection()
    {
        // DataBase constants
        require_once dirname(dirname(dirname(dirname(__DIR__)))).'/config/bdd.php';

        // Checks if Pdo connection doesn't exist
        if (is_null(self::$pdo)) {

            // Creates the first parameters for the new pdo concerning the database
            $dsn = 'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME;

            // Sets & stores the pdo options as the last parameters for the new pdo
            $options = [
                PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
                PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
            ];
            // Creates & stores the pdo connection
            $pdo = new PDO($dsn, DB_USER, DB_PASS, $options);

            // Sets the encoding characters
            $pdo->exec('SET NAMES UTF8');

            // Stores the pdo connection
            self::$pdo = $pdo;

            // Returns the connection
            return $pdo;
        } else {

            // Return the pdo connection
            return self::$pdo;
        }
    }
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;
    }
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;
    }
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;
	}
1013525
public function Connection() {
      $this->_IsPersistent = GetValue(PDO::ATTR_PERSISTENT, $this->ConnectionOptions, FALSE);
      if(!is_object($this->_Connection)) {
         try {
            $this->_Connection = new PDO(strtolower($this->Engine) . ':' . $this->Dsn, $this->User, $this->Password, $this->ConnectionOptions);
            $this->_Connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
            
            if($this->ConnectionOptions[1002])
               $this->Query($this->ConnectionOptions[1002]);
            
            // We only throw exceptions during connect
            $this->_Connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
         } catch (Exception $ex) {
            $Timeout = FALSE;
            if ($ex->getCode() == '2002' && preg_match('/Operation timed out/i', $ex->getMessage()))
               $Timeout = TRUE;
            if ($ex->getCode() == '2003' && preg_match("/Can't connect to MySQL/i", $ex->getMessage()))
               $Timeout = TRUE;
                    
            if ($Timeout)
               throw new Exception(ErrorMessage('Timeout while connecting to the database', $this->ClassName, 'Connection', $ex->getMessage()), 504);
            
            trigger_error(ErrorMessage('An error occurred while attempting to connect to the database', $this->ClassName, 'Connection', $ex->getMessage()), E_USER_ERROR);
         }
      }
      
      return $this->_Connection;
   }
704519
protected function dbConnect() {
		try {
			$pdo = new PDO('mysql:host=' . conf::$db['host'] . ';dbname=' . conf::$db['name'], conf::$db['user'], conf::$db['pass']);
    		$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
			return $pdo;
		} catch(PDOException $e) {
			return false;
		}
	}
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;
    }
1317777
public function get()
    {
        $row = $this->pdoStatement->fetch(\PDO::FETCH_NUM);
        return $row ? $this->map($row) : $row;
    }
928781
public function getDbalConnection()
    {
        $dbalDriver = '';
        $driverCode = $this->getDriver()->getCode();

        if ($driverCode === 'MySQL') $dbalDriver = 'pdo_mysql';
        if ($dbalDriver == '') return null;

        $config = new Configuration();
        $loggerChain = new LoggerChain();

        if (\Arvici\Heart\Config\Configuration::get('app.env') == 'development') {
            $loggerChain->addLogger(new DoctrineLogBridge(\Logger::getInstance()->getMonologInstance()));
            $loggerChain->addLogger(DebugBarHelper::getInstance()->getDebugStack());
        }
        $config->setSQLLogger($loggerChain);

        return DriverManager::getConnection([
            'driver' => $dbalDriver,
            'pdo' => $this
        ], $config);
    }
244046
private function connect()
    {
        if ($this->isConnected()) {
            return $this;
        }

        $connectionString = sprintf(
            'host=%s port=%d dbname=%s user=%s password=%s sslmode=%s',
            $this->host,
            $this->port,
            $this->dbName,
            $this->username,
            $this->password,
            $this->sslMode ? 'require' : 'disable'
        );

        $this->pgConn = pg_connect($connectionString);
        if ($this->pgConn === false) {
            throw $this->createException('Can`t connect');
        }

        $this->pendingConnection = false;

        return $this;
    }
793228
public function getConnection()
    {
        if( null === $this->connection && null !== $this->connectionFactory ) {
            $this->connection = $this->connectionFactory->createMysqli();
        }
        return $this->connection;
    }
364007
public function getConnection()
    {
        if ($this->connection instanceof ConnectionInterface === FALSE)
        {
            $this->connection = Propel::getConnection();
        }

        return $this->connection;
    }
803207
public function getConnection()
	{
		if ($this->connection) return $this->connection;

		return $this->connection = new Net_SFTP($this->host, $this->port);
	}
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;
    }
1105061
public function getDoctrineConnection()
    {
        $driver = $this->getDoctrineDriver();

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

        return new DoctrineConnection($data, $driver);
    }
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;
    }
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;
    }