Jump to content


Photo

Call to undefined method DB_Error::fetchRow()


  • Please log in to reply
2 replies to this topic

#1 AncientSage

AncientSage
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 20 September 2006 - 05:54 AM

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:

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

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?

#2 btherl

btherl
  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 20 September 2006 - 06:06 AM

Single quotes vs double quotes is important.  It should be:

$sql = "SELECT id, name FROM threads WHERE forum = '$id'";

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.

#3 AncientSage

AncientSage
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 20 September 2006 - 06:13 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users