45 lines
No EOL
1.3 KiB
PHP
45 lines
No EOL
1.3 KiB
PHP
<?php
|
|
|
|
require_once("Connection.class.php");
|
|
|
|
class Setting {
|
|
private $connection = null;
|
|
private $settingKey = "";
|
|
|
|
public function __construct($setting_key)
|
|
{
|
|
$this->connection = new Connection();
|
|
$this->settingKey = $this->connection->escape($setting_key);
|
|
}
|
|
|
|
public function get($default="")
|
|
{
|
|
$query = "SELECT `setting_value` FROM `settings` WHERE `setting_key` = '" . $this->settingKey . "';";
|
|
$result = $this->connection->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 = $this->connection->escape($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 (!$this->connection->query($query)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
} |