Fatal error: Call to a member function fetch() on a non-object

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

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

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

get_Country() method contents:

function get_Countries() { $sql = "SELECT * FROM tbl_countries;"; return $this->dbconn->fetch($sql); }

$this->dbconn->fetch() contents:

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

Could it be because 'data' parameter is an array?

-------------Problems Reply------------

Try

function get_Countries() {
$sql = "SELECT * FROM tbl_countries;";
return $this->dbconn->query($sql);
}

Category:php Views:0 Time:2012-01-12
Tags: php

Related post

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.185 (s). 11 q(s)