public function connect($pHost, $pDb, $pUser = NULL, $pPass = NULL)
    {
        try {
            if ($pUser !== NULL and $pPass !== NULL and is_string($pUser) and is_string($pPass)) {
                $connection = new PDO("mysql:host=$pHost;dbname=$pDb", $pUser, $pPass);
            } else {
                $connection = new PDO("mysql:host=$pHost;dbname=$pDb");
            }
        } catch(PDOException $e) {
            throw new Exception("Unable to establish a connection to MySQL: Host '$pHost', DB '$pDb', User '$pUser', Password '$pPass' with message '" . $e->getMessage() . "'");
        }

        $connection->query("SET NAMES 'utf8';");

        return $connection;
    }
public function connect($pHost, $pDb, $pUser = NULL, $pPass = NULL)
    {
        try {
            if ($pUser !== NULL and $pPass !== NULL and is_string($pUser) and is_string($pPass)) {
                $connection = new PDO("mysql:host=$pHost;dbname=$pDb", $pUser, $pPass);
            } else {
                $connection = new PDO("mysql:host=$pHost;dbname=$pDb");
            }
        } catch(PDOException $e) {
            throw new Exception("Unable to establish a connection to MySQL: Host '$pHost', DB '$pDb', User '$pUser', Password '$pPass' with message '" . $e->getMessage() . "'");
        }

        $connection->query("SET NAMES 'utf8';");

        return $connection;
    }
public function connect ( $ pHost , $ pDb , $ pUser = NULL , $ pPass = NULL ) { try { if ( $ pUser !== NULL and $ pPass !== NULL and is_string ( $ pUser ) and is_string ( $ pPass ) ) { $ connection = new PDO ( "mysql:host=$pHost;dbname=$pDb" , $ pUser , $ pPass ) ; } else { $ connection = new PDO ( "mysql:host=$pHost;dbname=$pDb" ) ; } } catch ( PDOException $ e ) { throw new Exception ( "Unable to establish a connection to MySQL: Host '$pHost', DB '$pDb', User '$pUser', Password '$pPass' with message '" . $ e -> getMessage ( ) . "'" ) ; } $ connection -> query ( "SET NAMES 'utf8';" ) ; return $ connection ; }
Establish the database connection.

@param string $pHost Database host
@param string $pDb Database name
@param string $pUser Database user
@param string $pPass Database password
@return PDO
Establish the database connection .