Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved loop for getAllQueries #2114

Merged
merged 1 commit into from
Feb 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions api_db.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,36 @@
$stmt->bindValue(":from", intval($from), SQLITE3_INTEGER);
$stmt->bindValue(":until", intval($until), SQLITE3_INTEGER);
$results = $stmt->execute();
if(!is_bool($results))
while ($row = $results->fetchArray())
{
// Convert query type ID to name
if (!is_bool($results)) {
// Start the JSON string
echo '{"data":[';

$first = true;
while ($row = $results->fetchArray()) {
// Insert a comma before the next record (except on the first one)
if (!$first) {
echo ",";
} else {
$first = false;
}

// Convert query type ID to name, encode domain, encode destination
$query_type = getQueryTypeStr($row[1]);
$domain = utf8_encode(str_replace("~"," ",$row[2]));
$destination = utf8_encode($row[5]);

// Insert into array
// array: time type domain client status upstream destination
$allQueries[] = [$row[0], $query_type, utf8_encode(str_replace("~"," ",$row[2])), $row[3], $row[4], utf8_encode($row[5])];
// Insert into array and output it in JSON format
// array: time type domain client status upstream destination
echo json_encode([$row[0], $query_type, $domain, $row[3], $row[4], $destination]);
}

// Finish the JSON string
echo ']}';
}
// exit at the end
exit();
}
// only used if getAllQueries==empty
$result = array('data' => $allQueries);
$data = array_merge($data, $result);
}
Expand Down