I wanted to know if prepared statements can be used in the following way:
public static function GetCategoryItems($categoryId,$pageNum, &$rnum_pages)
{
$sql = 'SELECT DISTINCT COUNT(*) AS items_count
FROM item I
JOIN sub_category SC
ON I.sub_category_id = SC.sub_category_id
JOIN category C
ON C.category_id = SC.category_id
WHERE (I.location = 2 OR I.location = 3)
AND C.category_id =' . (int)$categoryId ;
$params = array (':category_id'=>$categoryId);
$rnum_pages = Catalog::CalculatePages($sql,$params);
$first_item = ($pageNum - 1) * ITEMS_PER_PAGE;
$sql =
"PREPARE stmt_name FROM
'SELECT I.item_id, I.name , I.price, I.discounted_price, I.thumbnail_photo
FROM item I
JOIN sub_category SC
ON I.sub_category_id = SC.sub_category_id
JOIN category C
ON C.category_id = SC.category_id
WHERE C.category_id = ?
LIMIT ?,? ' ;
SET @p1 = categoryId;
SET @p2 = firstItem;
SET @p3 = items_per_page;
EXECUTE stmt_name USING @p1,@p2,@p3; "
return DatabaseConnection::GetAll($sql,$params);
}
I am actually getting an error :
ERRNO: 256 TEXT: SQLSTATE[HY000]: General error
Can anyone help please?