PHP_SMART_HOME_V3/app/models/managers/SettingsManager.php
2020-12-09 12:28:31 +01:00

38 lines
795 B
PHP

<?php
class SettingsManager{
static function getAllValues () {
return Db::loadAll ("SELECT * FROM settings");
}
static function getByName($settingName) {
return Db::loadOne("SELECT * FROM settings WHERE name = ?", array($settingName));
}
public static function create ($name, $value) {
$setting = array (
'name' => $name,
'value' => $value,
);
try {
Db::add ('settings', $setting);
} catch(PDOException $error) {
echo $error->getMessage();
die();
}
}
public static function update ($name, $value) {
if ($this.getByName($name)){
$this->create($name, $value);
} else {
try {
Db::edit ('settings', ['value' => $value], 'WHERE name = ?', array($name));
} catch(PDOException $error) {
echo $error->getMessage();
die();
}
}
}
}
?>