Semi-stable version with old variable names
This commit is contained in:
@@ -130,3 +130,56 @@ function db_get_var($mysqli, $sql, $params = []) {
|
||||
$stmt->close();
|
||||
return $value;
|
||||
}
|
||||
|
||||
function db_get_variable($mysqli, $tableVar, $params = []) {
|
||||
if (count($params) !== 1) return null;
|
||||
$stmt = $mysqli->prepare("SELECT `value` FROM $tableVar WHERE `name` = ?");
|
||||
$stmt->bind_param("s", ...$params);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($value);
|
||||
$stmt->fetch();
|
||||
$stmt->close();
|
||||
return $value;
|
||||
}
|
||||
|
||||
function db_update_variable($mysqli, $tableVar, $params = ['name', 'value']) {
|
||||
if (count($params) !== 2) return false;
|
||||
$stmt = $mysqli->prepare("INSERT INTO $tableVar (`name`, `value`) VALUES (?, ?) ON DUPLICATE KEY UPDATE `value` = VALUES(`value`)");
|
||||
$stmt->bind_param("ss", ...$params);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
return true;
|
||||
}
|
||||
|
||||
function db_check_var(mysqli $mysqli, string $table, string $where, array $params = []) : bool {
|
||||
|
||||
$table = preg_replace('/[^a-zA-Z0-9_]/', '', $table);
|
||||
|
||||
$stmt = $mysqli->prepare("SELECT 1 FROM `" . $table . "` WHERE " . $where);
|
||||
if (!$stmt) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!empty($params)) {
|
||||
$types = '';
|
||||
foreach ($params as $param) {
|
||||
if (is_int($param)) {
|
||||
$types .= 'i';
|
||||
} elseif (is_float($param)) {
|
||||
$types .= 'd';
|
||||
} else {
|
||||
$types .= 's';
|
||||
}
|
||||
}
|
||||
$stmt->bind_param($types, ...$params);
|
||||
}
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
$stmt->store_result();
|
||||
$exists = $stmt->num_rows > 0;
|
||||
|
||||
$stmt->close();
|
||||
|
||||
return $exists;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user