archinsa/init_db.php
2023-10-22 19:24:59 +02:00

70 lines
No EOL
1.6 KiB
PHP

<?php
// Database connection parameters
$servername = "127.0.0.1";
$username = "root";
$password = "";
$dbname = "archivinsa";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Create tables
$sql = "
CREATE TABLE IF NOT EXISTS themes (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL
);
CREATE TABLE IF NOT EXISTS ensemble (
id INT AUTO_INCREMENT PRIMARY KEY,
commentaire_auteur TEXT
);
CREATE TABLE IF NOT EXISTS documents (
id INT AUTO_INCREMENT PRIMARY KEY,
titre VARCHAR(255) NOT NULL,
type INT,
upload_path TEXT NOT NULL,
commentaire_auteur TEXT,
ensemble_id INT,
theme_id INT,
FOREIGN KEY (theme_id) REFERENCES themes(id),
FOREIGN KEY (ensemble_id) REFERENCES ensemble(id)
);
CREATE TABLE IF NOT EXISTS exercices (
id INT AUTO_INCREMENT PRIMARY KEY,
titre VARCHAR(255) NOT NULL,
commentaire_auteur TEXT,
document_id INT,
FOREIGN KEY (document_id) REFERENCES documents(id)
);
CREATE TABLE IF NOT EXISTS exercices_themes (
id INT AUTO_INCREMENT PRIMARY KEY,
exercice_id INT,
theme_id INT,
FOREIGN KEY (exercice_id) REFERENCES exercices(id),
FOREIGN KEY (theme_id) REFERENCES themes(id)
);
";
if ($conn->multi_query($sql) === TRUE) {
echo "Tables created successfully";
} else {
echo "Error creating tables: " . $conn->error;
}
// Close the connection
$conn->close();
?>