Fatal error: Call to a member function fetch() on a non-object
<p>I have this PHP code where I create a dropdownlist from the database. But when I run the application it fires an error <code>Fatal error:  Call to a member function fetch() on a non-object in ----\register.php on line 79</code>.</p>

<pre><code>&lt;select name="country"&gt;
&lt;?php
    $country_result = $dataclass-&gt;get_Countries();
    while ($country_row = $country_result-&gt;fetch()){ //line 79
        echo "&lt;option value='" . $country_row["country_id"] . "'&gt;" . $country_row["country_name"] . "&lt;/option&gt;" . "\n";
    }
?&gt;
&lt;/select&gt;
</code></pre>

<p>I have used such methods anywhere and they worked, but when using it for drop down list it doesn't work.</p>

<p>get_Country() method contents:</p>

<pre><code>function get_Countries() {
    $sql = "SELECT * FROM tbl_countries;";
    return $this-&gt;dbconn-&gt;fetch($sql);
}
</code></pre>

<p>$this->dbconn->fetch() contents:</p>

<pre><code>function fetch($sql, $data=array()) {
    try{
        $STH = $this-&gt;dbh-&gt;prepare($sql);
        $STH-&gt;setFetchMode(PDO::FETCH_ASSOC);
        $STH-&gt;execute($data);
        return $STH;
    } catch (PDOException $e){
        echo $e-&gt;getMessage();
    }
}
</code></pre>

<p>Could it be because 'data' parameter is an array?</p>
