zippers24 Posted July 11, 2008 Share Posted July 11, 2008 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. 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: 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: 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 Link to comment https://forums.phpfreaks.com/topic/114238-problem-using-a-mysql-query-in-php-error-possible-involves-peardb/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.