 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
zippers24
Joined: 11 Jul 2008 Posts: 2
|
Posted: Fri Jul 11, 2008 11:52 am Post subject: Problem using a MySQL query in php, error involving PEAR |
|
|
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 |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1053
|
Posted: Fri Jul 11, 2008 9:31 pm Post subject: |
|
|
| Code: | | $result->getDebugInfo() | will give you more information about the error. |
|
| Back to top |
|
 |
zippers24
Joined: 11 Jul 2008 Posts: 2
|
Posted: Sat Jul 12, 2008 1:49 pm Post subject: |
|
|
| Thanks Mark, turned out product_id was ambigious, now everything works fine. |
|
| Back to top |
|
 |
|
|
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
|
|