PDO::ERRMODE_EXCEPTION, ]); $pdo_admin->exec('CREATE DATABASE IF NOT EXISTS '.DB_NAME); echo "Database '" . DB_NAME . "' created or already exists.\n"; // Now connect to the database to run migrations $pdo = db(); $migration_files = glob(__DIR__ . '/migrations/*.sql'); sort($migration_files); foreach ($migration_files as $file) { echo "Running migration: " . basename($file) . "...\n"; $sql = file_get_contents($file); try { $pdo->exec($sql); echo "Migration " . basename($file) . " completed.\n"; } catch (PDOException $e) { echo "Error in migration " . basename($file) . ": " . $e->getMessage() . "\n"; } } echo "All migrations completed successfully.\n"; } catch (PDOException $e) { die("DB ERROR: " . $e->getMessage()); }