34092-vm/db/config.php
Flatlogic Bot 021503baf9 1
2025-09-16 13:00:53 +00:00

28 lines
740 B
PHP

<?php
function db() {
$host = '127.0.0.1';
$db = 'webapp';
$user = 'webapp';
$pass = 'webapp';
$charset = 'utf8mb4';
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
try {
return new PDO($dsn, $user, $pass, $options);
} catch (\PDOException $e) {
throw new \PDOException($e->getMessage(), (int)$e->getCode());
}
}
// Run migrations
$pdo = db();
$migration_files = glob(__DIR__ . '/migrations/*.sql');
foreach ($migration_files as $file) {
$pdo->exec(file_get_contents($file));
}