Нужно было сделать несколько запросов, изменив set
на select
, а затем правильно выполнить итерацию результатов.
$query = <<<SQL
select @num := 0, @priority := '';
select * from (
select
id, status_ts,
@num := if(@priority = priority, @num + 1, 1) as _row_number,
@priority := priority as priority
FROM ($priority_query) as get_priority
ORDER BY priority DESC, status_ts ASC
) as items where items._row_number <= CEIL(priority);
SQL;
PDO
$sql = $pdo->query($query);
if ($sql && $sql->nextRowset()) {
$items = [];
$numRows = $sql->rowCount();
if (($numRows > 0)) {
$items = $sql->fetchAll(\PDO::FETCH_OBJ);
}
} else {
$error = $this->DB->pdo->errorInfo();
throw new \Exception($error[2]);
}
MySQLi
$mysqli->multi_query($query);
$mysqli->next_result();
if ($result = $mysqli->store_result()) {
while ($row = $result->fetch_row()) {
printf("%s\n", $row[0]);
}
}