我有一个mysqli的问题。当我尝试在其中使用它时,我给了我一个错误php
,但是当我在某些地方执行查询时database application
它工作得很好。它给了我错误
SET @rank=0; SELECT (@rank := @rank+1)
我可以在其中正确执行mysql yog
它。有没有其他方法可以让它工作?
这是代码:
function get_rank($branch,$cat){
global $connection;
$result = array();
$rank = 0;
if ($statement = $connection->prepare("SET @rank=0; SELECT (@rank := @rank+1) AS rank, a.branch_code_id, SUM(b.amount), c.category FROM sales_add_h AS a INNER JOIN sales_add_i AS b ON a.id = b.sales_h_id INNER JOIN control_panel_item_create AS c ON b.item_code_id = c.id WHERE a.branch_code_id = ? AND c.category = ? GROUP BY c.category, a.branch_code_id, b.amount ORDER BY SUM(b.amount) DESC")) {
$statement->bind_param("is",$branch,$cat);
$statement->execute();
$statement->bind_result($a,$b,$c,$d);
while ($row = $statement->fetch()) {
array_push($result,array($a,$b,$c,$d));
}
$statement->close();
} else {
printf("Errormessage: %s\n", $connection->error);
echo " error in SQL Statement.";
}
return $result;
}