"Trying to get property of non-object in" - custom mysqli class
<p>I'm trying to write a custom class for MySQLi, but I keep receiving the error "Trying to get property of non-object in" when using <code>num_rows</code>. Can anyone help?</p>

<pre><code>class db { 
    private $host = "***";
    private $user = "***";
    private $pass = "***";
    private $database;

    private $connection;
    private $result;
    public $sql;

    function __construct($database) {
        if (!empty($database)) $this-&gt;database = $database;
        $this-&gt;connection = new mysqli($this-&gt;host,$this-&gt;user,$this-&gt;pass,$this-&gt;database);
        return $this-&gt;connection;
    }

    public function fetchRowNum($sql) {
        if (!empty($sql)) {
            $this-&gt;sql = $sql;
            return $this-&gt;connection-&gt;query($sql)-&gt;num_rows;
        } else {
            throw new Exception("Error fetching row");
        }
    }
}
</code></pre>
