38443-vm/fix_db.php
2026-02-21 20:41:25 +00:00

90 lines
3.4 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once __DIR__ . '/db/config.php';
header('Content-Type: text/html; charset=utf-8');
echo "<h1>Réparation de la base de données</h1>";
try {
$pdo = db();
} catch (Exception $e) {
die("<p style='color:red;'>Erreur de connexion : " . $e->getMessage() . "</p>");
}
$tables = [
"CREATE TABLE IF NOT EXISTS `channel_events` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`channel_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`title` varchar(255) NOT NULL,
`description` text DEFAULT NULL,
`banner_url` varchar(255) DEFAULT NULL,
`banner_color` varchar(20) DEFAULT NULL,
`start_date` date NOT NULL,
`start_time` time NOT NULL,
`end_date` date NOT NULL,
`end_time` time NOT NULL,
`frequency` varchar(50) DEFAULT NULL,
`is_permanent` tinyint(1) DEFAULT 0,
`created_at` timestamp NULL DEFAULT current_timestamp(),
`enable_reactions` tinyint(1) DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
"CREATE TABLE IF NOT EXISTS `poll_votes` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`message_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`option_index` int(11) NOT NULL,
`created_at` timestamp NULL DEFAULT current_timestamp(),
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
"CREATE TABLE IF NOT EXISTS `server_badges` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`server_id` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
`image_url` text NOT NULL,
`created_at` timestamp NULL DEFAULT current_timestamp(),
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
"CREATE TABLE IF NOT EXISTS `member_badges` (
`server_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`badge_id` int(11) NOT NULL,
PRIMARY KEY (`server_id`,`user_id`,`badge_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;",
"CREATE TABLE IF NOT EXISTS `event_participations` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`event_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`created_at` timestamp NULL DEFAULT current_timestamp(),
PRIMARY KEY (`id`),
UNIQUE KEY `event_id` (`event_id`,`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;"
];
foreach ($tables as $sql) {
try {
$pdo->exec($sql);
echo "<p>✅ Exécution réussie d'une requête de création.</p>";
} catch (Exception $e) {
echo "<p style='color:orange;'>⚠️ Info : " . $e->getMessage() . " (Peut-être que la table existe déjà)</p>";
}
}
echo "<h2>Vérification finale des colonnes (Correction Erreur 500 courante)</h2>";
// Ajout de colonnes si manquantes (exemple pour channels)
try {
$pdo->exec("ALTER TABLE `channels` ADD COLUMN IF NOT EXISTS `message_limit` int(11) DEFAULT NULL;");
$pdo->exec("ALTER TABLE `channels` ADD COLUMN IF NOT EXISTS `theme_color` varchar(20) DEFAULT NULL;");
echo "<p>✅ Mise à jour des colonnes 'channels' terminée.</p>";
} catch (Exception $e) {
echo "<p> Colonnes déjà présentes dans 'channels'.</p>";
}
echo "<hr><p style='color:green;'>Terminé ! Essayez de rafraîchir votre page index.php.</p>";
echo "<p style='color:red;'><b>IMPORTANT : Supprimez ce fichier (fix_db.php) après usage.</b></p>";