Optimize queries

This commit is contained in:
ruan 2018-05-31 10:16:10 +02:00
parent 4b3565b9aa
commit 5857a0d374
No known key found for this signature in database
GPG Key ID: 0D2EC1C52E469C0B
2 changed files with 12 additions and 12 deletions

View File

@ -116,12 +116,12 @@ try {
(SELECT COUNT(*) FROM $t_bans WHERE $field=:uuid0) +
(SELECT COUNT(*) FROM $t_mutes WHERE $field=:uuid1) +
(SELECT COUNT(*) FROM $t_warnings WHERE $field=:uuid2) +
(SELECT COUNT(*) FROM $t_kicks WHERE $field=:uuid3) as total
(SELECT COUNT(*) FROM $t_kicks WHERE $field=:uuid3)
");
for ($i = 0; $i <= 3; $i++) $count_st->bindParam(":uuid$i", $uuid, PDO::PARAM_STR);
if ($count_st->execute() && ($row = $count_st->fetch()) !== null) {
$total = $row['total'];
if ($count_st->execute() && ($row = $count_st->fetch(PDO::FETCH_NUM)) !== null) {
$total = $row[0];
}
$count_st->closeCursor();

View File

@ -14,17 +14,17 @@ function __construct($page) {
$t_kicks = $t['kicks'];
try {
$st = $page->conn->query("SELECT
(SELECT COUNT(*) FROM $t_bans) AS c_bans,
(SELECT COUNT(*) FROM $t_mutes) AS c_mutes,
(SELECT COUNT(*) FROM $t_warnings) AS c_warnings,
(SELECT COUNT(*) FROM $t_kicks) AS c_kicks");
($row = $st->fetch(PDO::FETCH_ASSOC)) or die('Failed to fetch row counts.');
(SELECT COUNT(*) FROM $t_bans),
(SELECT COUNT(*) FROM $t_mutes),
(SELECT COUNT(*) FROM $t_warnings),
(SELECT COUNT(*) FROM $t_kicks)");
($row = $st->fetch(PDO::FETCH_NUM)) or die('Failed to fetch row counts.');
$st->closeCursor();
$this->count = array(
'bans.php' => $row['c_bans'],
'mutes.php' => $row['c_mutes'],
'warnings.php' => $row['c_warnings'],
'kicks.php' => $row['c_kicks'],
'bans.php' => $row[0],
'mutes.php' => $row[1],
'warnings.php' => $row[2],
'kicks.php' => $row[3],
);
} catch (PDOException $ex) {
Settings::handle_error($page->settings, $ex);