При неудаче в запросе к БД валидные данные сохраняются в yaml-файл (script.php)

This commit is contained in:
2024-08-19 10:17:54 +03:00
parent adc163edfe
commit 826ae10f10
11 changed files with 2793 additions and 104 deletions

View File

@ -5,6 +5,7 @@ use App\Library\DatabaseConfig;
use App\Library\Logger;
use PDOException;
use PDO;
use Symfony\Component\Yaml\Yaml;
class Database
{
private PDO $pdo;
@ -66,7 +67,10 @@ class Database
}
$stmt->execute();
Logger::log(self::$logFile, "Запрос выполнен успешно!");
} catch (PDOException $e) {
} catch (PDOException $e) {
// При ошибке запроса сохраняем валидные данные в yaml-файл
$yaml = Yaml::dump($params);
file_put_contents(__DIR__ . '/not-recorded-in-db.yaml', $yaml);
$message = "Ошибка запроса:" . $e->getMessage();
Logger::log(self::$logFile, $message);
}