gastrodata/Setting.class.php

41 lines
1.2 KiB
PHP
Raw Normal View History

2020-08-02 12:07:03 +00:00
<?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;
}
}
}