PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Problem using a MySQL query in php, error involving PEAR

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PEAR Forum Forum Index -> General PEAR questions
View previous topic :: View next topic  
Author Message
zippers24



Joined: 11 Jul 2008
Posts: 2

PostPosted: Fri Jul 11, 2008 11:52 am    Post subject: Problem using a MySQL query in php, error involving PEAR Reply with quote

I was hoping someone here could help me with a problem i am having. I am storing details on a product and I have written the following function and used a template to show the data that has been retrieved.

Code:
Code:

public function GetProductDetails($productId)
  {             
    $query_string =
      "SELECT product_id, name, description,
               price, image_file_1, image_file_2
       FROM product
       WHERE product_id = $productId";
    return $this->dbManager->DbGetRow($query_string);



This worked fine and I was able to retrieve the results through my template. I then wanted to retrieve some attributes, colour and size to be exact. I therefore used a different query which worked fine in the MySQL command line. So I placed it into the function:

Code:
Code:

 public function GetProductDetails($productId)
  {             
    $query_string =
      "SELECT product.product_id
     , product.name
     , product.description
     , product.fabric
     , product.weight
     , product.price
     , product.image_file_1
     , product.image_file_2
     , sizedata.sizes
     , colourdata.colours
  FROM product
INNER
  JOIN ( SELECT product_size.product_id
              , GROUP_CONCAT(size.size) AS sizes
           FROM product_size
         INNER
           JOIN size
             ON size.size_id = product_size.size_id
       GROUP BY product_size.product_id ) AS sizedata 
    ON sizedata.product_id = product.product_id
INNER
  JOIN ( SELECT product_colour.product_id,             
          GROUP_CONCAT(colour.colour) AS colours       
          FROM product_colour                           
          INNER JOIN colour                             
          ON colour.colour_id = product_colour.colour_id
          GROUP BY product_colour.product_id
       ) AS colourdata           
    ON colourdata.product_id = product.product_id
    WHERE product_id = $productId";
    return $this->dbManager->DbGetRow($query_string);
  }




This however produces an error: ERRNO: 256 TEXT: DB Error: unknown error. The error location is in the following function:

Code:

Code:

public function DbGetRow($queryString)
  {     
    $result = $this->db->getRow($queryString);
    if (DB::isError($result))
       trigger_error($result->getMessage(), E_USER_ERROR);
    return $result;
  }





Which uses pearDB's getRow function. It might worth noting that the query combines several attributes into one row so if a product come in M and L it creates the field sizes. "M,L" even though these are stored seperatly within the table, I don't know if that is relevant.

Does anyone know what the problem with this is. Any help would be much appreciated.

Andy
Code:
Back to top
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1235

PostPosted: Fri Jul 11, 2008 9:31 pm    Post subject: Reply with quote

Code:
$result->getDebugInfo()
will give you more information about the error.
Back to top
View user's profile Send private message
zippers24



Joined: 11 Jul 2008
Posts: 2

PostPosted: Sat Jul 12, 2008 1:49 pm    Post subject: Reply with quote

Thanks Mark, turned out product_id was ambigious, now everything works fine.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PEAR Forum Forum Index -> General PEAR questions All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement