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/pages/summary.inc.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'modules-available/statistics/pages/summary.inc.php') diff --git a/modules-available/statistics/pages/summary.inc.php b/modules-available/statistics/pages/summary.inc.php index ce67070e..4599b8b6 100644 --- a/modules-available/statistics/pages/summary.inc.php +++ b/modules-available/statistics/pages/summary.inc.php @@ -67,7 +67,7 @@ class SubPage $points1 = array('data' => array(), 'label' => 'Online', 'fillColor' => '#efe', 'strokeColor' => '#aea', 'pointColor' => '#7e7', 'pointStrokeColor' => '#fff', 'pointHighlightFill' => '#fff', 'pointHighlightStroke' => '#7e7'); $points2 = array('data' => array(), 'label' => 'In use', 'fillColor' => '#fee', 'strokeColor' => '#eaa', 'pointColor' => '#e77', 'pointStrokeColor' => '#fff', 'pointHighlightFill' => '#fff', 'pointHighlightStroke' => '#e77'); $sum = 0; - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { $x = explode('#', $row['data']); if ($sum === 0) { $labels[] = date('H:i', $row['dateline']); @@ -103,7 +103,7 @@ class SubPage $lines = array(); $json = array(); $id = 0; - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { if (empty($row['systemmodel'])) { continue; } @@ -131,7 +131,7 @@ class SubPage $res = Database::simpleQuery("SELECT mbram, Count(*) AS `count` FROM machine m $join WHERE $where GROUP BY mbram", $args); $lines = array(); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { $gb = (int)ceil($row['mbram'] / 1024); for ($i = 1; $i < count(StatisticsFilter::SIZE_RAM); ++$i) { if (StatisticsFilter::SIZE_RAM[$i] < $gb) { @@ -178,7 +178,7 @@ class SubPage WHERE $where GROUP BY kvmstate ORDER BY `count` DESC", $args); $lines = array(); $json = array(); - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { $lines[] = $row; $json[] = array( 'color' => isset($colors[$row['kvmstate']]) ? $colors[$row['kvmstate']] : '#000', @@ -198,7 +198,7 @@ class SubPage $res = Database::simpleQuery("SELECT id44mb, Count(*) AS `count` FROM machine m $join WHERE $where GROUP BY id44mb", $args); $lines = array(); $total = 0; - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { $total += $row['count']; $gb = (int)ceil($row['id44mb'] / 1024); for ($i = 1; $i < count(StatisticsFilter::SIZE_ID44); ++$i) { @@ -251,7 +251,7 @@ class SubPage . " WHERE firstseen > :cutoff AND $where ORDER BY firstseen DESC LIMIT 32", $args); $rows = array(); $count = 0; - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { if (empty($row['hostname'])) { $row['hostname'] = $row['clientip']; } -- cgit v1.2.3-55-g7522