gastrodata/Setting.class.php

45 lines
1.3 KiB
PHP
Raw Normal View History

2020-08-02 12:07:03 +00:00
<?php
require_once("Connection.class.php");
2020-08-02 12:07:03 +00:00
class Setting {
private $connection = null;
2020-08-02 12:07:03 +00:00
private $settingKey = "";
public function __construct($setting_key)
{
$this->connection = new Connection();
$this->settingKey = $this->connection->escape($setting_key);
2020-08-02 12:07:03 +00:00
}
public function get($default="")
{
$query = "SELECT `setting_value` FROM `settings` WHERE `setting_key` = '" . $this->settingKey . "';";
$result = $this->connection->query($query);
2020-08-02 12:07:03 +00:00
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);
2020-08-02 12:07:03 +00:00
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;
2020-08-02 12:07:03 +00:00
}
return true;
2020-08-02 12:07:03 +00:00
}
}