mirror of
https://gitlab.com/ruany/litebans-php.git
synced 2025-07-09 07:17: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) {
|
||||
$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);
|
||||
|
||||
|
@ -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() {
|
||||
try {
|
||||
$table = $this->table;
|
||||
@ -100,17 +115,7 @@ class Page {
|
||||
$offset = ($limit * $page);
|
||||
}
|
||||
|
||||
if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
|
||||
$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";
|
||||
}
|
||||
}
|
||||
$sel = $this->get_selection($table);
|
||||
|
||||
$query = "SELECT $sel FROM $table $active_query GROUP BY $table.id ORDER BY time DESC LIMIT :limit OFFSET :offset";
|
||||
$st = $this->conn->prepare($query);
|
||||
|
@ -99,6 +99,7 @@ final class Settings {
|
||||
try {
|
||||
$this->conn = new PDO($dsn, $username, $password);
|
||||
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$this->conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
||||
} catch (PDOException $e) {
|
||||
die('Connection failed: ' . $e->getMessage());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user