41 lines
No EOL
1.2 KiB
PHP
41 lines
No EOL
1.2 KiB
PHP
<?php
|
|
|
|
include_once("./connection.php");
|
|
|
|
class Setting {
|
|
private $settingKey = "";
|
|
|
|
public function __construct($setting_key)
|
|
{
|
|
$this->settingKey = $mysqli->real_escape_string($setting_key);
|
|
}
|
|
|
|
public function get($default="")
|
|
{
|
|
$query = "SELECT `setting_value` FROM `settings` WHERE `setting_key` = '" . $this->settingKey . "';";
|
|
$result = $mysqli->query($query);
|
|
if ($result->num_rows == 1) {
|
|
return $result->fetch_assoc()["setting_key"];
|
|
} else {
|
|
if (!empty($default)) {
|
|
return $default;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function set($value)
|
|
{
|
|
$escaped_value = $mysqli->real_escape_string($value);
|
|
|
|
if ($this->get()) {
|
|
$query = "UPDATE `settings` SET `setting_value` = '" . $escaped_value . "' WHERE `setting_key` = '" . $this->settingKey . "';";
|
|
} else {
|
|
$query = "INSERT INTO `settings` (`setting_key`, `setting_value`) VALUES ('". $this->settingKey . "', '" . $escaped_value . "');";
|
|
}
|
|
|
|
if (!$mysqli->query($query)) {
|
|
return False;
|
|
}
|
|
}
|
|
} |