Files

29 lines
729 B
PHP
Raw Permalink Normal View History

<?php
/**
* 家庭级键值对设置。
*/
declare(strict_types=1);
namespace App;
final class Setting
{
public static function get(int $familyId, string $key, $default = null)
{
$st = Database::get()->prepare('SELECT v FROM settings WHERE family_id = ? AND k = ?');
$st->execute([$familyId, $key]);
$v = $st->fetchColumn();
return $v === false ? $default : $v;
}
public static function set(int $familyId, string $key, string $value): void
{
$st = Database::get()->prepare(
'INSERT INTO settings (family_id, k, v) VALUES (?, ?, ?)
ON DUPLICATE KEY UPDATE v = VALUES(v)'
);
$st->execute([$familyId, $key, $value]);
}
}