From 8dc2b92d667f1401ab9f1315a36add61658f899c Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 6 May 2021 10:26:09 +0200 Subject: Moderize Database handling * Auto-convert to utf8mb4_unicode_520_ci * Use foreach instead of while to loop over results * Drop useless statement caching * Keep emulated prepares, as we sometimes loop over nested queries --- modules-available/statistics_reporting/inc/queries.inc.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'modules-available/statistics_reporting/inc/queries.inc.php') diff --git a/modules-available/statistics_reporting/inc/queries.inc.php b/modules-available/statistics_reporting/inc/queries.inc.php index 128d8e7d..8c6ff9a8 100644 --- a/modules-available/statistics_reporting/inc/queries.inc.php +++ b/modules-available/statistics_reporting/inc/queries.inc.php @@ -106,7 +106,7 @@ class Queries $bounds = [$lowerTimeBound, $upperTimeBound]; } $machines = array(); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { $row['firstseen'] = max($row['firstseen'], $from); $row += array( 'totalTime' => self::timeDiff($row['firstseen'], $to, $bounds), @@ -132,7 +132,7 @@ class Queries ORDER BY dateline ASC LIMIT 1000", compact('last', 'to')); $last = false; $count = 0; - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { $count += 1; // Update count first, as we use it as a condition in outer loop. No continue before this settype($row['logid'], 'int'); // Update for next query @@ -375,7 +375,7 @@ class Queries LEFT JOIN exams_x_location exl USING (examid) WHERE starttime < $to AND endtime > $from GROUP BY examid"); - while ($row = $eres->fetch(PDO::FETCH_ASSOC)) { + foreach ($eres as $row) { // Get all boot events $data = ['from' => $row['starttime'], 'to' => $row['endtime']]; if (empty($row['locs'])) { -- cgit v1.2.3-55-g7522