34762-vm/db/config.php
Flatlogic Bot 5235a9fa88 v1
2025-10-07 17:01:46 +00:00

35 lines
962 B
PHP

<?php
function db() {
static $pdoconn = null;
if ($pdoconn === null) {
$host = '127.0.0.1';
$db = 'lamp_app';
$user = 'lamp_user';
$pass = '';
$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 {
$pdoconn = new PDO($dsn, $user, $pass, $options);
} catch (\PDOException $e) {
throw new \PDOException($e->getMessage(), (int)$e->getCode());
}
}
return $pdoconn;
}
function run_migrations() {
$pdo = db();
$migration_files = glob(__DIR__ . '/migrations/*.sql');
foreach ($migration_files as $file) {
$sql = file_get_contents($file);
$pdo->exec($sql);
}
}
run_migrations();