41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
|
// Generated by setup_mariadb_project.sh — edit as needed.
|
|
define('DB_HOST', '127.0.0.1');
|
|
define('DB_NAME', 'app_35573');
|
|
define('DB_USER', 'app_35573');
|
|
define('DB_PASS', '3a9c9286-552d-43b3-aa10-057fbae31b48');
|
|
|
|
function db() {
|
|
static $pdo;
|
|
if (!$pdo) {
|
|
$pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS, [
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
|
]);
|
|
}
|
|
function run_migrations($pdo) {
|
|
$migration_dir = __DIR__ . '/migrations';
|
|
if (!is_dir($migration_dir)) return;
|
|
|
|
$files = glob($migration_dir . '/*.sql');
|
|
sort($files);
|
|
|
|
foreach ($files as $file) {
|
|
try {
|
|
$sql = file_get_contents($file);
|
|
if (!empty(trim($sql))) {
|
|
$pdo->exec($sql);
|
|
}
|
|
} catch (PDOException $e) {
|
|
// Log error or handle it, but don't stop other migrations
|
|
error_log("Migration failed for file: " . basename($file) . " with error: " . $e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
|
|
// Run migrations on connection
|
|
run_migrations($pdo);
|
|
|
|
return $pdo;
|
|
}
|