Jump to content

Archived

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

AncientSage

Call to undefined method DB_Error::fetchRow()

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Meh, I suck with the where clause. >_>

Yeah, I intend to add some error checks here soon enough, hopefully I'll be able to comprehend the errors better then.

Thanks for the help.

Share this post


Link to post
Share on other sites

×

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.