Page 1 of 1

MySQL error - ?

PostPosted: 07. September 2009 07:31
by OrcaSoul
I'm new to MySQL, so really need help!

The error I get:
Fatal error: Call to undefined method MDB2_Error::fetchRow() in C:\xampp\htdocs\OrcaTools\includes\orcatools.inc on line 193


The query string:
SELECT gv.variety FROM grape_variety gv, wine_variety wv, wine w WHERE w.wine_id = wv.wine_id AND wv.variety_id = gv.variety_id AND w.wine_id = ORDER BY wv.id


This is the function - line 193 is marked with <-:
Code: Select all
// Find the varieties for a wineID
function showVarieties($connection, $wineID)
{
   // Find the varieties of the current wine,
   // and order them by id
   $query = "SELECT gv.variety
             FROM grape_variety gv, wine_variety wv, wine w
             WHERE w.wine_id = wv.wine_id
             AND wv.variety_id = gv.variety_id
             AND w.wine_id = {$wineID}
             ORDER BY wv.id";

   $result = $connection->query($query);
   print $query;

   if (MDB2::isError($result))
      trigger_error($result->getMessage(), E_USER_ERROR);

   $varieties = "";

   // Retrieve and print the varieties
   while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))   // <-<-<-<- line #193
      $varieties .= " {$row["variety"]}";

   return $varieties;
}



So, why isn't this working?

Re: MySQL error - ?

PostPosted: 07. September 2009 10:03
by Nobbie
You should read the error message more carefully. The message says, that $result does not know the method fetchRow(). That's not a MySQL Error.

Is that your script? Debug it and find out whats wrong with $result.

Re: MySQL error - ?

PostPosted: 07. September 2009 20:05
by OrcaSoul
Nobbie wrote:You should read the error message more carefully. The message says, that $result does not know the method fetchRow(). That's not a MySQL Error.

Is that your script? Debug it and find out whats wrong with $result.


Hmmm...OK, I had assumed it was SQL, you are correct, it isn't...but I can't find it defined anywhere in the code I downloaded! :cry:

My apologies for posting - it's been a looooong weekend...and I'm trying to learn everything at once... :roll:

Re: MySQL error - ?

PostPosted: 07. September 2009 23:53
by Altrea
Everything to know is in the error_message:

Fatal error: Call to undefined method MDB2_Error::fetchRow() in C:\xampp\htdocs\OrcaTools\includes\orcatools.inc on line 193


File: C:\xampp\htdocs\OrcaTools\includes\orcatools.inc
Line: 193

There must be a function named fetchRow, which the PHP-Interpreter can't find in Class MDB2_Error.

Maybe it's easier for us to see, if you show us the code of line 193

Re: MySQL error - ?

PostPosted: 08. September 2009 01:32
by OrcaSoul
It's in the code segment in my original post.

Here it is again:

Code: Select all
    // Find the varieties for a wineID
    function showVarieties($connection, $wineID)
    {
       // Find the varieties of the current wine,
       // and order them by id
       $query = "SELECT gv.variety
                 FROM grape_variety gv, wine_variety wv, wine w
                 WHERE w.wine_id = wv.wine_id
                 AND wv.variety_id = gv.variety_id
                 AND w.wine_id = {$wineID}
                 ORDER BY wv.id";

       $result = $connection->query($query);
       print $query;

       if (MDB2::isError($result))
          trigger_error($result->getMessage(), E_USER_ERROR);

       $varieties = "";

       // Retrieve and print the varieties
       while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))   // <-<-<-<- line #193
          $varieties .= " {$row["variety"]}";

       return $varieties;
    }


I have since found that fetchRow is not part of MDB2...so looking for an "easy" replacement.

Re: MySQL error - ?

PostPosted: 08. September 2009 10:22
by Altrea
I don't know anything about the MDB2 class. It's a PEAR class, right?

It seems to be wrong, that your Script tries to call MDB2_Error::fetchRow(), because the MDB_Error class hasn't got a fetchRow method. It's an Error class, so why it should have one? Have you already tried to output your result_set? Maybe your query went wrong.

Re: MySQL error - ?

PostPosted: 09. September 2009 03:58
by OrcaSoul
OK, I found the reason the code wasn't working...one of those slight-of-hand things you never see even when it hits you in the face:

The use of DB_FETCHMODE_ASSOC was the problem - that is defined in DB.inc, but NOT in MDB2.inc - which uses MDB2_FETCHMODE_ASSOC...

I made that one change, and it ran just as advertised... :roll: :oops:

Aw well, what would life be if we weren't learning something new... :shock:

Thanks for the tips!