初始化仓库及v1.0.0提交
This commit is contained in:
27
app/Models/Config.php
Normal file
27
app/Models/Config.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Config\Database;
|
||||
|
||||
class Config
|
||||
{
|
||||
public static function getByKey(string $key): ?array
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$stmt = $db->prepare('SELECT * FROM config WHERE config_key = :config_key');
|
||||
$stmt->execute(['config_key' => $key]);
|
||||
$result = $stmt->fetch();
|
||||
return $result ?: null;
|
||||
}
|
||||
|
||||
public static function setByKey(string $key, string $value): bool
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$stmt = $db->prepare('INSERT INTO config (config_key, config_value) VALUES (:config_key, :config_value) ON DUPLICATE KEY UPDATE config_value = VALUES(config_value)');
|
||||
return $stmt->execute([
|
||||
'config_key' => $key,
|
||||
'config_value' => $value,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user