Connection creation

@param \PDO $pdo
490158
protected function createConnection($pdo)
    {
        $params = [
            'user' => $this->config['username'],
            'password' => $this->config['password'],
            'pdo' => $pdo,
            'driverClass' => DoctrineDriver::class,
        ];
        $this->doctrineConnection = \Doctrine\DBAL\DriverManager::getConnection($params);
    }
125748
public static function setupPDO($connectionString, $user, $password)
    {
        try {
            self::$pdoInstance = new PDO($connectionString, $user, $password);
        } catch (PDOException $e) {
            trigger_error($e->getMessage(), E_USER_ERROR);
        }
    }
1346749
private function connect()
    {
		$this->sessionLink = mysqli_connect($this->host_master,$this->user,$this->password,$this->name) or die("Error " . mysqli_error($this->sessionLink));

//        $this->pdo = new \PDO($dsn, $this->username, $this->password, $this->connectionOptions);
//        $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
//        $this->driver = $this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
    }
980696
protected function connect()
    {
        // Build a database connection if we don't have one connected

        $adapter = '\\Pixie\\ConnectionAdapters\\' . ucfirst(strtolower($this->adapter));

        $adapterInstance = $this->container->build($adapter, array($this->container));

        $pdo = $adapterInstance->connect($this->adapterConfig);
        $this->setPdoInstance($pdo);

        // Preserve the first database connection with a static property
        if (!static::$storedConnection) {
            static::$storedConnection = $this;
        }
    }
1058512
protected function createPdoConnection($dsn, $username, $password, $options)
    {
        if (class_exists(PDOConnection::class) && ! $this->isPersistentConnection($options)) {
            return new PDOConnection($dsn, $username, $password, $options);
        }

        return new PDO($dsn, $username, $password, $options);
    }
1083652
protected function initOptions(PDO $pdo)
    {
        // set time zone
        if (isset($this->config['timezone']))
        {
            $pdo->prepare('set time_zone="' . $this->config['timezone'] . '"')->execute();
        }

        //set charset
        if (isset($this->config['charset']))
        {
            $pdo->prepare('set names "' . $this->config['charset'] . '"')->execute();
        }

        // set strict mode
        if (isset($this->config['strict']) && $this->config['strict'])
        {
            $pdo->prepare("set session sql_mode='STRICT_ALL_TABLES'")->execute();
        }

        return $pdo;
    }
1124337
private function connect()
    {
        $port = isset($this->_args['port']) && $this->_args['port'] ? $this->_args['port'] : 3306;
        $dsn = "mysql:host={$this->_args['host']};port={$port};dbname={$this->_args['dbname']}";
        $username = $this->_args['username'];
        $password = $this->_args['password'];

        // TODO: Move to use the follow: PDO::ATTR_EMULATE_PREPARES to 'false'
        // For security reason
        $options = [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'];

        /*\
         * The latter can be fixed by turning off emulation
         * and using the DSN charset attribute instead of SET NAMES.
         * The former is tricky, because you have no concept for safely
         * dealing with identifiers (they're just dumped straight into the query).
         * One possible approach would be to wrap all identifiers in backticks
         * while escaping all backticks within the identifiers (through doubling).
         * Whether this actually works in all cases is an open question, though.
        \*/

        try {
            $this->_pdo = new PDO($dsn, $username, $password, $options);
        } catch (PDOException $ex) {
            $this->_database->error('connect', $ex);
        }

        $this->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    }
1090818
public static function loadPDO(PDO $connection)
    {
        $reflection = new ReflectionClass(static::class);
        $instance = $reflection->newInstanceWithoutConstructor();
        return $instance->connect($connection);
    }
1072807
protected function createPdoConnection($dsn, $username, $password, $options)
    {
        return new PDO($dsn, $username, $password, $options);
    }
647706
protected function conn_create($dsn)
    {
        // Get database specific connection options
        $dsn_string  = $this->dsn_string($dsn);
        $dsn_options = $this->dsn_options($dsn);

        // Connect
        try {
            // with this check we skip fatal error on PDO object creation
            if (!class_exists('PDO', false)) {
                throw new Exception('PDO extension not loaded. See http://php.net/manual/en/intro.pdo.php');
            }

            $this->conn_prepare($dsn);

            $dbh = new PDO($dsn_string, $dsn['username'], $dsn['password'], $dsn_options);

            // don't throw exceptions or warnings
            $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);

            $this->conn_configure($dsn, $dbh);
        }
        catch (Exception $e) {
            $this->db_error     = true;
            $this->db_error_msg = $e->getMessage();

            rcube::raise_error(array('code' => 500, 'type' => 'db',
                'line' => __LINE__, 'file' => __FILE__,
                'message' => $this->db_error_msg), true, false);

            return null;
        }

        return $dbh;
    }
905067
private function databaseConnect()
    {
        $dsn = 'mysql:host='.$this->db['host'].';port='.$this->db['port'].';dbname='.$this->db['name'];

        $options = array(
            \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
            \PDO::ATTR_PERSISTENT         => true,
            \PDO::ATTR_ERRMODE            => \PDO::ERRMODE_EXCEPTION
        );

        // Create a new PDO instance
        try
        {
            $this->dbh = new \PDO($dsn, $this->db['user'], $this->db['password'], $options);
        }
        // Catch any errors
        catch (\PDOException $e)
        {
            exit($e->getMessage());
        }
    }
404396
protected function connect() {
        $db = Config::config()['user']['database'];

        if ($db['enabled']) {
            switch ($db['driver']) {
                case 'pdo' :
                    $options = [Pdo::ATTR_STATEMENT_CLASS => ['\Gcs\Framework\Core\Pdo\PdoStatement', []]];

                    switch ($db['type']) {
                        case 'mysql':
                            try {
                                $this->db = new Pdo('mysql:host=' . $db['hostname'] . ';dbname=' . $db['database'], $db['username'], $db['password'], $options);
                                //self::$sql->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                                $this->db->exec('SET NAMES ' . strtoupper($db['charset']));
                            }
                            catch (\PDOException $e) {
                                throw new MissingDatabaseException($e->getMessage() . ' / ' . $e->getCode() . ' / ' . $e->getFile());
                            }
                            break;

                        case 'pgsql':
                            try {
                                $this->db = new Pdo('mysql:host=' . $db['hostname'] . ';dbname=' . $db['database'], $db['username'], $db['password'], $options);
                                //self::$sql->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                                $this->db->exec('SET NAMES ' . strtoupper($db['charset']));
                            }
                            catch (\PDOException $e) {
                                throw new MissingDatabaseException($e->getMessage() . ' / ' . $e->getCode());
                            }
                            break;

                        default :
                            throw new MissingDatabaseException("Can't connect to SQL Database because the driver is not supported");
                            break;
                    }
                    break;

                default :
                    throw new MissingDatabaseException("Can't connect to SQL Database because the API is unrecognized");
                    break;
            }

            return $this->db;
        }
        else {
            return null;
        }
    }
929369
public static function initPDO(PDO $pdo): PDO
    {
        if (self::$debugbar instanceof StandardDebugBar) {
            $traceable_pdo = new TraceablePDO($pdo);
            self::$debugbar->addCollector(new PDOCollector($traceable_pdo));
        }

        return $pdo;
    }
1048822
public function connect()
    {
        try {
            $this->_connection = new PDO(
                $this->_type .":host=". $this->_host .";dbname=". $this->_database .";port=". $this->_port,
                $this->_username,
                $this->_password
            );
        } catch(PDOException $e) {
            $code    = $e->getCode();
            $message = $e->getMessage();

            throw new ConnectionFailed($code, $message);
        }
    }
1341127
protected function setModes(PDO $connection, array $config)
    {
        if (isset($config['modes'])) {
            $this->setCustomModes($connection, $config);
        } elseif (isset($config['strict'])) {
            if ($config['strict']) {
                $connection->exec($this->strictMode());
            } else {
                $connection->exec("set session sql_mode='NO_ENGINE_SUBSTITUTION'");
            }
        }
    }
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;
   }
202620
function givePdo(\PDO $conn)
    {
        if ($this->pdo)
            throw new exImmutable;


        $this->pdo = $conn;
        return $this;
    }