Jump to content

Call to undefined method DB_Error::fetchRow()


AncientSage

Recommended Posts

Currently, I'm working on a forum script, using PEAR DBAL. The error I get is in the title, the code works fine in any other file, except this one. So I would guess it's code problems, the code:

[code]      $sql = "SELECT id, name FROM threads WHERE forum = " . '$id';
      $result = $dbh->query($sql);
      $topics = array();
      while($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
      {
      $topics[] = $row;
      }      [/code]

However, I don't see anything wrong with it...it's working on my index.php page, which is built the same, except this one has an if statement surrounding it.

Possibly a query problem?
Single quotes vs double quotes is important.  It should be:

[code]$sql = "SELECT id, name FROM threads WHERE forum = '$id'";[/code]

What you had would literally put "$id", not the contents of the variable named id, into the query.

You should also check if your result is valid before calling fetchRow .. it's actually an error, which is why it has no fetchRow method.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.