I'm attempting to create an aggregated data set for graphing (min and max values of every X rows) and I'm not getting the results I expect. I can run the query from PHPMyAdmin and it works perfectly, I get a single row with two columns. However, when I use PDO it simply produces false
instead of an array as I expect.
// Get an min/max aggregated dataset
$aggregatedData = [];
echo (string)$count . "<br>"; // DEBUG
$query = "SELECT MIN(channel1) AS MinVal, MAX(channel1) AS MaxVal FROM "
. "(SELECT channel1 FROM datacache WHERE fileId = ? ORDER BY time LIMIT ?,?) subset";
$sql = $conn->prepare($query);
while ($offset < $count)
{
$sql->execute([$chart, $offset, $aggregate]);
echo $chart . ", " . $offset . ", " . $aggregate . "<br>"; // DEBUG
$data = $sql->fetch(PDO::FETCH_ASSOC);
echo json_encode($data)."<br>"; // DEBUG
array_push($aggregatedData, $data["MinVal"], $data["MaxVal"]);
$offset += $aggregate;
}
echo json_encode($aggregatedData); //AJAX Export
My debug output is as follows (excerpt for brevity)
1000004
37, 0, 50
false
37, 50, 50
false
37, 100, 50
false
37, 150, 50
false
37, 200, 50
false
Note: this was not a duplicate as suggested.