i have been lately introduced to method chaining, and am not sure if what I'm doing here is illegal, or I'm doing it wrong. I have a database Class like:

```
    class Database
    {
    private $connection;
    private $resultset, $last_query, $current_row;

    function __construct()
    {
        $this->connect();
    }

    public function connect()
    {
        // Connect to the database
    }

    public function query($query)
    {
        $this->last_query = $query;
        $this->resultset = mysql_query($query, $this->connection);
    }

    public function fetchObject()
    {
        $this->current_row = mysql_fetch_object($this->resultset);
        return $this->current_row;
    }
}

```

I tried using it like:

```
$db->query("SELECT * FROM users WHERE name='JimmyP'")->fetchObject();

```

I also tried 

```
$db->fetchObject()->query("SELECT * FROM users WHERE name='JimmyP'");

```

But i get the error: "Call to a member function fetchObject() on a non-object"

Can someone please explain to me what Im doing incorrectly here as it relates to using method chaining. Thank you.