mirror of
https://gitlab.com/ruany/litebans-php.git
synced 2025-07-09 15:27:32 +00:00
Use same selection across all queries
This commit is contained in:
parent
180d757078
commit
7817c33088
@ -26,8 +26,9 @@ class History {
|
|||||||
if ($count_st->execute() && ($row = $count_st->fetch()) !== null) {
|
if ($count_st->execute() && ($row = $count_st->fetch()) !== null) {
|
||||||
$counts[$type] = $row['count'];
|
$counts[$type] = $row['count'];
|
||||||
}
|
}
|
||||||
|
$sel = $page->get_selection($table);
|
||||||
|
|
||||||
$st = $page->conn->prepare("SELECT * FROM $table WHERE $field=:uuid ORDER BY time");
|
$st = $page->conn->prepare("SELECT $sel FROM $table WHERE $field=:uuid ORDER BY time");
|
||||||
|
|
||||||
$st->bindParam(":uuid", $uuid, PDO::PARAM_STR);
|
$st->bindParam(":uuid", $uuid, PDO::PARAM_STR);
|
||||||
|
|
||||||
|
@ -88,6 +88,21 @@ class Page {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_selection($table) {
|
||||||
|
if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
|
||||||
|
$selection = "*";
|
||||||
|
} else {
|
||||||
|
// PDO+MySQL under PHP 5.3.x has a bug with BIT columns.
|
||||||
|
// An empty string is returned no matter what the value is.
|
||||||
|
// Workaround: cast to unsigned.
|
||||||
|
$selection = "id,uuid,reason,banned_by_name,banned_by_uuid,time,until,CAST(active AS UNSIGNED) AS active";
|
||||||
|
if ($table === $this->settings->table['warnings']) {
|
||||||
|
$selection .= ",CAST(warned AS UNSIGNED) AS warned";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $selection;
|
||||||
|
}
|
||||||
|
|
||||||
function run_query() {
|
function run_query() {
|
||||||
try {
|
try {
|
||||||
$table = $this->table;
|
$table = $this->table;
|
||||||
@ -100,17 +115,7 @@ class Page {
|
|||||||
$offset = ($limit * $page);
|
$offset = ($limit * $page);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
|
$sel = $this->get_selection($table);
|
||||||
$sel = "*";
|
|
||||||
} else {
|
|
||||||
// PDO+MySQL under PHP 5.3.x has a bug with BIT columns.
|
|
||||||
// An empty string is returned no matter what the value is.
|
|
||||||
// Workaround: cast to unsigned.
|
|
||||||
$sel = "id,uuid,reason,banned_by_name,banned_by_uuid,time,until,CAST(active AS UNSIGNED) AS active";
|
|
||||||
if ($table === $this->settings->table['warnings']) {
|
|
||||||
$sel .= ",CAST(warned AS UNSIGNED) AS warned";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$query = "SELECT $sel FROM $table $active_query GROUP BY $table.id ORDER BY time DESC LIMIT :limit OFFSET :offset";
|
$query = "SELECT $sel FROM $table $active_query GROUP BY $table.id ORDER BY time DESC LIMIT :limit OFFSET :offset";
|
||||||
$st = $this->conn->prepare($query);
|
$st = $this->conn->prepare($query);
|
||||||
|
@ -99,6 +99,7 @@ final class Settings {
|
|||||||
try {
|
try {
|
||||||
$this->conn = new PDO($dsn, $username, $password);
|
$this->conn = new PDO($dsn, $username, $password);
|
||||||
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
|
$this->conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
die('Connection failed: ' . $e->getMessage());
|
die('Connection failed: ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
|
3
info.php
3
info.php
@ -128,7 +128,8 @@ $id = (int)$id;
|
|||||||
|
|
||||||
$type = $page->type;
|
$type = $page->type;
|
||||||
$table = $page->table;
|
$table = $page->table;
|
||||||
$query = "SELECT * FROM $table WHERE id=? LIMIT 1";
|
$sel = $page->get_selection($table);
|
||||||
|
$query = "SELECT $sel FROM $table WHERE id=? LIMIT 1";
|
||||||
|
|
||||||
$st = $page->conn->prepare($query);
|
$st = $page->conn->prepare($query);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user